@@ -52,21 +52,16 @@ use proc_macro::TokenStream;
52
52
pub fn entry ( args : TokenStream , input : TokenStream ) -> TokenStream {
53
53
let f = parse_macro_input ! ( input as ItemFn ) ;
54
54
55
- // check the function arguments
56
55
#[ cfg( not( feature = "u-boot" ) ) ]
57
- if f. sig . inputs . len ( ) > 3 {
58
- return parse:: Error :: new (
59
- f. sig . inputs . last ( ) . unwrap ( ) . span ( ) ,
60
- "`#[entry]` function has too many arguments" ,
61
- )
62
- . to_compile_error ( )
63
- . into ( ) ;
64
- }
56
+ let arguments_limit = 3 ;
65
57
#[ cfg( feature = "u-boot" ) ]
66
- if f. sig . inputs . len ( ) != 2 {
58
+ let arguments_limit = 2 ;
59
+
60
+ // check the function arguments
61
+ if f. sig . inputs . len ( ) > arguments_limit {
67
62
return parse:: Error :: new (
68
63
f. sig . inputs . last ( ) . unwrap ( ) . span ( ) ,
69
- "`#[entry]` function must have exactly two arguments" ,
64
+ "`#[entry]` function has too many arguments" ,
70
65
)
71
66
. to_compile_error ( )
72
67
. into ( ) ;
@@ -90,10 +85,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
90
85
}
91
86
}
92
87
#[ cfg( feature = "u-boot" ) ]
93
- {
94
- // We have checked that there are two arguments above.
95
- let ( a1, a2) = ( & f. sig . inputs [ 0 ] , & f. sig . inputs [ 1 ] ) ;
96
-
88
+ if let Some ( a1) = f. sig . inputs . get ( 0 ) {
97
89
match a1 {
98
90
FnArg :: Receiver ( _) => {
99
91
return parse:: Error :: new ( a1. span ( ) , "invalid argument" )
@@ -108,18 +100,20 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
108
100
}
109
101
}
110
102
}
111
- match a2 {
112
- FnArg :: Receiver ( _) => {
113
- return parse:: Error :: new ( a2. span ( ) , "invalid argument" )
114
- . to_compile_error ( )
115
- . into ( ) ;
116
- }
117
- FnArg :: Typed ( t) => {
118
- if !is_simple_type ( & t. ty , "usize" ) {
119
- return parse:: Error :: new ( t. ty . span ( ) , "argument type must be usize" )
103
+ if let Some ( a2) = f. sig . inputs . get ( 1 ) {
104
+ match a2 {
105
+ FnArg :: Receiver ( _) => {
106
+ return parse:: Error :: new ( a2. span ( ) , "invalid argument" )
120
107
. to_compile_error ( )
121
108
. into ( ) ;
122
109
}
110
+ FnArg :: Typed ( t) => {
111
+ if !is_simple_type ( & t. ty , "usize" ) {
112
+ return parse:: Error :: new ( t. ty . span ( ) , "argument type must be usize" )
113
+ . to_compile_error ( )
114
+ . into ( ) ;
115
+ }
116
+ }
123
117
}
124
118
}
125
119
}
0 commit comments