11use crate :: diagnostics:: { ImportSuggestion , LabelSuggestion , TypoSuggestion } ;
22use crate :: late:: { AliasPossibility , LateResolutionVisitor , RibKind } ;
33use crate :: late:: { LifetimeBinderKind , LifetimeRes , LifetimeRibKind , LifetimeUseSet } ;
4- use crate :: path_names_to_string;
4+ use crate :: { errors , path_names_to_string} ;
55use crate :: { Module , ModuleKind , ModuleOrUniformRoot } ;
66use crate :: { PathResult , PathSource , Segment } ;
77
@@ -22,7 +22,6 @@ use rustc_hir::def::{self, CtorKind, CtorOf, DefKind};
2222use rustc_hir:: def_id:: { DefId , CRATE_DEF_ID } ;
2323use rustc_hir:: PrimTy ;
2424use rustc_session:: lint;
25- use rustc_session:: parse:: feature_err;
2625use rustc_session:: Session ;
2726use rustc_span:: edit_distance:: find_best_match_for_name;
2827use rustc_span:: edition:: Edition ;
@@ -35,6 +34,8 @@ use std::ops::Deref;
3534
3635use thin_vec:: ThinVec ;
3736
37+ use super :: NoConstantGenericsReason ;
38+
3839type Res = def:: Res < ast:: NodeId > ;
3940
4041/// 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> {
23162317 }
23172318 }
23182319
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 ( ) ;
23322330 }
23332331
23342332 /// Non-static lifetimes are prohibited in anonymous constants under `min_const_generics`.
23352333 /// This function will emit an error if `generic_const_exprs` is not enabled, the body identified by
23362334 /// `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 (
23382336 & self ,
2337+ cause : NoConstantGenericsReason ,
23392338 lifetime_ref : & ast:: Lifetime ,
23402339 ) {
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+ }
23502370 }
23512371 }
23522372
0 commit comments