@@ -1196,6 +1196,44 @@ where
11961196 self . delegate . evaluate_const ( param_env, uv)
11971197 }
11981198
1199+ pub ( super ) fn evaluate_const_and_instantiate_normalizes_to_term (
1200+ & mut self ,
1201+ goal : Goal < I , ty:: NormalizesTo < I > > ,
1202+ uv : ty:: UnevaluatedConst < I > ,
1203+ ) -> QueryResult < I > {
1204+ match self . evaluate_const ( goal. param_env , uv) {
1205+ Some ( evaluated) => {
1206+ self . instantiate_normalizes_to_term ( goal, evaluated. into ( ) ) ;
1207+ self . evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
1208+ }
1209+ None if self . cx ( ) . features ( ) . generic_const_args ( ) => {
1210+ // HACK(khyperia): calling `resolve_vars_if_possible` here shouldn't be necessary,
1211+ // `try_evaluate_const` calls `resolve_vars_if_possible` already. However, we want
1212+ // to check `has_non_region_infer` against the type with vars resolved (i.e. check
1213+ // if there are vars we failed to resolve), so we need to call it again here.
1214+ // Perhaps we could split EvaluateConstErr::HasGenericsOrInfers into HasGenerics and
1215+ // HasInfers or something, make evaluate_const return that, and make this branch be
1216+ // based on that, rather than checking `has_non_region_infer`.
1217+ if self . resolve_vars_if_possible ( uv) . has_non_region_infer ( ) {
1218+ self . evaluate_added_goals_and_make_canonical_response ( Certainty :: AMBIGUOUS )
1219+ } else {
1220+ // We do not instantiate to the `uv` passed in, but rather
1221+ // `goal.predicate.alias`. The `uv` passed in might correspond to the `impl`
1222+ // form of a constant (with generic arguments corresponding to the impl block),
1223+ // however, we want to structurally instantiate to the original, non-rebased,
1224+ // trait `Self` form of the constant (with generic arguments being the trait
1225+ // `Self` type).
1226+ self . structurally_instantiate_normalizes_to_term ( goal, goal. predicate . alias ) ;
1227+ self . evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
1228+ }
1229+ }
1230+ None => {
1231+ // Legacy behavior: always treat as ambiguous
1232+ self . evaluate_added_goals_and_make_canonical_response ( Certainty :: AMBIGUOUS )
1233+ }
1234+ }
1235+ }
1236+
11991237 pub ( super ) fn is_transmutable (
12001238 & mut self ,
12011239 src : I :: Ty ,
0 commit comments