@@ -704,14 +704,6 @@ struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
704704 /// [`elided_named_lifetimes`](lint::builtin::ELIDED_NAMED_LIFETIMES).
705705 /// See comments in [`MissingLifetime::id_if_exists_in_source_or`].
706706 crate_node_id : NodeId ,
707-
708- /// Don't emit [`elided_named_lifetimes`](lint::builtin::ELIDED_NAMED_LIFETIMES)
709- /// when we are in a type annotation for a `const` or `static`.
710- /// ```rust
711- /// const HELLO_WORLD: &str = "Hello, world!";
712- /// static ZEROES: &[u8] = &[0, 0, 0];
713- /// ```
714- warn_elided_static : bool ,
715707}
716708
717709/// Walks the whole crate in DFS order, visiting each item, resolving names as it goes.
@@ -1357,7 +1349,6 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
13571349 in_func_body : false ,
13581350 lifetime_uses : Default :: default ( ) ,
13591351 crate_node_id : krate. id ,
1360- warn_elided_static : true ,
13611352 }
13621353 }
13631354
@@ -1568,21 +1559,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
15681559 ret
15691560 }
15701561
1571- #[ instrument( level = "debug" , skip( self ) ) ]
1572- fn visit_ty_do_not_warn_elided_static ( & mut self , ty : & ' ast Ty ) {
1573- self . warn_elided_static = false ;
1574- self . visit_ty ( ty) ;
1575- self . warn_elided_static = true ;
1576- }
1577-
15781562 #[ instrument( level = "debug" , skip( self ) ) ]
15791563 fn resolve_lifetime ( & mut self , lifetime : & ' ast Lifetime , use_ctxt : visit:: LifetimeCtxt ) {
15801564 let ident = lifetime. ident ;
15811565
15821566 if ident. name == kw:: StaticLifetime {
15831567 self . record_lifetime_res (
15841568 lifetime. id ,
1585- LifetimeRes :: Static ,
1569+ LifetimeRes :: Static { suppress_elision_warning : false } ,
15861570 LifetimeElisionCandidate :: Named ,
15871571 ) ;
15881572 return ;
@@ -1722,7 +1706,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
17221706 if lifetimes_in_scope. is_empty ( ) {
17231707 self . record_lifetime_res (
17241708 lifetime. id ,
1725- LifetimeRes :: Static ,
1709+ // We are inside a const item, so do not warn.
1710+ LifetimeRes :: Static { suppress_elision_warning : true } ,
17261711 elision_candidate,
17271712 ) ;
17281713 return ;
@@ -2069,8 +2054,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
20692054 LifetimeElisionCandidate :: Missing ( missing @ MissingLifetime { span : elided, .. } ) => {
20702055 debug_assert_eq ! ( id, missing. id) ;
20712056 match res {
2072- LifetimeRes :: Static => {
2073- if self . warn_elided_static {
2057+ LifetimeRes :: Static { suppress_elision_warning } => {
2058+ if !suppress_elision_warning {
20742059 self . r . lint_buffer . buffer_lint (
20752060 lint:: builtin:: ELIDED_NAMED_LIFETIMES ,
20762061 missing. id_if_exists_in_source_or ( self . crate_node_id ) ,
@@ -2106,7 +2091,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
21062091 }
21072092
21082093 match res {
2109- LifetimeRes :: Param { .. } | LifetimeRes :: Fresh { .. } | LifetimeRes :: Static => {
2094+ LifetimeRes :: Param { .. } | LifetimeRes :: Fresh { .. } | LifetimeRes :: Static { .. } => {
21102095 if let Some ( ref mut candidates) = self . lifetime_elision_candidates {
21112096 candidates. push ( ( res, candidate) ) ;
21122097 }
@@ -2624,9 +2609,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
26242609
26252610 ItemKind :: Static ( box ast:: StaticItem { ref ty, ref expr, .. } ) => {
26262611 self . with_static_rib ( def_kind, |this| {
2627- this. with_lifetime_rib ( LifetimeRibKind :: Elided ( LifetimeRes :: Static ) , |this| {
2628- this. visit_ty_do_not_warn_elided_static ( ty) ;
2629- } ) ;
2612+ this. with_lifetime_rib (
2613+ LifetimeRibKind :: Elided ( LifetimeRes :: Static {
2614+ suppress_elision_warning : true ,
2615+ } ) ,
2616+ |this| {
2617+ this. visit_ty ( ty) ;
2618+ } ,
2619+ ) ;
26302620 if let Some ( expr) = expr {
26312621 // We already forbid generic params because of the above item rib,
26322622 // so it doesn't matter whether this is a trivial constant.
@@ -2655,8 +2645,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
26552645 this. visit_generics ( generics) ;
26562646
26572647 this. with_lifetime_rib (
2658- LifetimeRibKind :: Elided ( LifetimeRes :: Static ) ,
2659- |this| this. visit_ty_do_not_warn_elided_static ( ty) ,
2648+ LifetimeRibKind :: Elided ( LifetimeRes :: Static {
2649+ suppress_elision_warning : true ,
2650+ } ) ,
2651+ |this| this. visit_ty ( ty) ,
26602652 ) ;
26612653
26622654 if let Some ( expr) = expr {
@@ -2983,7 +2975,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
29832975 } ,
29842976 |this| {
29852977 this. visit_generics ( generics) ;
2986- this. visit_ty_do_not_warn_elided_static ( ty) ;
2978+ this. visit_ty ( ty) ;
29872979
29882980 // Only impose the restrictions of `ConstRibKind` for an
29892981 // actual constant expression in a provided default.
@@ -3196,7 +3188,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
31963188 ) ;
31973189
31983190 this. visit_generics ( generics) ;
3199- this. visit_ty_do_not_warn_elided_static ( ty) ;
3191+ this. visit_ty ( ty) ;
32003192 if let Some ( expr) = expr {
32013193 // We allow arbitrary const expressions inside of associated consts,
32023194 // even if they are potentially not const evaluatable.
0 commit comments