@@ -25,7 +25,7 @@ use rustc_middle::traits::solve::{
2525} ;
2626use rustc_middle:: ty:: {
2727 self , AliasRelationDirection , CoercePredicate , RegionOutlivesPredicate , SubtypePredicate , Ty ,
28- TyCtxt , TypeOutlivesPredicate , UniverseIndex ,
28+ TyCtxt , TypeOutlivesPredicate , TypeVisitableExt , UniverseIndex ,
2929} ;
3030
3131mod alias_relate;
@@ -208,22 +208,58 @@ impl<'a, 'tcx> EvalCtxt<'a, InferCtxt<'tcx>> {
208208 // We do still stall on infer vars though as otherwise a goal like:
209209 // `ConstArgHasType(?x: usize, usize)` can succeed even though it might later
210210 // get unified with some const that is not of type `usize`.
211- match ct. kind ( ) {
211+ let ct_ty = match ct. kind ( ) {
212212 // FIXME: Ignore effect vars because canonicalization doesn't handle them correctly
213213 // and if we stall on the var then we wind up creating ambiguity errors in a probe
214214 // for this goal which contains an effect var. Which then ends up ICEing.
215- ty:: ConstKind :: Infer ( ty:: InferConst :: Var ( _) ) => {
216- self . evaluate_added_goals_and_make_canonical_response ( Certainty :: AMBIGUOUS )
215+ ty:: ConstKind :: Infer ( ty:: InferConst :: EffectVar ( _) ) => {
216+ return self . evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes ) ;
217+ }
218+ ty:: ConstKind :: Infer ( _) => {
219+ return self . evaluate_added_goals_and_make_canonical_response ( Certainty :: AMBIGUOUS ) ;
217220 }
218221 ty:: ConstKind :: Error ( _) => {
219- self . evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
222+ return self . evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes ) ;
220223 }
221- _ => {
222- // THISPR
223- self . eq ( goal. param_env , todo ! ( ) , ty) ?;
224- self . evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
224+ ty:: ConstKind :: Unevaluated ( uv) => {
225+ self . interner ( ) . type_of ( uv. def ) . instantiate ( self . interner ( ) , uv. args )
225226 }
226- }
227+ ty:: ConstKind :: Expr ( _) => unimplemented ! (
228+ "`feature(generic_const_exprs)` is not supported in the new trait solver"
229+ ) ,
230+ ty:: ConstKind :: Param ( _) => {
231+ unreachable ! ( "`ConstKind::Param` should have been canonicalized to `Placeholder`" )
232+ }
233+ ty:: ConstKind :: Bound ( _, _) => bug ! ( "escaping bound vars in {:?}" , ct) ,
234+ ty:: ConstKind :: Value ( ty, _) => ty,
235+ ty:: ConstKind :: Placeholder ( placeholder) => {
236+ let mut candidates = goal. param_env . caller_bounds ( ) . iter ( ) . filter_map ( |clause| {
237+ // `ConstArgHasType` are never desugared to be higher ranked.
238+ match clause. kind ( ) . skip_binder ( ) {
239+ ty:: ClauseKind :: ConstArgHasType ( placeholder_ct, ty) => {
240+ assert ! ( !( placeholder_ct, ty) . has_escaping_bound_vars( ) ) ;
241+
242+ match placeholder_ct. kind ( ) {
243+ ty:: ConstKind :: Placeholder ( placeholder_ct)
244+ if placeholder_ct == placeholder =>
245+ {
246+ Some ( ty)
247+ }
248+ _ => None ,
249+ }
250+ }
251+ _ => None ,
252+ }
253+ } ) ;
254+
255+ let ty = candidates. next ( ) . unwrap ( ) ;
256+ assert ! ( candidates. next( ) . is_none( ) ) ;
257+ ty
258+ }
259+ } ;
260+
261+ self . eq ( goal. param_env , ct_ty, ty) ?;
262+ self . evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
227263 }
228264}
229265
0 commit comments