1
1
use crate :: diagnostics:: { ImportSuggestion , LabelSuggestion , TypoSuggestion } ;
2
2
use crate :: late:: { AliasPossibility , LateResolutionVisitor , RibKind } ;
3
3
use crate :: late:: { LifetimeBinderKind , LifetimeRes , LifetimeRibKind , LifetimeUseSet } ;
4
- use crate :: path_names_to_string;
4
+ use crate :: { errors , path_names_to_string} ;
5
5
use crate :: { Module , ModuleKind , ModuleOrUniformRoot } ;
6
6
use crate :: { PathResult , PathSource , Segment } ;
7
7
@@ -22,7 +22,6 @@ use rustc_hir::def::{self, CtorKind, CtorOf, DefKind};
22
22
use rustc_hir:: def_id:: { DefId , CRATE_DEF_ID } ;
23
23
use rustc_hir:: PrimTy ;
24
24
use rustc_session:: lint;
25
- use rustc_session:: parse:: feature_err;
26
25
use rustc_session:: Session ;
27
26
use rustc_span:: edit_distance:: find_best_match_for_name;
28
27
use rustc_span:: edition:: Edition ;
@@ -35,6 +34,8 @@ use std::ops::Deref;
35
34
36
35
use thin_vec:: ThinVec ;
37
36
37
+ use super :: NoConstantGenericsReason ;
38
+
38
39
type Res = def:: Res < ast:: NodeId > ;
39
40
40
41
/// A field or associated item from self type suggested in case of resolution failure.
@@ -2316,37 +2317,56 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
2316
2317
}
2317
2318
}
2318
2319
2319
- pub ( crate ) fn emit_non_static_lt_in_const_generic_error ( & self , lifetime_ref : & ast:: Lifetime ) {
2320
- struct_span_err ! (
2321
- self . r. tcx. sess,
2322
- lifetime_ref. ident. span,
2323
- E0771 ,
2324
- "use of non-static lifetime `{}` in const generic" ,
2325
- lifetime_ref. ident
2326
- )
2327
- . note (
2328
- "for more information, see issue #74052 \
2329
- <https://github.com/rust-lang/rust/issues/74052>",
2330
- )
2331
- . emit ( ) ;
2320
+ pub ( crate ) fn emit_non_static_lt_in_const_param_ty_error ( & self , lifetime_ref : & ast:: Lifetime ) {
2321
+ self . r
2322
+ . tcx
2323
+ . sess
2324
+ . create_err ( errors:: ParamInTyOfConstParam {
2325
+ span : lifetime_ref. ident . span ,
2326
+ name : lifetime_ref. ident . name ,
2327
+ param_kind : Some ( errors:: ParamKindInTyOfConstParam :: Lifetime ) ,
2328
+ } )
2329
+ . emit ( ) ;
2332
2330
}
2333
2331
2334
2332
/// Non-static lifetimes are prohibited in anonymous constants under `min_const_generics`.
2335
2333
/// This function will emit an error if `generic_const_exprs` is not enabled, the body identified by
2336
2334
/// `body_id` is an anonymous constant and `lifetime_ref` is non-static.
2337
- pub ( crate ) fn maybe_emit_forbidden_non_static_lifetime_error (
2335
+ pub ( crate ) fn emit_forbidden_non_static_lifetime_error (
2338
2336
& self ,
2337
+ cause : NoConstantGenericsReason ,
2339
2338
lifetime_ref : & ast:: Lifetime ,
2340
2339
) {
2341
- let feature_active = self . r . tcx . sess . features_untracked ( ) . generic_const_exprs ;
2342
- if !feature_active {
2343
- feature_err (
2344
- & self . r . tcx . sess . parse_sess ,
2345
- sym:: generic_const_exprs,
2346
- lifetime_ref. ident . span ,
2347
- "a non-static lifetime is not allowed in a `const`" ,
2348
- )
2349
- . emit ( ) ;
2340
+ match cause {
2341
+ NoConstantGenericsReason :: IsEnumDiscriminant => {
2342
+ self . r
2343
+ . tcx
2344
+ . sess
2345
+ . create_err ( errors:: ParamInEnumDiscriminant {
2346
+ span : lifetime_ref. ident . span ,
2347
+ name : lifetime_ref. ident . name ,
2348
+ param_kind : errors:: ParamKindInEnumDiscriminant :: Lifetime ,
2349
+ } )
2350
+ . emit ( ) ;
2351
+ }
2352
+ NoConstantGenericsReason :: NonTrivialConstArg => {
2353
+ assert ! ( !self . r. tcx. features( ) . generic_const_exprs) ;
2354
+ self . r
2355
+ . tcx
2356
+ . sess
2357
+ . create_err ( errors:: ParamInNonTrivialAnonConst {
2358
+ span : lifetime_ref. ident . span ,
2359
+ name : lifetime_ref. ident . name ,
2360
+ param_kind : errors:: ParamKindInNonTrivialAnonConst :: Lifetime ,
2361
+ help : self
2362
+ . r
2363
+ . tcx
2364
+ . sess
2365
+ . is_nightly_build ( )
2366
+ . then_some ( errors:: ParamInNonTrivialAnonConstHelp ) ,
2367
+ } )
2368
+ . emit ( ) ;
2369
+ }
2350
2370
}
2351
2371
}
2352
2372
0 commit comments