|
15 | 15 | //! about it on zulip.
|
16 | 16 | use rustc_hir::def_id::DefId;
|
17 | 17 | use rustc_infer::infer::canonical::{Canonical, CanonicalVarValues};
|
18 |
| -use rustc_infer::infer::DefineOpaqueTypes; |
19 | 18 | use rustc_infer::traits::query::NoSolution;
|
20 | 19 | use rustc_middle::infer::canonical::CanonicalVarInfos;
|
21 | 20 | use rustc_middle::traits::solve::{
|
22 | 21 | CanonicalResponse, Certainty, ExternalConstraintsData, Goal, GoalSource, IsNormalizesToHack,
|
23 | 22 | QueryResult, Response,
|
24 | 23 | };
|
25 |
| -use rustc_middle::ty::{self, Ty, TyCtxt, UniverseIndex}; |
| 24 | +use rustc_middle::ty::{self, AliasRelationDirection, Ty, TyCtxt, UniverseIndex}; |
26 | 25 | use rustc_middle::ty::{
|
27 | 26 | CoercePredicate, RegionOutlivesPredicate, SubtypePredicate, TypeOutlivesPredicate,
|
28 | 27 | };
|
@@ -266,49 +265,32 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
266 | 265 | Ok(self.make_ambiguous_response_no_constraints(maybe_cause))
|
267 | 266 | }
|
268 | 267 |
|
269 |
| - /// Normalize a type when it is structually matched on. |
| 268 | + /// Normalize a type for when it is structurally matched on. |
270 | 269 | ///
|
271 |
| - /// In nearly all cases this function must be used before matching on a type. |
| 270 | + /// This function is necessary in nearly all cases before matching on a type. |
272 | 271 | /// Not doing so is likely to be incomplete and therefore unsound during
|
273 | 272 | /// coherence.
|
274 |
| - #[instrument(level = "debug", skip(self), ret)] |
275 |
| - fn try_normalize_ty( |
276 |
| - &mut self, |
277 |
| - param_env: ty::ParamEnv<'tcx>, |
278 |
| - ty: Ty<'tcx>, |
279 |
| - ) -> Option<Ty<'tcx>> { |
280 |
| - self.try_normalize_ty_recur(param_env, DefineOpaqueTypes::Yes, 0, ty) |
281 |
| - } |
282 |
| - |
283 |
| - fn try_normalize_ty_recur( |
| 273 | + fn structurally_normalize_ty( |
284 | 274 | &mut self,
|
285 | 275 | param_env: ty::ParamEnv<'tcx>,
|
286 |
| - define_opaque_types: DefineOpaqueTypes, |
287 |
| - depth: usize, |
288 | 276 | ty: Ty<'tcx>,
|
289 |
| - ) -> Option<Ty<'tcx>> { |
290 |
| - if !self.tcx().recursion_limit().value_within_limit(depth) { |
291 |
| - return None; |
292 |
| - } |
293 |
| - |
294 |
| - let ty::Alias(_, alias) = *ty.kind() else { |
295 |
| - return Some(ty); |
296 |
| - }; |
297 |
| - |
298 |
| - match self.commit_if_ok(|this| { |
299 |
| - let normalized_ty = this.next_ty_infer(); |
300 |
| - let normalizes_to_goal = Goal::new( |
301 |
| - this.tcx(), |
| 277 | + ) -> Result<Ty<'tcx>, NoSolution> { |
| 278 | + if let ty::Alias(..) = ty.kind() { |
| 279 | + let normalized_ty = self.next_ty_infer(); |
| 280 | + let alias_relate_goal = Goal::new( |
| 281 | + self.tcx(), |
302 | 282 | param_env,
|
303 |
| - ty::NormalizesTo { alias, term: normalized_ty.into() }, |
| 283 | + ty::PredicateKind::AliasRelate( |
| 284 | + ty.into(), |
| 285 | + normalized_ty.into(), |
| 286 | + AliasRelationDirection::Equate, |
| 287 | + ), |
304 | 288 | );
|
305 |
| - this.add_goal(GoalSource::Misc, normalizes_to_goal); |
306 |
| - this.try_evaluate_added_goals()?; |
307 |
| - let ty = this.resolve_vars_if_possible(normalized_ty); |
308 |
| - Ok(this.try_normalize_ty_recur(param_env, define_opaque_types, depth + 1, ty)) |
309 |
| - }) { |
310 |
| - Ok(ty) => ty, |
311 |
| - Err(NoSolution) => Some(ty), |
| 289 | + self.add_goal(GoalSource::Misc, alias_relate_goal); |
| 290 | + self.try_evaluate_added_goals()?; |
| 291 | + Ok(self.resolve_vars_if_possible(normalized_ty)) |
| 292 | + } else { |
| 293 | + Ok(ty) |
312 | 294 | }
|
313 | 295 | }
|
314 | 296 | }
|
|
0 commit comments