@@ -704,6 +704,13 @@ struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
704
704
/// [`elided_named_lifetimes`](lint::builtin::ELIDED_NAMED_LIFETIMES).
705
705
/// See comments in [`MissingLifetime::id_if_not_fake_or`].
706
706
crate_node_id : NodeId ,
707
+ /// Don't emit [`elided_named_lifetimes`](lint::builtin::ELIDED_NAMED_LIFETIMES)
708
+ /// when we are in a type annotation for a `const` or `static`.
709
+ /// ```rust
710
+ /// const HELLO_WORLD: &str = "Hello, world!";
711
+ /// static ZEROES: &[u8] = &[0, 0, 0];
712
+ /// ```
713
+ allow_elided_static : bool ,
707
714
}
708
715
709
716
/// Walks the whole crate in DFS order, visiting each item, resolving names as it goes.
@@ -1349,6 +1356,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1349
1356
in_func_body : false ,
1350
1357
lifetime_uses : Default :: default ( ) ,
1351
1358
crate_node_id : krate. id ,
1359
+ allow_elided_static : false ,
1352
1360
}
1353
1361
}
1354
1362
@@ -1559,6 +1567,13 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1559
1567
ret
1560
1568
}
1561
1569
1570
+ #[ instrument( level = "debug" , skip( self ) ) ]
1571
+ fn visit_ty_allow_elided_static ( & mut self , ty : & ' ast Ty ) {
1572
+ self . allow_elided_static = true ;
1573
+ self . visit_ty ( ty) ;
1574
+ self . allow_elided_static = false ;
1575
+ }
1576
+
1562
1577
#[ instrument( level = "debug" , skip( self ) ) ]
1563
1578
fn resolve_lifetime ( & mut self , lifetime : & ' ast Lifetime , use_ctxt : visit:: LifetimeCtxt ) {
1564
1579
let ident = lifetime. ident ;
@@ -2054,12 +2069,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2054
2069
debug_assert_eq ! ( id, missing. id) ;
2055
2070
match res {
2056
2071
LifetimeRes :: Static => {
2057
- self . r . lint_buffer . buffer_lint (
2058
- lint:: builtin:: ELIDED_NAMED_LIFETIMES ,
2059
- missing. id_if_not_fake_or ( self . crate_node_id ) ,
2060
- missing. span ,
2061
- BuiltinLintDiag :: ElidedIsStatic { elided : missing. span } ,
2062
- ) ;
2072
+ if !self . allow_elided_static {
2073
+ self . r . lint_buffer . buffer_lint (
2074
+ lint:: builtin:: ELIDED_NAMED_LIFETIMES ,
2075
+ missing. id_if_not_fake_or ( self . crate_node_id ) ,
2076
+ missing. span ,
2077
+ BuiltinLintDiag :: ElidedIsStatic { elided : missing. span } ,
2078
+ ) ;
2079
+ }
2063
2080
}
2064
2081
LifetimeRes :: Param { param, binder } => {
2065
2082
self . r . lint_buffer . buffer_lint (
@@ -2606,7 +2623,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2606
2623
ItemKind :: Static ( box ast:: StaticItem { ref ty, ref expr, .. } ) => {
2607
2624
self . with_static_rib ( def_kind, |this| {
2608
2625
this. with_lifetime_rib ( LifetimeRibKind :: Elided ( LifetimeRes :: Static ) , |this| {
2609
- this. visit_ty ( ty) ;
2626
+ this. visit_ty_allow_elided_static ( ty) ;
2610
2627
} ) ;
2611
2628
if let Some ( expr) = expr {
2612
2629
// We already forbid generic params because of the above item rib,
@@ -2637,7 +2654,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2637
2654
2638
2655
this. with_lifetime_rib (
2639
2656
LifetimeRibKind :: Elided ( LifetimeRes :: Static ) ,
2640
- |this| this. visit_ty ( ty) ,
2657
+ |this| this. visit_ty_allow_elided_static ( ty) ,
2641
2658
) ;
2642
2659
2643
2660
if let Some ( expr) = expr {
0 commit comments