normalization folders, yeet ParamEnv::reveal
This commit is contained in:
@@ -9,7 +9,7 @@ use rustc_macros::extension;
|
||||
pub use rustc_middle::traits::query::NormalizationResult;
|
||||
use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable};
|
||||
use rustc_middle::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor, TypingMode};
|
||||
use rustc_span::DUMMY_SP;
|
||||
use tracing::{debug, info, instrument};
|
||||
|
||||
@@ -21,7 +21,7 @@ use crate::infer::canonical::OriginalQueryValues;
|
||||
use crate::infer::{InferCtxt, InferOk};
|
||||
use crate::traits::normalize::needs_normalization;
|
||||
use crate::traits::{
|
||||
BoundVarReplacer, Normalized, ObligationCause, PlaceholderReplacer, Reveal, ScrubbedTraitError,
|
||||
BoundVarReplacer, Normalized, ObligationCause, PlaceholderReplacer, ScrubbedTraitError,
|
||||
};
|
||||
|
||||
#[extension(pub trait QueryNormalizeExt<'tcx>)]
|
||||
@@ -89,7 +89,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
if !needs_normalization(&value, self.param_env.reveal()) {
|
||||
if !needs_normalization(self.infcx, self.param_env, &value) {
|
||||
return Ok(Normalized { value, obligations: PredicateObligations::new() });
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'a, 'tcx> {
|
||||
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
fn try_fold_ty(&mut self, ty: Ty<'tcx>) -> Result<Ty<'tcx>, Self::Error> {
|
||||
if !needs_normalization(&ty, self.param_env.reveal()) {
|
||||
if !needs_normalization(self.infcx, self.param_env, &ty) {
|
||||
return Ok(ty);
|
||||
}
|
||||
|
||||
@@ -215,10 +215,12 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'a, 'tcx> {
|
||||
let res = match kind {
|
||||
ty::Opaque => {
|
||||
// Only normalize `impl Trait` outside of type inference, usually in codegen.
|
||||
match self.param_env.reveal() {
|
||||
Reveal::UserFacing => ty.try_super_fold_with(self)?,
|
||||
match self.infcx.typing_mode(self.param_env) {
|
||||
TypingMode::Coherence | TypingMode::Analysis { defining_opaque_types: _ } => {
|
||||
ty.try_super_fold_with(self)?
|
||||
}
|
||||
|
||||
Reveal::All => {
|
||||
TypingMode::PostAnalysis => {
|
||||
let args = data.args.try_fold_with(self)?;
|
||||
let recursion_limit = self.cx().recursion_limit();
|
||||
|
||||
@@ -332,7 +334,7 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'a, 'tcx> {
|
||||
&mut self,
|
||||
constant: ty::Const<'tcx>,
|
||||
) -> Result<ty::Const<'tcx>, Self::Error> {
|
||||
if !needs_normalization(&constant, self.param_env.reveal()) {
|
||||
if !needs_normalization(self.infcx, self.param_env, &constant) {
|
||||
return Ok(constant);
|
||||
}
|
||||
|
||||
@@ -351,7 +353,7 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'a, 'tcx> {
|
||||
&mut self,
|
||||
p: ty::Predicate<'tcx>,
|
||||
) -> Result<ty::Predicate<'tcx>, Self::Error> {
|
||||
if p.allow_normalization() && needs_normalization(&p, self.param_env.reveal()) {
|
||||
if p.allow_normalization() && needs_normalization(self.infcx, self.param_env, &p) {
|
||||
p.try_super_fold_with(self)
|
||||
} else {
|
||||
Ok(p)
|
||||
|
||||
Reference in New Issue
Block a user