|
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 | }; |
@@ -285,49 +284,32 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { |
285 | 284 | Ok(self.make_ambiguous_response_no_constraints(maybe_cause)) |
286 | 285 | } |
287 | 286 |
|
288 | | - /// Normalize a type when it is structually matched on. |
| 287 | + /// Normalize a type for when it is structurally matched on. |
289 | 288 | /// |
290 | | - /// In nearly all cases this function must be used before matching on a type. |
| 289 | + /// This function is necessary in nearly all cases before matching on a type. |
291 | 290 | /// Not doing so is likely to be incomplete and therefore unsound during |
292 | 291 | /// coherence. |
293 | | - #[instrument(level = "debug", skip(self), ret)] |
294 | | - fn try_normalize_ty( |
295 | | - &mut self, |
296 | | - param_env: ty::ParamEnv<'tcx>, |
297 | | - ty: Ty<'tcx>, |
298 | | - ) -> Option<Ty<'tcx>> { |
299 | | - self.try_normalize_ty_recur(param_env, DefineOpaqueTypes::Yes, 0, ty) |
300 | | - } |
301 | | - |
302 | | - fn try_normalize_ty_recur( |
| 292 | + fn structurally_normalize_ty( |
303 | 293 | &mut self, |
304 | 294 | param_env: ty::ParamEnv<'tcx>, |
305 | | - define_opaque_types: DefineOpaqueTypes, |
306 | | - depth: usize, |
307 | 295 | ty: Ty<'tcx>, |
308 | | - ) -> Option<Ty<'tcx>> { |
309 | | - if !self.tcx().recursion_limit().value_within_limit(depth) { |
310 | | - return None; |
311 | | - } |
312 | | - |
313 | | - let ty::Alias(_, alias) = *ty.kind() else { |
314 | | - return Some(ty); |
315 | | - }; |
316 | | - |
317 | | - match self.commit_if_ok(|this| { |
318 | | - let normalized_ty = this.next_ty_infer(); |
319 | | - let normalizes_to_goal = Goal::new( |
320 | | - this.tcx(), |
| 296 | + ) -> Result<Ty<'tcx>, NoSolution> { |
| 297 | + if let ty::Alias(..) = ty.kind() { |
| 298 | + let normalized_ty = self.next_ty_infer(); |
| 299 | + let alias_relate_goal = Goal::new( |
| 300 | + self.tcx(), |
321 | 301 | param_env, |
322 | | - ty::NormalizesTo { alias, term: normalized_ty.into() }, |
| 302 | + ty::PredicateKind::AliasRelate( |
| 303 | + ty.into(), |
| 304 | + normalized_ty.into(), |
| 305 | + AliasRelationDirection::Equate, |
| 306 | + ), |
323 | 307 | ); |
324 | | - this.add_goal(GoalSource::Misc, normalizes_to_goal); |
325 | | - this.try_evaluate_added_goals()?; |
326 | | - let ty = this.resolve_vars_if_possible(normalized_ty); |
327 | | - Ok(this.try_normalize_ty_recur(param_env, define_opaque_types, depth + 1, ty)) |
328 | | - }) { |
329 | | - Ok(ty) => ty, |
330 | | - Err(NoSolution) => Some(ty), |
| 308 | + self.add_goal(GoalSource::Misc, alias_relate_goal); |
| 309 | + self.try_evaluate_added_goals()?; |
| 310 | + Ok(self.resolve_vars_if_possible(normalized_ty)) |
| 311 | + } else { |
| 312 | + Ok(ty) |
331 | 313 | } |
332 | 314 | } |
333 | 315 | } |
|
0 commit comments