From e00fd781c91bc4b2703f25a75b0b28c775bd51b9 Mon Sep 17 00:00:00 2001 From: lcnr Date: Wed, 10 Jul 2024 14:45:07 +0200 Subject: [PATCH] simplify and future-proof `needs_normalization` --- .../rustc_trait_selection/src/traits/normalize.rs | 13 +++++-------- compiler/rustc_type_ir/src/flags.rs | 8 ++++---- compiler/rustc_type_ir/src/visit.rs | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/normalize.rs b/compiler/rustc_trait_selection/src/traits/normalize.rs index dda3aaaf71e82..3a7481acbafd3 100644 --- a/compiler/rustc_trait_selection/src/traits/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/normalize.rs @@ -109,16 +109,13 @@ pub(super) fn needs_normalization<'tcx, T: TypeVisitable>>( value: &T, reveal: Reveal, ) -> bool { - // This mirrors `ty::TypeFlags::HAS_ALIASES` except that we take `Reveal` into account. - - let mut flags = ty::TypeFlags::HAS_TY_PROJECTION - | ty::TypeFlags::HAS_TY_WEAK - | ty::TypeFlags::HAS_TY_INHERENT - | ty::TypeFlags::HAS_CT_PROJECTION; + let mut flags = ty::TypeFlags::HAS_ALIAS; + // Opaques are treated as rigid with `Reveal::UserFacing`, + // so we can ignore those. match reveal { - Reveal::UserFacing => {} - Reveal::All => flags |= ty::TypeFlags::HAS_TY_OPAQUE, + Reveal::UserFacing => flags.remove(ty::TypeFlags::HAS_TY_OPAQUE), + Reveal::All => {} } value.has_type_flags(flags) diff --git a/compiler/rustc_type_ir/src/flags.rs b/compiler/rustc_type_ir/src/flags.rs index 6a1ac642b70f7..81aa4a1f19ee0 100644 --- a/compiler/rustc_type_ir/src/flags.rs +++ b/compiler/rustc_type_ir/src/flags.rs @@ -14,7 +14,7 @@ bitflags::bitflags! { /// Does this have `ConstKind::Param`? const HAS_CT_PARAM = 1 << 2; - const HAS_PARAM = TypeFlags::HAS_TY_PARAM.bits() + const HAS_PARAM = TypeFlags::HAS_TY_PARAM.bits() | TypeFlags::HAS_RE_PARAM.bits() | TypeFlags::HAS_CT_PARAM.bits(); @@ -27,7 +27,7 @@ bitflags::bitflags! { /// Does this have inference variables? Used to determine whether /// inference is required. - const HAS_INFER = TypeFlags::HAS_TY_INFER.bits() + const HAS_INFER = TypeFlags::HAS_TY_INFER.bits() | TypeFlags::HAS_RE_INFER.bits() | TypeFlags::HAS_CT_INFER.bits(); @@ -39,7 +39,7 @@ bitflags::bitflags! { const HAS_CT_PLACEHOLDER = 1 << 8; /// Does this have placeholders? - const HAS_PLACEHOLDER = TypeFlags::HAS_TY_PLACEHOLDER.bits() + const HAS_PLACEHOLDER = TypeFlags::HAS_TY_PLACEHOLDER.bits() | TypeFlags::HAS_RE_PLACEHOLDER.bits() | TypeFlags::HAS_CT_PLACEHOLDER.bits(); @@ -81,7 +81,7 @@ bitflags::bitflags! { /// Does this have `Alias` or `ConstKind::Unevaluated`? /// /// Rephrased, could this term be normalized further? - const HAS_ALIASES = TypeFlags::HAS_TY_PROJECTION.bits() + const HAS_ALIAS = TypeFlags::HAS_TY_PROJECTION.bits() | TypeFlags::HAS_TY_WEAK.bits() | TypeFlags::HAS_TY_OPAQUE.bits() | TypeFlags::HAS_TY_INHERENT.bits() diff --git a/compiler/rustc_type_ir/src/visit.rs b/compiler/rustc_type_ir/src/visit.rs index 473a0aa250ffc..25eb56fe3fb51 100644 --- a/compiler/rustc_type_ir/src/visit.rs +++ b/compiler/rustc_type_ir/src/visit.rs @@ -230,7 +230,7 @@ pub trait TypeVisitableExt: TypeVisitable { } fn has_aliases(&self) -> bool { - self.has_type_flags(TypeFlags::HAS_ALIASES) + self.has_type_flags(TypeFlags::HAS_ALIAS) } fn has_inherent_projections(&self) -> bool {