Skip to content

Commit

Permalink
Fix order of normalization and recursion in const folding.
Browse files Browse the repository at this point in the history
Fixes rust-lang#126831.

Without this patch, type normalization is not always idempotent, which
leads to all sorts of bugs in places that assume that normalizing a
normalized type does nothing.
  • Loading branch information
veluca93 committed Aug 17, 2024
1 parent 426a60a commit 1077e36
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions compiler/rustc_trait_selection/src/traits/query/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,14 @@ impl<'cx, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'cx, 'tcx>
return Ok(constant);
}

let constant = constant.try_super_fold_with(self)?;
debug!(?constant, ?self.param_env);
Ok(crate::traits::with_replaced_escaping_bound_vars(
let constant = crate::traits::with_replaced_escaping_bound_vars(
self.infcx,
&mut self.universes,
constant,
|constant| constant.normalize(self.infcx.tcx, self.param_env),
))
);
debug!(?constant, ?self.param_env);
constant.try_super_fold_with(self)
}

#[inline]
Expand Down

0 comments on commit 1077e36

Please sign in to comment.