@@ -32,8 +32,6 @@ pub fn quote_args<DB: DatabaseExt>(
3232 #( let #arg_name = & ( #arg_expr) ; ) *
3333 } ;
3434
35- let mut args_warnings: Vec < TokenStream > = vec ! [ ] ;
36-
3735 let args_check = match info. parameters ( ) {
3836 None | Some ( Either :: Right ( _) ) => {
3937 // all we can do is check arity which we did
@@ -52,14 +50,11 @@ pub fn quote_args<DB: DatabaseExt>(
5250 . enumerate ( )
5351 . map ( |( i, ( param_ty, ( name, expr) ) ) | -> crate :: Result < _ > {
5452 let param_ty = match get_type_override ( expr) {
55- // cast or type ascription will fail to compile if the type does not match
53+ // cast will fail to compile if the type does not match
5654 // and we strip casts to wildcard
5755 Some ( ( _, false ) ) => return Ok ( quote ! ( ) ) ,
58- Some ( ( ty, true ) ) => {
59- let warning = create_warning ( name. clone ( ) , ty. clone ( ) , expr. clone ( ) ) ;
60- args_warnings. push ( warning) ;
61- return Ok ( quote ! ( ) )
62- } ,
56+ // type ascription is deprecated
57+ Some ( ( ty, true ) ) => return Ok ( create_warning ( name. clone ( ) , & ty, & expr) ) ,
6358 None => {
6459 DB :: param_type_for_id ( & param_ty)
6560 . ok_or_else ( || {
@@ -108,8 +103,6 @@ pub fn quote_args<DB: DatabaseExt>(
108103 let args_count = input. arg_exprs . len ( ) ;
109104
110105 Ok ( quote ! {
111- #( #args_warnings) *
112-
113106 #arg_bindings
114107
115108 #args_check
@@ -123,11 +116,13 @@ pub fn quote_args<DB: DatabaseExt>(
123116 } )
124117}
125118
126- fn create_warning ( name : Ident , ty : Type , expr : Expr ) -> TokenStream {
127- let span = expr. span ( ) ;
128- let stripped = strip_wildcard ( expr) . to_token_stream ( ) ;
119+ fn create_warning ( name : Ident , ty : & Type , expr : & Expr ) -> TokenStream {
120+ let Expr :: Type ( ExprType { expr : stripped, .. } ) = expr else {
121+ return quote ! ( ) ;
122+ } ;
129123 let current = quote ! ( #stripped: #ty) . to_string ( ) ;
130124 let fix = quote ! ( #stripped as #ty) . to_string ( ) ;
125+ let name = Ident :: new ( & format ! ( "warning_{name}" ) , expr. span ( ) ) ;
131126
132127 let message = format ! (
133128 "
@@ -140,12 +135,15 @@ fn create_warning(name: Ident, ty: Type, expr: Expr) -> TokenStream {
140135\t \t See <https://github.com/rust-lang/rfcs/pull/3307> for more information
141136"
142137 ) ;
143- let name = Ident :: new ( & format ! ( "warning_{name}" ) , span) ;
144- quote_spanned ! ( span =>
145- #[ deprecated( note = #message) ]
146- #[ allow( non_upper_case_globals) ]
147- const #name: ( ) = ( ) ;
148- let _ = #name;
138+
139+ quote_spanned ! ( expr. span( ) =>
140+ // this shouldn't actually run
141+ if false {
142+ #[ deprecated( note = #message) ]
143+ #[ allow( non_upper_case_globals) ]
144+ const #name: ( ) = ( ) ;
145+ let _ = #name;
146+ }
149147 )
150148}
151149
0 commit comments