@@ -7,9 +7,10 @@ use rustc_ast::Mutability;
77use rustc_hir as hir;
88use rustc_infer:: infer:: { RegionResolutionError , TyCtxtInferExt } ;
99use rustc_middle:: ty:: { self , AdtDef , Ty , TyCtxt , TypeVisitableExt , TypingMode } ;
10+ use rustc_span:: sym;
1011
1112use crate :: regions:: InferCtxtRegionExt ;
12- use crate :: traits:: { self , FulfillmentError , ObligationCause } ;
13+ use crate :: traits:: { self , FulfillmentError , Obligation , ObligationCause } ;
1314
1415pub enum CopyImplementationError < ' tcx > {
1516 InfringingFields ( Vec < ( & ' tcx ty:: FieldDef , Ty < ' tcx > , InfringingFieldsReason < ' tcx > ) > ) ,
@@ -101,7 +102,9 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>(
101102 lang_item : LangItem ,
102103 parent_cause : ObligationCause < ' tcx > ,
103104) -> Result < ( ) , ConstParamTyImplementationError < ' tcx > > {
105+ // FIXME: remove the unsizedconstparamty item
104106 assert_matches ! ( lang_item, LangItem :: ConstParamTy | LangItem :: UnsizedConstParamTy ) ;
107+ let mut need_unstable_feature_bound = false ;
105108
106109 let inner_tys: Vec < _ > = match * self_type. kind ( ) {
107110 // Trivially okay as these types are all:
@@ -112,17 +115,14 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>(
112115
113116 // Handle types gated under `feature(unsized_const_params)`
114117 // FIXME(unsized_const_params): Make `const N: [u8]` work then forbid references
115- ty:: Slice ( inner_ty) | ty:: Ref ( _, inner_ty, Mutability :: Not )
116- if lang_item == LangItem :: UnsizedConstParamTy =>
117- {
118+ ty:: Slice ( inner_ty) | ty:: Ref ( _, inner_ty, Mutability :: Not ) => {
119+ need_unstable_feature_bound = true ;
118120 vec ! [ inner_ty]
119121 }
120- ty:: Str if lang_item == LangItem :: UnsizedConstParamTy => {
122+ ty:: Str => {
123+ need_unstable_feature_bound = true ;
121124 vec ! [ Ty :: new_slice( tcx, tcx. types. u8 ) ]
122125 }
123- ty:: Str | ty:: Slice ( ..) | ty:: Ref ( _, _, Mutability :: Not ) => {
124- return Err ( ConstParamTyImplementationError :: UnsizedConstParamsFeatureRequired ) ;
125- }
126126
127127 ty:: Array ( inner_ty, _) => vec ! [ inner_ty] ,
128128
@@ -153,6 +153,16 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>(
153153 let infcx = tcx. infer_ctxt ( ) . build ( TypingMode :: non_body_analysis ( ) ) ;
154154 let ocx = traits:: ObligationCtxt :: new_with_diagnostics ( & infcx) ;
155155
156+ // FIXME: add a comment here
157+ if need_unstable_feature_bound {
158+ ocx. register_obligation ( Obligation :: new (
159+ tcx,
160+ parent_cause. clone ( ) ,
161+ param_env,
162+ ty:: ClauseKind :: UnstableFeature ( sym:: unsized_const_params) ,
163+ ) )
164+ }
165+
156166 ocx. register_bound (
157167 parent_cause. clone ( ) ,
158168 param_env,
0 commit comments