@@ -312,8 +312,8 @@ enum LifetimeRibKind {
312
312
313
313
/// Resolves elided lifetimes to `'static` if there are no other lifetimes in scope,
314
314
/// otherwise give a warning that the previous behavior of introducing a new early-bound
315
- /// lifetime is a bug and will be removed.
316
- StaticIfNoLifetimeInScope ( NodeId ) ,
315
+ /// lifetime is a bug and will be removed (if `emit_lint` is enabled) .
316
+ StaticIfNoLifetimeInScope { lint_id : NodeId , emit_lint : bool } ,
317
317
318
318
/// Signal we cannot find which should be the anonymous lifetime.
319
319
ElisionFailure ,
@@ -1213,7 +1213,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
1213
1213
}
1214
1214
LifetimeRibKind :: AnonymousCreateParameter { .. }
1215
1215
| LifetimeRibKind :: AnonymousReportError
1216
- | LifetimeRibKind :: StaticIfNoLifetimeInScope ( _ )
1216
+ | LifetimeRibKind :: StaticIfNoLifetimeInScope { .. }
1217
1217
| LifetimeRibKind :: Elided ( _)
1218
1218
| LifetimeRibKind :: ElisionFailure
1219
1219
| LifetimeRibKind :: ConcreteAnonConst ( _)
@@ -1581,7 +1581,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1581
1581
// lifetime would be illegal.
1582
1582
LifetimeRibKind :: Item
1583
1583
| LifetimeRibKind :: AnonymousReportError
1584
- | LifetimeRibKind :: StaticIfNoLifetimeInScope ( _ )
1584
+ | LifetimeRibKind :: StaticIfNoLifetimeInScope { .. }
1585
1585
| LifetimeRibKind :: ElisionFailure => Some ( LifetimeUseSet :: Many ) ,
1586
1586
// An anonymous lifetime is legal here, and bound to the right
1587
1587
// place, go ahead.
@@ -1644,7 +1644,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1644
1644
| LifetimeRibKind :: Generics { .. }
1645
1645
| LifetimeRibKind :: ElisionFailure
1646
1646
| LifetimeRibKind :: AnonymousReportError
1647
- | LifetimeRibKind :: StaticIfNoLifetimeInScope ( _ ) => { }
1647
+ | LifetimeRibKind :: StaticIfNoLifetimeInScope { .. } => { }
1648
1648
}
1649
1649
}
1650
1650
@@ -1678,7 +1678,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1678
1678
self . record_lifetime_res ( lifetime. id , res, elision_candidate) ;
1679
1679
return ;
1680
1680
}
1681
- LifetimeRibKind :: StaticIfNoLifetimeInScope ( node_id) => {
1681
+ LifetimeRibKind :: StaticIfNoLifetimeInScope { lint_id : node_id, emit_lint } => {
1682
1682
let mut lifetimes_in_scope = vec ! [ ] ;
1683
1683
for rib in & self . lifetime_ribs [ ..i] {
1684
1684
lifetimes_in_scope. extend ( rib. bindings . iter ( ) . map ( |( ident, _) | ident. span ) ) ;
@@ -1696,7 +1696,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1696
1696
elision_candidate,
1697
1697
) ;
1698
1698
return ;
1699
- } else {
1699
+ } else if emit_lint {
1700
1700
self . r . lint_buffer . buffer_lint (
1701
1701
lint:: builtin:: ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT ,
1702
1702
node_id,
@@ -1925,7 +1925,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1925
1925
// impl Foo for std::cell::Ref<u32> // note lack of '_
1926
1926
// async fn foo(_: std::cell::Ref<u32>) { ... }
1927
1927
LifetimeRibKind :: AnonymousCreateParameter { report_in_path : true , .. }
1928
- | LifetimeRibKind :: StaticIfNoLifetimeInScope ( _ ) => {
1928
+ | LifetimeRibKind :: StaticIfNoLifetimeInScope { .. } => {
1929
1929
let sess = self . r . tcx . sess ;
1930
1930
let subdiag = rustc_errors:: elided_lifetime_in_path_suggestion (
1931
1931
sess. source_map ( ) ,
@@ -2859,19 +2859,27 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2859
2859
kind : LifetimeBinderKind :: ConstItem ,
2860
2860
} ,
2861
2861
|this| {
2862
- this. visit_generics ( generics) ;
2863
- this. visit_ty ( ty) ;
2864
-
2865
- // Only impose the restrictions of `ConstRibKind` for an
2866
- // actual constant expression in a provided default.
2867
- if let Some ( expr) = expr {
2868
- // We allow arbitrary const expressions inside of associated consts,
2869
- // even if they are potentially not const evaluatable.
2870
- //
2871
- // Type parameters can already be used and as associated consts are
2872
- // not used as part of the type system, this is far less surprising.
2873
- this. resolve_const_body ( expr, None ) ;
2874
- }
2862
+ this. with_lifetime_rib (
2863
+ LifetimeRibKind :: StaticIfNoLifetimeInScope {
2864
+ lint_id : item. id ,
2865
+ emit_lint : false ,
2866
+ } ,
2867
+ |this| {
2868
+ this. visit_generics ( generics) ;
2869
+ this. visit_ty ( ty) ;
2870
+
2871
+ // Only impose the restrictions of `ConstRibKind` for an
2872
+ // actual constant expression in a provided default.
2873
+ if let Some ( expr) = expr {
2874
+ // We allow arbitrary const expressions inside of associated consts,
2875
+ // even if they are potentially not const evaluatable.
2876
+ //
2877
+ // Type parameters can already be used and as associated consts are
2878
+ // not used as part of the type system, this is far less surprising.
2879
+ this. resolve_const_body ( expr, None ) ;
2880
+ }
2881
+ } ,
2882
+ )
2875
2883
} ,
2876
2884
) ;
2877
2885
}
@@ -3052,7 +3060,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
3052
3060
} ,
3053
3061
|this| {
3054
3062
this. with_lifetime_rib (
3055
- LifetimeRibKind :: StaticIfNoLifetimeInScope ( item. id ) ,
3063
+ LifetimeRibKind :: StaticIfNoLifetimeInScope {
3064
+ lint_id : item. id ,
3065
+ // In impls, it's not a hard error yet due to backcompat.
3066
+ emit_lint : true ,
3067
+ } ,
3056
3068
|this| {
3057
3069
// If this is a trait impl, ensure the const
3058
3070
// exists in trait
0 commit comments