171
171
//! }
172
172
//! ```
173
173
//!
174
- #![ feature( extern_crate_item_prelude) ]
175
- #![ feature( proc_macro_diagnostic) ]
174
+ // #![feature(extern_crate_item_prelude)]
175
+ // #![feature(proc_macro_diagnostic)]
176
176
#![ recursion_limit="128" ]
177
177
extern crate proc_macro;
178
178
@@ -228,9 +228,7 @@ fn lru_cache_impl(attr: Attr, item: TokenStream) -> Result<TokenStream> {
228
228
let mut original_fn: syn:: ItemFn = match syn:: parse ( item. clone ( ) ) {
229
229
Ok ( ast) => ast,
230
230
Err ( e) => {
231
- let diag = proc_macro2:: Span :: call_site ( ) . unstable ( )
232
- . error ( "lru_cache may only be used on functions" ) ;
233
- return Err ( DiagnosticError :: new_with_syn_error ( diag, e) ) ;
231
+ return Err ( DiagnosticError :: new_with_syn_error ( String :: from ( "lru_cache may only be used on functions" ) , e) ) ;
234
232
}
235
233
} ;
236
234
@@ -365,9 +363,7 @@ fn get_cache_fn_return_type(original_fn: &syn::ItemFn) -> Result<Box<syn::Type>>
365
363
if let syn:: ReturnType :: Type ( _, ref ty) = original_fn. decl . output {
366
364
Ok ( ty. clone ( ) )
367
365
} else {
368
- let diag = original_fn. ident . span ( ) . unstable ( )
369
- . error ( "There's no point of caching the output of a function that has no output" ) ;
370
- return Err ( DiagnosticError :: new ( diag) ) ;
366
+ return Err ( DiagnosticError :: new ( String :: from ( "There's no point of caching the output of a function that has no output" ) ) ) ;
371
367
}
372
368
}
373
369
@@ -407,15 +403,11 @@ fn get_args_and_types(f: &syn::ItemFn, config: &config::Config) ->
407
403
408
404
for input in & f. decl . inputs {
409
405
match input {
410
- syn:: FnArg :: SelfValue ( p) => {
411
- let diag = p. span ( ) . unstable ( )
412
- . error ( "`self` arguments are currently unsupported by lru_cache" ) ;
413
- return Err ( DiagnosticError :: new ( diag) ) ;
406
+ syn:: FnArg :: SelfValue ( _p) => {
407
+ return Err ( DiagnosticError :: new ( String :: from ( "`self` arguments are currently unsupported by lru_cache" ) ) ) ;
414
408
}
415
- syn:: FnArg :: SelfRef ( p) => {
416
- let diag = p. span ( ) . unstable ( )
417
- . error ( "`&self` arguments are currently unsupported by lru_cache" ) ;
418
- return Err ( DiagnosticError :: new ( diag) ) ;
409
+ syn:: FnArg :: SelfRef ( _p) => {
410
+ return Err ( DiagnosticError :: new ( String :: from ( "`&self` arguments are currently unsupported by lru_cache" ) ) ) ;
419
411
}
420
412
syn:: FnArg :: Captured ( arg_captured) => {
421
413
let mut segments: syn:: punctuated:: Punctuated < _ , Token ! [ :: ] > = syn:: punctuated:: Punctuated :: new ( ) ;
@@ -424,9 +416,7 @@ fn get_args_and_types(f: &syn::ItemFn, config: &config::Config) ->
424
416
arg_name = pat_ident. ident . clone ( ) ;
425
417
segments. push ( syn:: PathSegment { ident : pat_ident. ident . clone ( ) , arguments : syn:: PathArguments :: None } ) ;
426
418
} else {
427
- let diag = arg_captured. span ( ) . unstable ( )
428
- . error ( "unsupported argument kind" ) ;
429
- return Err ( DiagnosticError :: new ( diag) ) ;
419
+ return Err ( DiagnosticError :: new ( String :: from ( "unsupported argument kind" ) ) ) ;
430
420
}
431
421
432
422
let arg_path = syn:: Expr :: Path ( syn:: ExprPath { attrs : Vec :: new ( ) , qself : None , path : syn:: Path { leading_colon : None , segments } } ) ;
@@ -435,10 +425,8 @@ fn get_args_and_types(f: &syn::ItemFn, config: &config::Config) ->
435
425
436
426
// If the arg type is a reference, remove the reference because the arg will be cloned
437
427
if let syn:: Type :: Reference ( type_reference) = & arg_captured. ty {
438
- if let Some ( m) = type_reference. mutability {
439
- let diag = m. span . unstable ( )
440
- . error ( "`mut` reference arguments are not supported as this could lead to incorrect results being stored" ) ;
441
- return Err ( DiagnosticError :: new ( diag) ) ;
428
+ if let Some ( _m) = type_reference. mutability {
429
+ return Err ( DiagnosticError :: new ( String :: from ( "`mut` reference arguments are not supported as this could lead to incorrect results being stored" ) ) ) ;
442
430
}
443
431
types. push ( type_reference. elem . as_ref ( ) . to_owned ( ) ) ; // as_ref -> to_owned unboxes the type
444
432
} else {
@@ -451,15 +439,11 @@ fn get_args_and_types(f: &syn::ItemFn, config: &config::Config) ->
451
439
452
440
call_args. push ( arg_path) ;
453
441
} ,
454
- syn:: FnArg :: Inferred ( p) => {
455
- let diag = p. span ( ) . unstable ( )
456
- . error ( "inferred arguments are currently unsupported by lru_cache" ) ;
457
- return Err ( DiagnosticError :: new ( diag) ) ;
442
+ syn:: FnArg :: Inferred ( _p) => {
443
+ return Err ( DiagnosticError :: new ( String :: from ( "inferred arguments are currently unsupported by lru_cache" ) ) ) ;
458
444
}
459
- syn:: FnArg :: Ignored ( p) => {
460
- let diag = p. span ( ) . unstable ( )
461
- . error ( "ignored arguments are currently unsupported by lru_cache" ) ;
462
- return Err ( DiagnosticError :: new ( diag) ) ;
445
+ syn:: FnArg :: Ignored ( _p) => {
446
+ return Err ( DiagnosticError :: new ( String :: from ( "ignored arguments are currently unsupported by lru_cache" ) ) ) ;
463
447
}
464
448
}
465
449
}
0 commit comments