@@ -704,14 +704,6 @@ struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
704
704
/// [`elided_named_lifetimes`](lint::builtin::ELIDED_NAMED_LIFETIMES).
705
705
/// See comments in [`MissingLifetime::id_if_exists_in_source_or`].
706
706
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 ,
715
707
}
716
708
717
709
/// 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> {
1357
1349
in_func_body : false ,
1358
1350
lifetime_uses : Default :: default ( ) ,
1359
1351
crate_node_id : krate. id ,
1360
- warn_elided_static : true ,
1361
1352
}
1362
1353
}
1363
1354
@@ -1568,21 +1559,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1568
1559
ret
1569
1560
}
1570
1561
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
-
1578
1562
#[ instrument( level = "debug" , skip( self ) ) ]
1579
1563
fn resolve_lifetime ( & mut self , lifetime : & ' ast Lifetime , use_ctxt : visit:: LifetimeCtxt ) {
1580
1564
let ident = lifetime. ident ;
1581
1565
1582
1566
if ident. name == kw:: StaticLifetime {
1583
1567
self . record_lifetime_res (
1584
1568
lifetime. id ,
1585
- LifetimeRes :: Static ,
1569
+ LifetimeRes :: Static { suppress_elision_warning : false } ,
1586
1570
LifetimeElisionCandidate :: Named ,
1587
1571
) ;
1588
1572
return ;
@@ -1722,7 +1706,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1722
1706
if lifetimes_in_scope. is_empty ( ) {
1723
1707
self . record_lifetime_res (
1724
1708
lifetime. id ,
1725
- LifetimeRes :: Static ,
1709
+ // We are inside a const item, so do not warn.
1710
+ LifetimeRes :: Static { suppress_elision_warning : true } ,
1726
1711
elision_candidate,
1727
1712
) ;
1728
1713
return ;
@@ -2069,8 +2054,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2069
2054
LifetimeElisionCandidate :: Missing ( missing @ MissingLifetime { span : elided, .. } ) => {
2070
2055
debug_assert_eq ! ( id, missing. id) ;
2071
2056
match res {
2072
- LifetimeRes :: Static => {
2073
- if self . warn_elided_static {
2057
+ LifetimeRes :: Static { suppress_elision_warning } => {
2058
+ if !suppress_elision_warning {
2074
2059
self . r . lint_buffer . buffer_lint (
2075
2060
lint:: builtin:: ELIDED_NAMED_LIFETIMES ,
2076
2061
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> {
2106
2091
}
2107
2092
2108
2093
match res {
2109
- LifetimeRes :: Param { .. } | LifetimeRes :: Fresh { .. } | LifetimeRes :: Static => {
2094
+ LifetimeRes :: Param { .. } | LifetimeRes :: Fresh { .. } | LifetimeRes :: Static { .. } => {
2110
2095
if let Some ( ref mut candidates) = self . lifetime_elision_candidates {
2111
2096
candidates. push ( ( res, candidate) ) ;
2112
2097
}
@@ -2624,9 +2609,14 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2624
2609
2625
2610
ItemKind :: Static ( box ast:: StaticItem { ref ty, ref expr, .. } ) => {
2626
2611
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
+ ) ;
2630
2620
if let Some ( expr) = expr {
2631
2621
// We already forbid generic params because of the above item rib,
2632
2622
// 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> {
2655
2645
this. visit_generics ( generics) ;
2656
2646
2657
2647
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) ,
2660
2652
) ;
2661
2653
2662
2654
if let Some ( expr) = expr {
@@ -2983,7 +2975,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2983
2975
} ,
2984
2976
|this| {
2985
2977
this. visit_generics ( generics) ;
2986
- this. visit_ty_do_not_warn_elided_static ( ty) ;
2978
+ this. visit_ty ( ty) ;
2987
2979
2988
2980
// Only impose the restrictions of `ConstRibKind` for an
2989
2981
// actual constant expression in a provided default.
@@ -3196,7 +3188,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
3196
3188
) ;
3197
3189
3198
3190
this. visit_generics ( generics) ;
3199
- this. visit_ty_do_not_warn_elided_static ( ty) ;
3191
+ this. visit_ty ( ty) ;
3200
3192
if let Some ( expr) = expr {
3201
3193
// We allow arbitrary const expressions inside of associated consts,
3202
3194
// even if they are potentially not const evaluatable.
0 commit comments