@@ -7,9 +7,10 @@ use rustc_ast::Mutability;
7
7
use rustc_hir as hir;
8
8
use rustc_infer:: infer:: { RegionResolutionError , TyCtxtInferExt } ;
9
9
use rustc_middle:: ty:: { self , AdtDef , Ty , TyCtxt , TypeVisitableExt , TypingMode } ;
10
+ use rustc_span:: sym;
10
11
11
12
use crate :: regions:: InferCtxtRegionExt ;
12
- use crate :: traits:: { self , FulfillmentError , ObligationCause } ;
13
+ use crate :: traits:: { self , FulfillmentError , Obligation , ObligationCause } ;
13
14
14
15
pub enum CopyImplementationError < ' tcx > {
15
16
InfringingFields ( Vec < ( & ' tcx ty:: FieldDef , Ty < ' tcx > , InfringingFieldsReason < ' tcx > ) > ) ,
@@ -101,7 +102,9 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>(
101
102
lang_item : LangItem ,
102
103
parent_cause : ObligationCause < ' tcx > ,
103
104
) -> Result < ( ) , ConstParamTyImplementationError < ' tcx > > {
105
+ // FIXME: remove the unsizedconstparamty item
104
106
assert_matches ! ( lang_item, LangItem :: ConstParamTy | LangItem :: UnsizedConstParamTy ) ;
107
+ let mut need_unstable_feature_bound = false ;
105
108
106
109
let inner_tys: Vec < _ > = match * self_type. kind ( ) {
107
110
// Trivially okay as these types are all:
@@ -112,17 +115,14 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>(
112
115
113
116
// Handle types gated under `feature(unsized_const_params)`
114
117
// 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 ;
118
120
vec ! [ inner_ty]
119
121
}
120
- ty:: Str if lang_item == LangItem :: UnsizedConstParamTy => {
122
+ ty:: Str => {
123
+ need_unstable_feature_bound = true ;
121
124
vec ! [ Ty :: new_slice( tcx, tcx. types. u8 ) ]
122
125
}
123
- ty:: Str | ty:: Slice ( ..) | ty:: Ref ( _, _, Mutability :: Not ) => {
124
- return Err ( ConstParamTyImplementationError :: UnsizedConstParamsFeatureRequired ) ;
125
- }
126
126
127
127
ty:: Array ( inner_ty, _) => vec ! [ inner_ty] ,
128
128
@@ -153,6 +153,16 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>(
153
153
let infcx = tcx. infer_ctxt ( ) . build ( TypingMode :: non_body_analysis ( ) ) ;
154
154
let ocx = traits:: ObligationCtxt :: new_with_diagnostics ( & infcx) ;
155
155
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
+
156
166
ocx. register_bound (
157
167
parent_cause. clone ( ) ,
158
168
param_env,
0 commit comments