@@ -311,6 +311,10 @@ enum LifetimeRibKind {
311
311
/// error on default object bounds (e.g., `Box<dyn Foo>`).
312
312
AnonymousReportError ,
313
313
314
+ /// Resolves elided lifetimes to `'static`, but gives a warning that this behavior
315
+ /// is a bug and will be reverted soon.
316
+ AnonymousWarnToStatic ( NodeId ) ,
317
+
314
318
/// Signal we cannot find which should be the anonymous lifetime.
315
319
ElisionFailure ,
316
320
@@ -1148,6 +1152,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
1148
1152
}
1149
1153
LifetimeRibKind :: AnonymousCreateParameter { .. }
1150
1154
| LifetimeRibKind :: AnonymousReportError
1155
+ | LifetimeRibKind :: AnonymousWarnToStatic ( _)
1151
1156
| LifetimeRibKind :: Elided ( _)
1152
1157
| LifetimeRibKind :: ElisionFailure
1153
1158
| LifetimeRibKind :: ConcreteAnonConst ( _)
@@ -1515,6 +1520,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1515
1520
// lifetime would be illegal.
1516
1521
LifetimeRibKind :: Item
1517
1522
| LifetimeRibKind :: AnonymousReportError
1523
+ | LifetimeRibKind :: AnonymousWarnToStatic ( _)
1518
1524
| LifetimeRibKind :: ElisionFailure => Some ( LifetimeUseSet :: Many ) ,
1519
1525
// An anonymous lifetime is legal here, and bound to the right
1520
1526
// place, go ahead.
@@ -1576,7 +1582,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1576
1582
| LifetimeRibKind :: Elided ( _)
1577
1583
| LifetimeRibKind :: Generics { .. }
1578
1584
| LifetimeRibKind :: ElisionFailure
1579
- | LifetimeRibKind :: AnonymousReportError => { }
1585
+ | LifetimeRibKind :: AnonymousReportError
1586
+ | LifetimeRibKind :: AnonymousWarnToStatic ( _) => { }
1580
1587
}
1581
1588
}
1582
1589
@@ -1616,6 +1623,25 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1616
1623
self . record_lifetime_res ( lifetime. id , res, elision_candidate) ;
1617
1624
return ;
1618
1625
}
1626
+ LifetimeRibKind :: AnonymousWarnToStatic ( node_id) => {
1627
+ self . record_lifetime_res ( lifetime. id , LifetimeRes :: Static , elision_candidate) ;
1628
+ let msg = if elided {
1629
+ "`&` without an explicit lifetime name cannot be used here"
1630
+ } else {
1631
+ "`'_` cannot be used here"
1632
+ } ;
1633
+ self . r . lint_buffer . buffer_lint_with_diagnostic (
1634
+ lint:: builtin:: ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT ,
1635
+ node_id,
1636
+ lifetime. ident . span ,
1637
+ msg,
1638
+ lint:: BuiltinLintDiagnostics :: AssociatedConstElidedLifetime {
1639
+ elided,
1640
+ span : lifetime. ident . span ,
1641
+ } ,
1642
+ ) ;
1643
+ return ;
1644
+ }
1619
1645
LifetimeRibKind :: AnonymousReportError => {
1620
1646
let ( msg, note) = if elided {
1621
1647
(
@@ -1811,7 +1837,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1811
1837
//
1812
1838
// impl Foo for std::cell::Ref<u32> // note lack of '_
1813
1839
// async fn foo(_: std::cell::Ref<u32>) { ... }
1814
- LifetimeRibKind :: AnonymousCreateParameter { report_in_path : true , .. } => {
1840
+ LifetimeRibKind :: AnonymousCreateParameter { report_in_path : true , .. }
1841
+ | LifetimeRibKind :: AnonymousWarnToStatic ( _) => {
1815
1842
let sess = self . r . tcx . sess ;
1816
1843
let mut err = rustc_errors:: struct_span_err!(
1817
1844
sess,
@@ -2898,7 +2925,6 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2898
2925
match & item. kind {
2899
2926
AssocItemKind :: Const ( box ast:: ConstItem { generics, ty, expr, .. } ) => {
2900
2927
debug ! ( "resolve_implementation AssocItemKind::Const" ) ;
2901
-
2902
2928
self . with_generic_param_rib (
2903
2929
& generics. params ,
2904
2930
RibKind :: AssocItem ,
@@ -2908,28 +2934,33 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2908
2934
kind : LifetimeBinderKind :: ConstItem ,
2909
2935
} ,
2910
2936
|this| {
2911
- // If this is a trait impl, ensure the const
2912
- // exists in trait
2913
- this. check_trait_item (
2914
- item. id ,
2915
- item. ident ,
2916
- & item. kind ,
2917
- ValueNS ,
2918
- item. span ,
2919
- seen_trait_items,
2920
- |i, s, c| ConstNotMemberOfTrait ( i, s, c) ,
2921
- ) ;
2937
+ this. with_lifetime_rib (
2938
+ LifetimeRibKind :: AnonymousWarnToStatic ( item. id ) ,
2939
+ |this| {
2940
+ // If this is a trait impl, ensure the const
2941
+ // exists in trait
2942
+ this. check_trait_item (
2943
+ item. id ,
2944
+ item. ident ,
2945
+ & item. kind ,
2946
+ ValueNS ,
2947
+ item. span ,
2948
+ seen_trait_items,
2949
+ |i, s, c| ConstNotMemberOfTrait ( i, s, c) ,
2950
+ ) ;
2922
2951
2923
- this. visit_generics ( generics) ;
2924
- this. visit_ty ( ty) ;
2925
- if let Some ( expr) = expr {
2926
- // We allow arbitrary const expressions inside of associated consts,
2927
- // even if they are potentially not const evaluatable.
2928
- //
2929
- // Type parameters can already be used and as associated consts are
2930
- // not used as part of the type system, this is far less surprising.
2931
- this. resolve_const_body ( expr, None ) ;
2932
- }
2952
+ this. visit_generics ( generics) ;
2953
+ this. visit_ty ( ty) ;
2954
+ if let Some ( expr) = expr {
2955
+ // We allow arbitrary const expressions inside of associated consts,
2956
+ // even if they are potentially not const evaluatable.
2957
+ //
2958
+ // Type parameters can already be used and as associated consts are
2959
+ // not used as part of the type system, this is far less surprising.
2960
+ this. resolve_const_body ( expr, None ) ;
2961
+ }
2962
+ } ,
2963
+ ) ;
2933
2964
} ,
2934
2965
) ;
2935
2966
}
0 commit comments