@@ -29,7 +29,7 @@ use syntax::ast;
29
29
use syntax:: attr;
30
30
use syntax:: ptr:: P ;
31
31
use syntax:: symbol:: keywords;
32
- use syntax_pos:: Span ;
32
+ use syntax_pos:: { mk_sp , Span } ;
33
33
use errors:: DiagnosticBuilder ;
34
34
use util:: nodemap:: { NodeMap , NodeSet , FxHashSet , FxHashMap , DefIdMap } ;
35
35
use rustc_back:: slice;
@@ -434,7 +434,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
434
434
self . resolve_elided_lifetimes ( slice:: ref_slice ( lifetime_ref) ) ;
435
435
return ;
436
436
}
437
- if lifetime_ref. name == keywords :: StaticLifetime . name ( ) {
437
+ if lifetime_ref. is_static ( ) {
438
438
self . insert_lifetime ( lifetime_ref, Region :: Static ) ;
439
439
return ;
440
440
}
@@ -1434,7 +1434,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1434
1434
let lifetime_i = & lifetimes[ i] ;
1435
1435
1436
1436
for lifetime in lifetimes {
1437
- if lifetime. lifetime . name == keywords :: StaticLifetime . name ( ) {
1437
+ if lifetime. lifetime . is_static ( ) {
1438
1438
let lifetime = lifetime. lifetime ;
1439
1439
let mut err = struct_span_err ! ( self . sess, lifetime. span, E0262 ,
1440
1440
"invalid lifetime parameter name: `{}`" , lifetime. name) ;
@@ -1464,7 +1464,17 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1464
1464
self . check_lifetime_def_for_shadowing ( old_scope, & lifetime_i. lifetime ) ;
1465
1465
1466
1466
for bound in & lifetime_i. bounds {
1467
- self . resolve_lifetime_ref ( bound) ;
1467
+ if !bound. is_static ( ) {
1468
+ self . resolve_lifetime_ref ( bound) ;
1469
+ } else {
1470
+ self . insert_lifetime ( bound, Region :: Static ) ;
1471
+ let full_span = mk_sp ( lifetime_i. lifetime . span . lo , bound. span . hi ) ;
1472
+ self . sess . struct_span_warn ( full_span,
1473
+ & format ! ( "unnecessary lifetime parameter `{}`" , lifetime_i. lifetime. name) )
1474
+ . help ( & format ! ( "you can use the `'static` lifetime directly, in place \
1475
+ of `{}`", lifetime_i. lifetime. name) )
1476
+ . emit ( ) ;
1477
+ }
1468
1478
}
1469
1479
}
1470
1480
}
0 commit comments