@@ -4,8 +4,9 @@ use hir::LangItem;
44use rustc_ast:: Mutability ;
55use rustc_hir as hir;
66use rustc_infer:: infer:: { RegionResolutionError , TyCtxtInferExt } ;
7+ use rustc_middle:: bug;
78use rustc_middle:: ty:: { self , AdtDef , Ty , TyCtxt , TypeVisitableExt , TypingMode , Unnormalized } ;
8- use rustc_span:: sym;
9+ use rustc_span:: { Span , sym} ;
910
1011use crate :: regions:: InferCtxtRegionExt ;
1112use crate :: traits:: { self , FulfillmentError , Obligation , ObligationCause } ;
@@ -22,6 +23,7 @@ pub enum ConstParamTyImplementationError<'tcx> {
2223 InvalidInnerTyOfBuiltinTy ( Vec < ( Ty < ' tcx > , InfringingFieldsReason < ' tcx > ) > ) ,
2324 InfrigingFields ( Vec < ( & ' tcx ty:: FieldDef , Ty < ' tcx > , InfringingFieldsReason < ' tcx > ) > ) ,
2425 NotAnAdtOrBuiltinAllowed ,
26+ NonExhaustive ( Span ) ,
2527}
2628
2729pub enum InfringingFieldsReason < ' tcx > {
@@ -124,6 +126,19 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>(
124126 ty:: Tuple ( inner_tys) => inner_tys. into_iter ( ) . collect ( ) ,
125127
126128 ty:: Adt ( adt, args) if adt. is_enum ( ) || adt. is_struct ( ) => {
129+ if !tcx. features ( ) . adt_const_params ( ) {
130+ for variant in adt. variants ( ) {
131+ if variant. is_field_list_non_exhaustive ( ) {
132+ let attr_span = match hir:: find_attr!( tcx, variant. def_id, hir:: attrs:: AttributeKind :: NonExhaustive ( span) => * span)
133+ {
134+ Some ( sp) => sp,
135+ None => bug ! ( "non_exhaustive variant missing NonExhaustive attribute" ) ,
136+ } ;
137+ return Err ( ConstParamTyImplementationError :: NonExhaustive ( attr_span) ) ;
138+ }
139+ }
140+ }
141+
127142 all_fields_implement_trait (
128143 tcx,
129144 param_env,
0 commit comments