summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_middle/src/traits
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /compiler/rustc_middle/src/traits
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_middle/src/traits')
-rw-r--r--compiler/rustc_middle/src/traits/chalk.rs396
-rw-r--r--compiler/rustc_middle/src/traits/mod.rs192
-rw-r--r--compiler/rustc_middle/src/traits/query.rs2
-rw-r--r--compiler/rustc_middle/src/traits/solve.rs26
-rw-r--r--compiler/rustc_middle/src/traits/solve/inspect.rs83
-rw-r--r--compiler/rustc_middle/src/traits/solve/inspect/format.rs131
-rw-r--r--compiler/rustc_middle/src/traits/specialization_graph.rs2
-rw-r--r--compiler/rustc_middle/src/traits/structural_impls.rs96
-rw-r--r--compiler/rustc_middle/src/traits/util.rs4
9 files changed, 261 insertions, 671 deletions
diff --git a/compiler/rustc_middle/src/traits/chalk.rs b/compiler/rustc_middle/src/traits/chalk.rs
deleted file mode 100644
index fcc8f457a..000000000
--- a/compiler/rustc_middle/src/traits/chalk.rs
+++ /dev/null
@@ -1,396 +0,0 @@
-//! Types required for Chalk-related queries
-//!
-//! The primary purpose of this file is defining an implementation for the
-//! `chalk_ir::interner::Interner` trait. The primary purpose of this trait, as
-//! its name suggest, is to provide an abstraction boundary for creating
-//! interned Chalk types.
-
-use rustc_middle::ty::{self, AdtDef, TyCtxt};
-
-use rustc_hir::def_id::DefId;
-use rustc_target::spec::abi::Abi;
-
-use std::cmp::Ordering;
-use std::fmt;
-use std::hash::{Hash, Hasher};
-
-#[derive(Copy, Clone)]
-pub struct RustInterner<'tcx> {
- pub tcx: TyCtxt<'tcx>,
-}
-
-/// We don't ever actually need this. It's only required for derives.
-impl<'tcx> Hash for RustInterner<'tcx> {
- fn hash<H: Hasher>(&self, _state: &mut H) {}
-}
-
-/// We don't ever actually need this. It's only required for derives.
-impl<'tcx> Ord for RustInterner<'tcx> {
- fn cmp(&self, _other: &Self) -> Ordering {
- Ordering::Equal
- }
-}
-
-/// We don't ever actually need this. It's only required for derives.
-impl<'tcx> PartialOrd for RustInterner<'tcx> {
- fn partial_cmp(&self, _other: &Self) -> Option<Ordering> {
- None
- }
-}
-
-/// We don't ever actually need this. It's only required for derives.
-impl<'tcx> PartialEq for RustInterner<'tcx> {
- fn eq(&self, _other: &Self) -> bool {
- false
- }
-}
-
-/// We don't ever actually need this. It's only required for derives.
-impl<'tcx> Eq for RustInterner<'tcx> {}
-
-impl fmt::Debug for RustInterner<'_> {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "RustInterner")
- }
-}
-
-// Right now, there is no interning at all. I was running into problems with
-// adding interning in `ty/context.rs` for Chalk types with
-// `parallel-compiler = true`. -jackh726
-impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> {
- type InternedType = Box<chalk_ir::TyData<Self>>;
- type InternedLifetime = Box<chalk_ir::LifetimeData<Self>>;
- type InternedConst = Box<chalk_ir::ConstData<Self>>;
- type InternedConcreteConst = ty::ValTree<'tcx>;
- type InternedGenericArg = Box<chalk_ir::GenericArgData<Self>>;
- type InternedGoal = Box<chalk_ir::GoalData<Self>>;
- type InternedGoals = Vec<chalk_ir::Goal<Self>>;
- type InternedSubstitution = Vec<chalk_ir::GenericArg<Self>>;
- type InternedProgramClause = Box<chalk_ir::ProgramClauseData<Self>>;
- type InternedProgramClauses = Vec<chalk_ir::ProgramClause<Self>>;
- type InternedQuantifiedWhereClauses = Vec<chalk_ir::QuantifiedWhereClause<Self>>;
- type InternedVariableKinds = Vec<chalk_ir::VariableKind<Self>>;
- type InternedCanonicalVarKinds = Vec<chalk_ir::CanonicalVarKind<Self>>;
- type InternedVariances = Vec<chalk_ir::Variance>;
- type InternedConstraints = Vec<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>>;
- type DefId = DefId;
- type InternedAdtId = AdtDef<'tcx>;
- type Identifier = ();
- type FnAbi = Abi;
-
- fn debug_program_clause_implication(
- pci: &chalk_ir::ProgramClauseImplication<Self>,
- fmt: &mut fmt::Formatter<'_>,
- ) -> Option<fmt::Result> {
- let mut write = || {
- write!(fmt, "{:?}", pci.consequence)?;
-
- let conditions = pci.conditions.interned();
- let constraints = pci.constraints.interned();
-
- let conds = conditions.len();
- let consts = constraints.len();
- if conds == 0 && consts == 0 {
- return Ok(());
- }
-
- write!(fmt, " :- ")?;
-
- if conds != 0 {
- for cond in &conditions[..conds - 1] {
- write!(fmt, "{:?}, ", cond)?;
- }
- write!(fmt, "{:?}", conditions[conds - 1])?;
- }
-
- if conds != 0 && consts != 0 {
- write!(fmt, " ; ")?;
- }
-
- if consts != 0 {
- for constraint in &constraints[..consts - 1] {
- write!(fmt, "{:?}, ", constraint)?;
- }
- write!(fmt, "{:?}", constraints[consts - 1])?;
- }
-
- Ok(())
- };
- Some(write())
- }
-
- fn debug_substitution(
- substitution: &chalk_ir::Substitution<Self>,
- fmt: &mut fmt::Formatter<'_>,
- ) -> Option<fmt::Result> {
- Some(write!(fmt, "{:?}", substitution.interned()))
- }
-
- fn debug_separator_trait_ref(
- separator_trait_ref: &chalk_ir::SeparatorTraitRef<'_, Self>,
- fmt: &mut fmt::Formatter<'_>,
- ) -> Option<fmt::Result> {
- let substitution = &separator_trait_ref.trait_ref.substitution;
- let parameters = substitution.interned();
- Some(write!(
- fmt,
- "{:?}{}{:?}{:?}",
- parameters[0],
- separator_trait_ref.separator,
- separator_trait_ref.trait_ref.trait_id,
- chalk_ir::debug::Angle(&parameters[1..])
- ))
- }
-
- fn debug_quantified_where_clauses(
- clauses: &chalk_ir::QuantifiedWhereClauses<Self>,
- fmt: &mut fmt::Formatter<'_>,
- ) -> Option<fmt::Result> {
- Some(write!(fmt, "{:?}", clauses.interned()))
- }
-
- fn debug_ty(ty: &chalk_ir::Ty<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
- match &ty.interned().kind {
- chalk_ir::TyKind::Ref(chalk_ir::Mutability::Not, lifetime, ty) => {
- Some(write!(fmt, "(&{:?} {:?})", lifetime, ty))
- }
- chalk_ir::TyKind::Ref(chalk_ir::Mutability::Mut, lifetime, ty) => {
- Some(write!(fmt, "(&{:?} mut {:?})", lifetime, ty))
- }
- chalk_ir::TyKind::Array(ty, len) => Some(write!(fmt, "[{:?}; {:?}]", ty, len)),
- chalk_ir::TyKind::Slice(ty) => Some(write!(fmt, "[{:?}]", ty)),
- chalk_ir::TyKind::Tuple(len, substs) => Some(
- try {
- write!(fmt, "(")?;
- for (idx, substitution) in substs.interned().iter().enumerate() {
- if idx == *len && *len != 1 {
- // Don't add a trailing comma if the tuple has more than one element
- write!(fmt, "{:?}", substitution)?;
- } else {
- write!(fmt, "{:?},", substitution)?;
- }
- }
- write!(fmt, ")")?;
- },
- ),
- _ => None,
- }
- }
-
- fn debug_alias(
- alias_ty: &chalk_ir::AliasTy<Self>,
- fmt: &mut fmt::Formatter<'_>,
- ) -> Option<fmt::Result> {
- match alias_ty {
- chalk_ir::AliasTy::Projection(projection_ty) => {
- Self::debug_projection_ty(projection_ty, fmt)
- }
- chalk_ir::AliasTy::Opaque(opaque_ty) => Self::debug_opaque_ty(opaque_ty, fmt),
- }
- }
-
- fn debug_projection_ty(
- projection_ty: &chalk_ir::ProjectionTy<Self>,
- fmt: &mut fmt::Formatter<'_>,
- ) -> Option<fmt::Result> {
- Some(write!(
- fmt,
- "projection: {:?} {:?}",
- projection_ty.associated_ty_id, projection_ty.substitution,
- ))
- }
-
- fn debug_opaque_ty(
- opaque_ty: &chalk_ir::OpaqueTy<Self>,
- fmt: &mut fmt::Formatter<'_>,
- ) -> Option<fmt::Result> {
- Some(write!(fmt, "{:?}", opaque_ty.opaque_ty_id))
- }
-
- fn intern_ty(self, ty: chalk_ir::TyKind<Self>) -> Self::InternedType {
- let flags = ty.compute_flags(self);
- Box::new(chalk_ir::TyData { kind: ty, flags: flags })
- }
-
- fn ty_data(self, ty: &Self::InternedType) -> &chalk_ir::TyData<Self> {
- ty
- }
-
- fn intern_lifetime(self, lifetime: chalk_ir::LifetimeData<Self>) -> Self::InternedLifetime {
- Box::new(lifetime)
- }
-
- fn lifetime_data(self, lifetime: &Self::InternedLifetime) -> &chalk_ir::LifetimeData<Self> {
- &lifetime
- }
-
- fn intern_const(self, constant: chalk_ir::ConstData<Self>) -> Self::InternedConst {
- Box::new(constant)
- }
-
- fn const_data(self, constant: &Self::InternedConst) -> &chalk_ir::ConstData<Self> {
- &constant
- }
-
- fn const_eq(
- self,
- _ty: &Self::InternedType,
- c1: &Self::InternedConcreteConst,
- c2: &Self::InternedConcreteConst,
- ) -> bool {
- c1 == c2
- }
-
- fn intern_generic_arg(self, data: chalk_ir::GenericArgData<Self>) -> Self::InternedGenericArg {
- Box::new(data)
- }
-
- fn generic_arg_data(self, data: &Self::InternedGenericArg) -> &chalk_ir::GenericArgData<Self> {
- &data
- }
-
- fn intern_goal(self, goal: chalk_ir::GoalData<Self>) -> Self::InternedGoal {
- Box::new(goal)
- }
-
- fn goal_data(self, goal: &Self::InternedGoal) -> &chalk_ir::GoalData<Self> {
- &goal
- }
-
- fn intern_goals<E>(
- self,
- data: impl IntoIterator<Item = Result<chalk_ir::Goal<Self>, E>>,
- ) -> Result<Self::InternedGoals, E> {
- data.into_iter().collect::<Result<Vec<_>, _>>()
- }
-
- fn goals_data(self, goals: &Self::InternedGoals) -> &[chalk_ir::Goal<Self>] {
- goals
- }
-
- fn intern_substitution<E>(
- self,
- data: impl IntoIterator<Item = Result<chalk_ir::GenericArg<Self>, E>>,
- ) -> Result<Self::InternedSubstitution, E> {
- data.into_iter().collect::<Result<Vec<_>, _>>()
- }
-
- fn substitution_data(
- self,
- substitution: &Self::InternedSubstitution,
- ) -> &[chalk_ir::GenericArg<Self>] {
- substitution
- }
-
- fn intern_program_clause(
- self,
- data: chalk_ir::ProgramClauseData<Self>,
- ) -> Self::InternedProgramClause {
- Box::new(data)
- }
-
- fn program_clause_data(
- self,
- clause: &Self::InternedProgramClause,
- ) -> &chalk_ir::ProgramClauseData<Self> {
- &clause
- }
-
- fn intern_program_clauses<E>(
- self,
- data: impl IntoIterator<Item = Result<chalk_ir::ProgramClause<Self>, E>>,
- ) -> Result<Self::InternedProgramClauses, E> {
- data.into_iter().collect::<Result<Vec<_>, _>>()
- }
-
- fn program_clauses_data(
- self,
- clauses: &Self::InternedProgramClauses,
- ) -> &[chalk_ir::ProgramClause<Self>] {
- clauses
- }
-
- fn intern_quantified_where_clauses<E>(
- self,
- data: impl IntoIterator<Item = Result<chalk_ir::QuantifiedWhereClause<Self>, E>>,
- ) -> Result<Self::InternedQuantifiedWhereClauses, E> {
- data.into_iter().collect::<Result<Vec<_>, _>>()
- }
-
- fn quantified_where_clauses_data(
- self,
- clauses: &Self::InternedQuantifiedWhereClauses,
- ) -> &[chalk_ir::QuantifiedWhereClause<Self>] {
- clauses
- }
-
- fn intern_generic_arg_kinds<E>(
- self,
- data: impl IntoIterator<Item = Result<chalk_ir::VariableKind<Self>, E>>,
- ) -> Result<Self::InternedVariableKinds, E> {
- data.into_iter().collect::<Result<Vec<_>, _>>()
- }
-
- fn variable_kinds_data(
- self,
- parameter_kinds: &Self::InternedVariableKinds,
- ) -> &[chalk_ir::VariableKind<Self>] {
- parameter_kinds
- }
-
- fn intern_canonical_var_kinds<E>(
- self,
- data: impl IntoIterator<Item = Result<chalk_ir::CanonicalVarKind<Self>, E>>,
- ) -> Result<Self::InternedCanonicalVarKinds, E> {
- data.into_iter().collect::<Result<Vec<_>, _>>()
- }
-
- fn canonical_var_kinds_data(
- self,
- canonical_var_kinds: &Self::InternedCanonicalVarKinds,
- ) -> &[chalk_ir::CanonicalVarKind<Self>] {
- canonical_var_kinds
- }
-
- fn intern_constraints<E>(
- self,
- data: impl IntoIterator<Item = Result<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>, E>>,
- ) -> Result<Self::InternedConstraints, E> {
- data.into_iter().collect::<Result<Vec<_>, _>>()
- }
-
- fn constraints_data(
- self,
- constraints: &Self::InternedConstraints,
- ) -> &[chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>] {
- constraints
- }
-
- fn intern_variances<E>(
- self,
- data: impl IntoIterator<Item = Result<chalk_ir::Variance, E>>,
- ) -> Result<Self::InternedVariances, E> {
- data.into_iter().collect::<Result<Vec<_>, _>>()
- }
-
- fn variances_data(self, variances: &Self::InternedVariances) -> &[chalk_ir::Variance] {
- variances
- }
-}
-
-impl<'tcx> chalk_ir::interner::HasInterner for RustInterner<'tcx> {
- type Interner = Self;
-}
-
-/// A chalk environment and goal.
-#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable, TypeVisitable)]
-pub struct ChalkEnvironmentAndGoal<'tcx> {
- pub environment: &'tcx ty::List<ty::Predicate<'tcx>>,
- pub goal: ty::Predicate<'tcx>,
-}
-
-impl<'tcx> fmt::Display for ChalkEnvironmentAndGoal<'tcx> {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "environment: {:?}, goal: {}", self.environment, self.goal)
- }
-}
diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs
index 0a903a769..c7d2e4c22 100644
--- a/compiler/rustc_middle/src/traits/mod.rs
+++ b/compiler/rustc_middle/src/traits/mod.rs
@@ -2,7 +2,6 @@
//!
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/resolution.html
-mod chalk;
pub mod query;
pub mod select;
pub mod solve;
@@ -30,12 +29,8 @@ use std::hash::{Hash, Hasher};
pub use self::select::{EvaluationCache, EvaluationResult, OverflowError, SelectionCache};
-pub type CanonicalChalkEnvironmentAndGoal<'tcx> = Canonical<'tcx, ChalkEnvironmentAndGoal<'tcx>>;
-
pub use self::ObligationCauseCode::*;
-pub use self::chalk::{ChalkEnvironmentAndGoal, RustInterner as ChalkRustInterner};
-
/// Depending on the stage of compilation, we want projection to be
/// more or less conservative.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, HashStable, Encodable, Decodable)]
@@ -445,6 +440,12 @@ pub enum ObligationCauseCode<'tcx> {
/// Obligations to prove that a `std::ops::Drop` impl is not stronger than
/// the ADT it's being implemented for.
DropImpl,
+
+ /// Requirement for a `const N: Ty` to implement `Ty: ConstParamTy`
+ ConstParam(Ty<'tcx>),
+
+ /// Obligations emitted during the normalization of a weak type alias.
+ TypeAlias(InternedObligationCauseCode<'tcx>, Span, DefId),
}
/// The 'location' at which we try to perform HIR-based wf checking.
@@ -587,6 +588,10 @@ pub enum SelectionError<'tcx> {
/// Signaling that an error has already been emitted, to avoid
/// multiple errors being shown.
ErrorReporting,
+ /// Computing an opaque type's hidden type caused an error (e.g. a cycle error).
+ /// We can thus not know whether the hidden type implements an auto trait, so
+ /// we should not presume anything about it.
+ OpaqueTypeAutoTraitLeakageUnknown(DefId),
}
#[derive(Clone, Debug, TypeVisitable, Lift)]
@@ -640,12 +645,6 @@ pub enum ImplSource<'tcx, N> {
/// ImplSource identifying a particular impl.
UserDefined(ImplSourceUserDefinedData<'tcx, N>),
- /// ImplSource for auto trait implementations.
- /// This carries the information and nested obligations with regards
- /// to an auto implementation for a trait `Trait`. The nested obligations
- /// ensure the trait implementation holds for all the constituent types.
- AutoImpl(ImplSourceAutoImplData<N>),
-
/// Successful resolution to an obligation provided by the caller
/// for some type parameter. The `Vec<N>` represents the
/// obligations incurred from normalizing the where-clause (if
@@ -653,84 +652,40 @@ pub enum ImplSource<'tcx, N> {
Param(Vec<N>, ty::BoundConstness),
/// Virtual calls through an object.
- Object(ImplSourceObjectData<'tcx, N>),
+ Object(ImplSourceObjectData<N>),
/// Successful resolution for a builtin trait.
- Builtin(ImplSourceBuiltinData<N>),
+ Builtin(Vec<N>),
/// ImplSource for trait upcasting coercion
- TraitUpcasting(ImplSourceTraitUpcastingData<'tcx, N>),
-
- /// ImplSource automatically generated for a closure. The `DefId` is the ID
- /// of the closure expression. This is an `ImplSource::UserDefined` in spirit, but the
- /// impl is generated by the compiler and does not appear in the source.
- Closure(ImplSourceClosureData<'tcx, N>),
-
- /// Same as above, but for a function pointer type with the given signature.
- FnPointer(ImplSourceFnPointerData<'tcx, N>),
-
- /// ImplSource automatically generated for a generator.
- Generator(ImplSourceGeneratorData<'tcx, N>),
-
- /// ImplSource automatically generated for a generator backing an async future.
- Future(ImplSourceFutureData<'tcx, N>),
-
- /// ImplSource for a trait alias.
- TraitAlias(ImplSourceTraitAliasData<'tcx, N>),
-
- /// ImplSource for a `const Drop` implementation.
- ConstDestruct(ImplSourceConstDestructData<N>),
+ TraitUpcasting(ImplSourceTraitUpcastingData<N>),
}
impl<'tcx, N> ImplSource<'tcx, N> {
pub fn nested_obligations(self) -> Vec<N> {
match self {
ImplSource::UserDefined(i) => i.nested,
- ImplSource::Param(n, _) => n,
- ImplSource::Builtin(i) => i.nested,
- ImplSource::AutoImpl(d) => d.nested,
- ImplSource::Closure(c) => c.nested,
- ImplSource::Generator(c) => c.nested,
- ImplSource::Future(c) => c.nested,
+ ImplSource::Param(n, _) | ImplSource::Builtin(n) => n,
ImplSource::Object(d) => d.nested,
- ImplSource::FnPointer(d) => d.nested,
- ImplSource::TraitAlias(d) => d.nested,
ImplSource::TraitUpcasting(d) => d.nested,
- ImplSource::ConstDestruct(i) => i.nested,
}
}
pub fn borrow_nested_obligations(&self) -> &[N] {
match self {
ImplSource::UserDefined(i) => &i.nested,
- ImplSource::Param(n, _) => n,
- ImplSource::Builtin(i) => &i.nested,
- ImplSource::AutoImpl(d) => &d.nested,
- ImplSource::Closure(c) => &c.nested,
- ImplSource::Generator(c) => &c.nested,
- ImplSource::Future(c) => &c.nested,
+ ImplSource::Param(n, _) | ImplSource::Builtin(n) => &n,
ImplSource::Object(d) => &d.nested,
- ImplSource::FnPointer(d) => &d.nested,
- ImplSource::TraitAlias(d) => &d.nested,
ImplSource::TraitUpcasting(d) => &d.nested,
- ImplSource::ConstDestruct(i) => &i.nested,
}
}
pub fn borrow_nested_obligations_mut(&mut self) -> &mut [N] {
match self {
ImplSource::UserDefined(i) => &mut i.nested,
- ImplSource::Param(n, _) => n,
- ImplSource::Builtin(i) => &mut i.nested,
- ImplSource::AutoImpl(d) => &mut d.nested,
- ImplSource::Closure(c) => &mut c.nested,
- ImplSource::Generator(c) => &mut c.nested,
- ImplSource::Future(c) => &mut c.nested,
+ ImplSource::Param(n, _) | ImplSource::Builtin(n) => n,
ImplSource::Object(d) => &mut d.nested,
- ImplSource::FnPointer(d) => &mut d.nested,
- ImplSource::TraitAlias(d) => &mut d.nested,
ImplSource::TraitUpcasting(d) => &mut d.nested,
- ImplSource::ConstDestruct(i) => &mut i.nested,
}
}
@@ -745,54 +700,17 @@ impl<'tcx, N> ImplSource<'tcx, N> {
nested: i.nested.into_iter().map(f).collect(),
}),
ImplSource::Param(n, ct) => ImplSource::Param(n.into_iter().map(f).collect(), ct),
- ImplSource::Builtin(i) => ImplSource::Builtin(ImplSourceBuiltinData {
- nested: i.nested.into_iter().map(f).collect(),
- }),
+ ImplSource::Builtin(n) => ImplSource::Builtin(n.into_iter().map(f).collect()),
ImplSource::Object(o) => ImplSource::Object(ImplSourceObjectData {
- upcast_trait_ref: o.upcast_trait_ref,
vtable_base: o.vtable_base,
nested: o.nested.into_iter().map(f).collect(),
}),
- ImplSource::AutoImpl(d) => ImplSource::AutoImpl(ImplSourceAutoImplData {
- trait_def_id: d.trait_def_id,
- nested: d.nested.into_iter().map(f).collect(),
- }),
- ImplSource::Closure(c) => ImplSource::Closure(ImplSourceClosureData {
- closure_def_id: c.closure_def_id,
- substs: c.substs,
- nested: c.nested.into_iter().map(f).collect(),
- }),
- ImplSource::Generator(c) => ImplSource::Generator(ImplSourceGeneratorData {
- generator_def_id: c.generator_def_id,
- substs: c.substs,
- nested: c.nested.into_iter().map(f).collect(),
- }),
- ImplSource::Future(c) => ImplSource::Future(ImplSourceFutureData {
- generator_def_id: c.generator_def_id,
- substs: c.substs,
- nested: c.nested.into_iter().map(f).collect(),
- }),
- ImplSource::FnPointer(p) => ImplSource::FnPointer(ImplSourceFnPointerData {
- fn_ty: p.fn_ty,
- nested: p.nested.into_iter().map(f).collect(),
- }),
- ImplSource::TraitAlias(d) => ImplSource::TraitAlias(ImplSourceTraitAliasData {
- alias_def_id: d.alias_def_id,
- substs: d.substs,
- nested: d.nested.into_iter().map(f).collect(),
- }),
ImplSource::TraitUpcasting(d) => {
ImplSource::TraitUpcasting(ImplSourceTraitUpcastingData {
- upcast_trait_ref: d.upcast_trait_ref,
vtable_vptr_slot: d.vtable_vptr_slot,
nested: d.nested.into_iter().map(f).collect(),
})
}
- ImplSource::ConstDestruct(i) => {
- ImplSource::ConstDestruct(ImplSourceConstDestructData {
- nested: i.nested.into_iter().map(f).collect(),
- })
- }
}
}
}
@@ -817,47 +735,7 @@ pub struct ImplSourceUserDefinedData<'tcx, N> {
#[derive(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Lift)]
#[derive(TypeFoldable, TypeVisitable)]
-pub struct ImplSourceGeneratorData<'tcx, N> {
- pub generator_def_id: DefId,
- pub substs: SubstsRef<'tcx>,
- /// Nested obligations. This can be non-empty if the generator
- /// signature contains associated types.
- pub nested: Vec<N>,
-}
-
-#[derive(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Lift)]
-#[derive(TypeFoldable, TypeVisitable)]
-pub struct ImplSourceFutureData<'tcx, N> {
- pub generator_def_id: DefId,
- pub substs: SubstsRef<'tcx>,
- /// Nested obligations. This can be non-empty if the generator
- /// signature contains associated types.
- pub nested: Vec<N>,
-}
-
-#[derive(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Lift)]
-#[derive(TypeFoldable, TypeVisitable)]
-pub struct ImplSourceClosureData<'tcx, N> {
- pub closure_def_id: DefId,
- pub substs: SubstsRef<'tcx>,
- /// Nested obligations. This can be non-empty if the closure
- /// signature contains associated types.
- pub nested: Vec<N>,
-}
-
-#[derive(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Lift)]
-#[derive(TypeFoldable, TypeVisitable)]
-pub struct ImplSourceAutoImplData<N> {
- pub trait_def_id: DefId,
- pub nested: Vec<N>,
-}
-
-#[derive(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Lift)]
-#[derive(TypeFoldable, TypeVisitable)]
-pub struct ImplSourceTraitUpcastingData<'tcx, N> {
- /// `Foo` upcast to the obligation trait. This will be some supertrait of `Foo`.
- pub upcast_trait_ref: ty::PolyTraitRef<'tcx>,
-
+pub struct ImplSourceTraitUpcastingData<N> {
/// The vtable is formed by concatenating together the method lists of
/// the base object trait and all supertraits, pointers to supertrait vtable will
/// be provided when necessary; this is the position of `upcast_trait_ref`'s vtable
@@ -867,18 +745,9 @@ pub struct ImplSourceTraitUpcastingData<'tcx, N> {
pub nested: Vec<N>,
}
-#[derive(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Lift)]
-#[derive(TypeFoldable, TypeVisitable)]
-pub struct ImplSourceBuiltinData<N> {
- pub nested: Vec<N>,
-}
-
#[derive(PartialEq, Eq, Clone, TyEncodable, TyDecodable, HashStable, Lift)]
#[derive(TypeFoldable, TypeVisitable)]
-pub struct ImplSourceObjectData<'tcx, N> {
- /// `Foo` upcast to the obligation trait. This will be some supertrait of `Foo`.
- pub upcast_trait_ref: ty::PolyTraitRef<'tcx>,
-
+pub struct ImplSourceObjectData<N> {
/// The vtable is formed by concatenating together the method lists of
/// the base object trait and all supertraits, pointers to supertrait vtable will
/// be provided when necessary; this is the start of `upcast_trait_ref`'s methods
@@ -888,27 +757,6 @@ pub struct ImplSourceObjectData<'tcx, N> {
pub nested: Vec<N>,
}
-#[derive(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Lift)]
-#[derive(TypeFoldable, TypeVisitable)]
-pub struct ImplSourceFnPointerData<'tcx, N> {
- pub fn_ty: Ty<'tcx>,
- pub nested: Vec<N>,
-}
-
-#[derive(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Lift)]
-#[derive(TypeFoldable, TypeVisitable)]
-pub struct ImplSourceConstDestructData<N> {
- pub nested: Vec<N>,
-}
-
-#[derive(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Lift)]
-#[derive(TypeFoldable, TypeVisitable)]
-pub struct ImplSourceTraitAliasData<'tcx, N> {
- pub alias_def_id: DefId,
- pub substs: SubstsRef<'tcx>,
- pub nested: Vec<N>,
-}
-
#[derive(Clone, Debug, PartialEq, Eq, Hash, HashStable, PartialOrd, Ord)]
pub enum ObjectSafetyViolation {
/// `Self: Sized` declared on the trait.
@@ -1109,7 +957,7 @@ pub enum CodegenObligationError {
FulfillmentError,
}
-#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, TypeFoldable, TypeVisitable)]
+#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, HashStable, TypeFoldable, TypeVisitable)]
pub enum DefiningAnchor {
/// `DefId` of the item.
Bind(LocalDefId),
diff --git a/compiler/rustc_middle/src/traits/query.rs b/compiler/rustc_middle/src/traits/query.rs
index eae5a280e..60a38747f 100644
--- a/compiler/rustc_middle/src/traits/query.rs
+++ b/compiler/rustc_middle/src/traits/query.rs
@@ -92,7 +92,7 @@ pub type CanonicalTypeOpProvePredicateGoal<'tcx> =
pub type CanonicalTypeOpNormalizeGoal<'tcx, T> =
Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::Normalize<T>>>;
-#[derive(Copy, Clone, Debug, HashStable, PartialEq, Eq)]
+#[derive(Copy, Clone, Debug, Hash, HashStable, PartialEq, Eq)]
pub struct NoSolution;
impl<'tcx> From<TypeError<'tcx>> for NoSolution {
diff --git a/compiler/rustc_middle/src/traits/solve.rs b/compiler/rustc_middle/src/traits/solve.rs
index 2c5b64a59..73b332fd8 100644
--- a/compiler/rustc_middle/src/traits/solve.rs
+++ b/compiler/rustc_middle/src/traits/solve.rs
@@ -11,6 +11,8 @@ use crate::ty::{
TypeVisitor,
};
+pub mod inspect;
+
pub type EvaluationCache<'tcx> = Cache<CanonicalInput<'tcx>, QueryResult<'tcx>>;
/// A goal is a statement, i.e. `predicate`, we want to prove
@@ -18,7 +20,7 @@ pub type EvaluationCache<'tcx> = Cache<CanonicalInput<'tcx>, QueryResult<'tcx>>;
///
/// Most of the time the `param_env` contains the `where`-bounds of the function
/// we're currently typechecking while the `predicate` is some trait bound.
-#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, TypeFoldable, TypeVisitable)]
+#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, HashStable, TypeFoldable, TypeVisitable)]
pub struct Goal<'tcx, P> {
pub predicate: P,
pub param_env: ty::ParamEnv<'tcx>,
@@ -39,7 +41,7 @@ impl<'tcx, P> Goal<'tcx, P> {
}
}
-#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, TypeFoldable, TypeVisitable)]
+#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, HashStable, TypeFoldable, TypeVisitable)]
pub struct Response<'tcx> {
pub certainty: Certainty,
pub var_values: CanonicalVarValues<'tcx>,
@@ -47,7 +49,7 @@ pub struct Response<'tcx> {
pub external_constraints: ExternalConstraints<'tcx>,
}
-#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, TypeFoldable, TypeVisitable)]
+#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, HashStable, TypeFoldable, TypeVisitable)]
pub enum Certainty {
Yes,
Maybe(MaybeCause),
@@ -86,7 +88,7 @@ impl Certainty {
}
/// Why we failed to evaluate a goal.
-#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, TypeFoldable, TypeVisitable)]
+#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, HashStable, TypeFoldable, TypeVisitable)]
pub enum MaybeCause {
/// We failed due to ambiguity. This ambiguity can either
/// be a true ambiguity, i.e. there are multiple different answers,
@@ -96,7 +98,7 @@ pub enum MaybeCause {
Overflow,
}
-#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, TypeFoldable, TypeVisitable)]
+#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, HashStable, TypeFoldable, TypeVisitable)]
pub struct QueryInput<'tcx, T> {
pub goal: Goal<'tcx, T>,
pub anchor: DefiningAnchor,
@@ -104,12 +106,12 @@ pub struct QueryInput<'tcx, T> {
}
/// Additional constraints returned on success.
-#[derive(Debug, PartialEq, Eq, Clone, Hash, Default)]
+#[derive(Debug, PartialEq, Eq, Clone, Hash, HashStable, Default)]
pub struct PredefinedOpaquesData<'tcx> {
pub opaque_types: Vec<(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)>,
}
-#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
+#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, HashStable)]
pub struct PredefinedOpaques<'tcx>(pub(crate) Interned<'tcx, PredefinedOpaquesData<'tcx>>);
impl<'tcx> std::ops::Deref for PredefinedOpaques<'tcx> {
@@ -132,7 +134,7 @@ pub type CanonicalResponse<'tcx> = Canonical<'tcx, Response<'tcx>>;
/// solver, merge the two responses again.
pub type QueryResult<'tcx> = Result<CanonicalResponse<'tcx>, NoSolution>;
-#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
+#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, HashStable)]
pub struct ExternalConstraints<'tcx>(pub(crate) Interned<'tcx, ExternalConstraintsData<'tcx>>);
impl<'tcx> std::ops::Deref for ExternalConstraints<'tcx> {
@@ -144,7 +146,7 @@ impl<'tcx> std::ops::Deref for ExternalConstraints<'tcx> {
}
/// Additional constraints returned on success.
-#[derive(Debug, PartialEq, Eq, Clone, Hash, Default)]
+#[derive(Debug, PartialEq, Eq, Clone, Hash, HashStable, Default)]
pub struct ExternalConstraintsData<'tcx> {
// FIXME: implement this.
pub region_constraints: QueryRegionConstraints<'tcx>,
@@ -226,3 +228,9 @@ impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for PredefinedOpaques<'tcx> {
self.opaque_types.visit_with(visitor)
}
}
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, HashStable)]
+pub enum IsNormalizesToHack {
+ Yes,
+ No,
+}
diff --git a/compiler/rustc_middle/src/traits/solve/inspect.rs b/compiler/rustc_middle/src/traits/solve/inspect.rs
new file mode 100644
index 000000000..527afa005
--- /dev/null
+++ b/compiler/rustc_middle/src/traits/solve/inspect.rs
@@ -0,0 +1,83 @@
+use super::{
+ CanonicalInput, Certainty, Goal, IsNormalizesToHack, NoSolution, QueryInput, QueryResult,
+};
+use crate::ty;
+use format::ProofTreeFormatter;
+use std::fmt::{Debug, Write};
+
+mod format;
+
+#[derive(Eq, PartialEq, Debug, Hash, HashStable)]
+pub enum CacheHit {
+ Provisional,
+ Global,
+}
+
+#[derive(Eq, PartialEq, Hash, HashStable)]
+pub struct GoalEvaluation<'tcx> {
+ pub uncanonicalized_goal: Goal<'tcx, ty::Predicate<'tcx>>,
+ pub canonicalized_goal: CanonicalInput<'tcx>,
+
+ pub kind: GoalEvaluationKind<'tcx>,
+ pub is_normalizes_to_hack: IsNormalizesToHack,
+ pub returned_goals: Vec<Goal<'tcx, ty::Predicate<'tcx>>>,
+
+ pub result: QueryResult<'tcx>,
+}
+
+#[derive(Eq, PartialEq, Hash, HashStable)]
+pub enum GoalEvaluationKind<'tcx> {
+ CacheHit(CacheHit),
+ Uncached { revisions: Vec<GoalEvaluationStep<'tcx>> },
+}
+impl Debug for GoalEvaluation<'_> {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ ProofTreeFormatter { f, on_newline: true }.format_goal_evaluation(self)
+ }
+}
+
+#[derive(Eq, PartialEq, Hash, HashStable)]
+pub struct AddedGoalsEvaluation<'tcx> {
+ pub evaluations: Vec<Vec<GoalEvaluation<'tcx>>>,
+ pub result: Result<Certainty, NoSolution>,
+}
+impl Debug for AddedGoalsEvaluation<'_> {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ ProofTreeFormatter { f, on_newline: true }.format_nested_goal_evaluation(self)
+ }
+}
+
+#[derive(Eq, PartialEq, Hash, HashStable)]
+pub struct GoalEvaluationStep<'tcx> {
+ pub instantiated_goal: QueryInput<'tcx, ty::Predicate<'tcx>>,
+
+ pub nested_goal_evaluations: Vec<AddedGoalsEvaluation<'tcx>>,
+ pub candidates: Vec<GoalCandidate<'tcx>>,
+
+ pub result: QueryResult<'tcx>,
+}
+impl Debug for GoalEvaluationStep<'_> {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ ProofTreeFormatter { f, on_newline: true }.format_evaluation_step(self)
+ }
+}
+
+#[derive(Eq, PartialEq, Hash, HashStable)]
+pub struct GoalCandidate<'tcx> {
+ pub nested_goal_evaluations: Vec<AddedGoalsEvaluation<'tcx>>,
+ pub candidates: Vec<GoalCandidate<'tcx>>,
+ pub kind: CandidateKind<'tcx>,
+}
+
+#[derive(Eq, PartialEq, Debug, Hash, HashStable)]
+pub enum CandidateKind<'tcx> {
+ /// Probe entered when normalizing the self ty during candidate assembly
+ NormalizedSelfTyAssembly,
+ /// A normal candidate for proving a goal
+ Candidate { name: String, result: QueryResult<'tcx> },
+}
+impl Debug for GoalCandidate<'_> {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ ProofTreeFormatter { f, on_newline: true }.format_candidate(self)
+ }
+}
diff --git a/compiler/rustc_middle/src/traits/solve/inspect/format.rs b/compiler/rustc_middle/src/traits/solve/inspect/format.rs
new file mode 100644
index 000000000..2ee625674
--- /dev/null
+++ b/compiler/rustc_middle/src/traits/solve/inspect/format.rs
@@ -0,0 +1,131 @@
+use super::*;
+
+pub(super) struct ProofTreeFormatter<'a, 'b> {
+ pub(super) f: &'a mut (dyn Write + 'b),
+ pub(super) on_newline: bool,
+}
+
+impl Write for ProofTreeFormatter<'_, '_> {
+ fn write_str(&mut self, s: &str) -> std::fmt::Result {
+ for line in s.split_inclusive("\n") {
+ if self.on_newline {
+ self.f.write_str(" ")?;
+ }
+ self.on_newline = line.ends_with("\n");
+ self.f.write_str(line)?;
+ }
+
+ Ok(())
+ }
+}
+
+impl ProofTreeFormatter<'_, '_> {
+ fn nested(&mut self) -> ProofTreeFormatter<'_, '_> {
+ ProofTreeFormatter { f: self, on_newline: true }
+ }
+
+ pub(super) fn format_goal_evaluation(&mut self, goal: &GoalEvaluation<'_>) -> std::fmt::Result {
+ let f = &mut *self.f;
+
+ let goal_text = match goal.is_normalizes_to_hack {
+ IsNormalizesToHack::Yes => "NORMALIZES-TO HACK GOAL",
+ IsNormalizesToHack::No => "GOAL",
+ };
+
+ writeln!(f, "{}: {:?}", goal_text, goal.uncanonicalized_goal,)?;
+ writeln!(f, "CANONICALIZED: {:?}", goal.canonicalized_goal)?;
+
+ match &goal.kind {
+ GoalEvaluationKind::CacheHit(CacheHit::Global) => {
+ writeln!(f, "GLOBAL CACHE HIT: {:?}", goal.result)
+ }
+ GoalEvaluationKind::CacheHit(CacheHit::Provisional) => {
+ writeln!(f, "PROVISIONAL CACHE HIT: {:?}", goal.result)
+ }
+ GoalEvaluationKind::Uncached { revisions } => {
+ for (n, step) in revisions.iter().enumerate() {
+ let f = &mut *self.f;
+ writeln!(f, "REVISION {n}: {:?}", step.result)?;
+ let mut f = self.nested();
+ f.format_evaluation_step(step)?;
+ }
+
+ let f = &mut *self.f;
+ writeln!(f, "RESULT: {:?}", goal.result)
+ }
+ }?;
+
+ if goal.returned_goals.len() > 0 {
+ let f = &mut *self.f;
+ writeln!(f, "NESTED GOALS ADDED TO CALLER: [")?;
+ let mut f = self.nested();
+ for goal in goal.returned_goals.iter() {
+ writeln!(f, "ADDED GOAL: {:?},", goal)?;
+ }
+ writeln!(self.f, "]")?;
+ }
+
+ Ok(())
+ }
+
+ pub(super) fn format_evaluation_step(
+ &mut self,
+ evaluation_step: &GoalEvaluationStep<'_>,
+ ) -> std::fmt::Result {
+ let f = &mut *self.f;
+ writeln!(f, "INSTANTIATED: {:?}", evaluation_step.instantiated_goal)?;
+
+ for candidate in &evaluation_step.candidates {
+ let mut f = self.nested();
+ f.format_candidate(candidate)?;
+ }
+ for nested_goal_evaluation in &evaluation_step.nested_goal_evaluations {
+ let mut f = self.nested();
+ f.format_nested_goal_evaluation(nested_goal_evaluation)?;
+ }
+
+ Ok(())
+ }
+
+ pub(super) fn format_candidate(&mut self, candidate: &GoalCandidate<'_>) -> std::fmt::Result {
+ let f = &mut *self.f;
+
+ match &candidate.kind {
+ CandidateKind::NormalizedSelfTyAssembly => {
+ writeln!(f, "NORMALIZING SELF TY FOR ASSEMBLY:")
+ }
+ CandidateKind::Candidate { name, result } => {
+ writeln!(f, "CANDIDATE {}: {:?}", name, result)
+ }
+ }?;
+
+ let mut f = self.nested();
+ for candidate in &candidate.candidates {
+ f.format_candidate(candidate)?;
+ }
+ for nested_evaluations in &candidate.nested_goal_evaluations {
+ f.format_nested_goal_evaluation(nested_evaluations)?;
+ }
+
+ Ok(())
+ }
+
+ pub(super) fn format_nested_goal_evaluation(
+ &mut self,
+ nested_goal_evaluation: &AddedGoalsEvaluation<'_>,
+ ) -> std::fmt::Result {
+ let f = &mut *self.f;
+ writeln!(f, "TRY_EVALUATE_ADDED_GOALS: {:?}", nested_goal_evaluation.result)?;
+
+ for (n, revision) in nested_goal_evaluation.evaluations.iter().enumerate() {
+ let f = &mut *self.f;
+ writeln!(f, "REVISION {n}")?;
+ let mut f = self.nested();
+ for goal_evaluation in revision {
+ f.format_goal_evaluation(goal_evaluation)?;
+ }
+ }
+
+ Ok(())
+ }
+}
diff --git a/compiler/rustc_middle/src/traits/specialization_graph.rs b/compiler/rustc_middle/src/traits/specialization_graph.rs
index c016f7227..dc2cd2035 100644
--- a/compiler/rustc_middle/src/traits/specialization_graph.rs
+++ b/compiler/rustc_middle/src/traits/specialization_graph.rs
@@ -228,7 +228,7 @@ impl<'tcx> Ancestors<'tcx> {
if let Some(item) = node.item(tcx, trait_item_def_id) {
if finalizing_node.is_none() {
let is_specializable = item.defaultness(tcx).is_default()
- || tcx.impl_defaultness(node.def_id()).is_default();
+ || tcx.defaultness(node.def_id()).is_default();
if !is_specializable {
finalizing_node = Some(node);
diff --git a/compiler/rustc_middle/src/traits/structural_impls.rs b/compiler/rustc_middle/src/traits/structural_impls.rs
index 6acb7745d..a703e3c95 100644
--- a/compiler/rustc_middle/src/traits/structural_impls.rs
+++ b/compiler/rustc_middle/src/traits/structural_impls.rs
@@ -9,15 +9,7 @@ impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSource<'tcx, N> {
match *self {
super::ImplSource::UserDefined(ref v) => write!(f, "{:?}", v),
- super::ImplSource::AutoImpl(ref t) => write!(f, "{:?}", t),
-
- super::ImplSource::Closure(ref d) => write!(f, "{:?}", d),
-
- super::ImplSource::Generator(ref d) => write!(f, "{:?}", d),
-
- super::ImplSource::Future(ref d) => write!(f, "{:?}", d),
-
- super::ImplSource::FnPointer(ref d) => write!(f, "({:?})", d),
+ super::ImplSource::Builtin(ref d) => write!(f, "{:?}", d),
super::ImplSource::Object(ref d) => write!(f, "{:?}", d),
@@ -25,13 +17,7 @@ impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSource<'tcx, N> {
write!(f, "ImplSourceParamData({:?}, {:?})", n, ct)
}
- super::ImplSource::Builtin(ref d) => write!(f, "{:?}", d),
-
- super::ImplSource::TraitAlias(ref d) => write!(f, "{:?}", d),
-
super::ImplSource::TraitUpcasting(ref d) => write!(f, "{:?}", d),
-
- super::ImplSource::ConstDestruct(ref d) => write!(f, "{:?}", d),
}
}
}
@@ -46,90 +32,22 @@ impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceUserDefinedData<'tcx,
}
}
-impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceGeneratorData<'tcx, N> {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(
- f,
- "ImplSourceGeneratorData(generator_def_id={:?}, substs={:?}, nested={:?})",
- self.generator_def_id, self.substs, self.nested
- )
- }
-}
-
-impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceFutureData<'tcx, N> {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(
- f,
- "ImplSourceFutureData(generator_def_id={:?}, substs={:?}, nested={:?})",
- self.generator_def_id, self.substs, self.nested
- )
- }
-}
-
-impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceClosureData<'tcx, N> {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(
- f,
- "ImplSourceClosureData(closure_def_id={:?}, substs={:?}, nested={:?})",
- self.closure_def_id, self.substs, self.nested
- )
- }
-}
-
-impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceBuiltinData<N> {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "ImplSourceBuiltinData(nested={:?})", self.nested)
- }
-}
-
-impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceTraitUpcastingData<'tcx, N> {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(
- f,
- "ImplSourceTraitUpcastingData(upcast={:?}, vtable_vptr_slot={:?}, nested={:?})",
- self.upcast_trait_ref, self.vtable_vptr_slot, self.nested
- )
- }
-}
-
-impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceAutoImplData<N> {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(
- f,
- "ImplSourceAutoImplData(trait_def_id={:?}, nested={:?})",
- self.trait_def_id, self.nested
- )
- }
-}
-
-impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceObjectData<'tcx, N> {
+impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceTraitUpcastingData<N> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
- "ImplSourceObjectData(upcast={:?}, vtable_base={}, nested={:?})",
- self.upcast_trait_ref, self.vtable_base, self.nested
+ "ImplSourceTraitUpcastingData(vtable_vptr_slot={:?}, nested={:?})",
+ self.vtable_vptr_slot, self.nested
)
}
}
-impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceFnPointerData<'tcx, N> {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "ImplSourceFnPointerData(fn_ty={:?}, nested={:?})", self.fn_ty, self.nested)
- }
-}
-
-impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceTraitAliasData<'tcx, N> {
+impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceObjectData<N> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
- "ImplSourceTraitAliasData(alias_def_id={:?}, substs={:?}, nested={:?})",
- self.alias_def_id, self.substs, self.nested
+ "ImplSourceObjectData(vtable_base={}, nested={:?})",
+ self.vtable_base, self.nested
)
}
}
-
-impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceConstDestructData<N> {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "ImplSourceConstDestructData(nested={:?})", self.nested)
- }
-}
diff --git a/compiler/rustc_middle/src/traits/util.rs b/compiler/rustc_middle/src/traits/util.rs
index d54b8c599..05c06efaf 100644
--- a/compiler/rustc_middle/src/traits/util.rs
+++ b/compiler/rustc_middle/src/traits/util.rs
@@ -25,9 +25,7 @@ impl<'tcx> Elaborator<'tcx> {
.super_predicates_of(trait_ref.def_id())
.predicates
.into_iter()
- .flat_map(|(pred, _)| {
- pred.subst_supertrait(self.tcx, &trait_ref).to_opt_poly_trait_pred()
- })
+ .flat_map(|(pred, _)| pred.subst_supertrait(self.tcx, &trait_ref).as_trait_clause())
.map(|t| t.map_bound(|pred| pred.trait_ref))
.filter(|supertrait_ref| self.visited.insert(*supertrait_ref));