@@ -16,14 +16,11 @@ enum ParameterKind {
16
16
17
17
impl ParameterKind {
18
18
fn from_ident ( ident : & Ident ) -> Option < ParameterKind > {
19
- if ident == "positional_only" {
20
- Some ( ParameterKind :: PositionalOnly )
21
- } else if ident == "positional_or_keyword" {
22
- Some ( ParameterKind :: PositionalOrKeyword )
23
- } else if ident == "keyword_only" {
24
- Some ( ParameterKind :: KeywordOnly )
25
- } else {
26
- None
19
+ match ident. to_string ( ) . as_str ( ) {
20
+ "positional_only" => Some ( ParameterKind :: PositionalOnly ) ,
21
+ "positional_or_keyword" => Some ( ParameterKind :: PositionalOrKeyword ) ,
22
+ "keyword_only" => Some ( ParameterKind :: KeywordOnly ) ,
23
+ _ => None ,
27
24
}
28
25
}
29
26
}
@@ -150,6 +147,13 @@ fn generate_field(field: &Field) -> Result<TokenStream2, Diagnostic> {
150
147
} ;
151
148
152
149
let name = & field. ident ;
150
+ if let Some ( name) = name {
151
+ if name. to_string ( ) . starts_with ( "_phantom" ) {
152
+ return Ok ( quote ! {
153
+ #name: std:: marker:: PhantomData ,
154
+ } ) ;
155
+ }
156
+ }
153
157
let middle = quote ! {
154
158
. map( |x| :: rustpython_vm:: pyobject:: TryFromObject :: try_from_object( vm, x) ) . transpose( ) ?
155
159
} ;
@@ -210,8 +214,9 @@ pub fn impl_from_args(input: DeriveInput) -> Result<TokenStream2, Diagnostic> {
210
214
} ;
211
215
212
216
let name = input. ident ;
217
+ let ( impl_generics, ty_generics, where_clause) = input. generics . split_for_impl ( ) ;
213
218
let output = quote ! {
214
- impl :: rustpython_vm:: function:: FromArgs for #name {
219
+ impl #impl_generics :: rustpython_vm:: function:: FromArgs for #name #ty_generics #where_clause {
215
220
fn from_args(
216
221
vm: & :: rustpython_vm:: VirtualMachine ,
217
222
args: & mut :: rustpython_vm:: function:: PyFuncArgs
0 commit comments