Rollup merge of #77155 - lcnr:ImplSource, r=ecstatic-morse
remove enum name from ImplSource variants This is quite a lot cleaner in my opinion.
This commit is contained in:
commit
e739468f97
8 changed files with 104 additions and 110 deletions
|
@ -28,7 +28,6 @@ pub use self::select::{EvaluationCache, EvaluationResult, OverflowError, Selecti
|
|||
|
||||
pub type CanonicalChalkEnvironmentAndGoal<'tcx> = Canonical<'tcx, ChalkEnvironmentAndGoal<'tcx>>;
|
||||
|
||||
pub use self::ImplSource::*;
|
||||
pub use self::ObligationCauseCode::*;
|
||||
|
||||
pub use self::chalk::{ChalkEnvironmentAndGoal, RustInterner as ChalkRustInterner};
|
||||
|
@ -418,10 +417,10 @@ pub type SelectionResult<'tcx, T> = Result<Option<T>, SelectionError<'tcx>>;
|
|||
///
|
||||
/// // Case B: ImplSource must be provided by caller. This applies when
|
||||
/// // type is a type parameter.
|
||||
/// param.clone(); // ImplSourceParam
|
||||
/// param.clone(); // ImplSource::Param
|
||||
///
|
||||
/// // Case C: A mix of cases A and B.
|
||||
/// mixed.clone(); // ImplSource(Impl_1, [ImplSourceParam])
|
||||
/// mixed.clone(); // ImplSource(Impl_1, [ImplSource::Param])
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
|
@ -431,72 +430,72 @@ pub type SelectionResult<'tcx, T> = Result<Option<T>, SelectionError<'tcx>>;
|
|||
#[derive(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, TypeFoldable, Lift)]
|
||||
pub enum ImplSource<'tcx, N> {
|
||||
/// ImplSource identifying a particular impl.
|
||||
ImplSourceUserDefined(ImplSourceUserDefinedData<'tcx, N>),
|
||||
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.
|
||||
ImplSourceAutoImpl(ImplSourceAutoImplData<N>),
|
||||
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
|
||||
/// any).
|
||||
ImplSourceParam(Vec<N>),
|
||||
Param(Vec<N>),
|
||||
|
||||
/// Virtual calls through an object.
|
||||
ImplSourceObject(ImplSourceObjectData<'tcx, N>),
|
||||
Object(ImplSourceObjectData<'tcx, N>),
|
||||
|
||||
/// Successful resolution for a builtin trait.
|
||||
ImplSourceBuiltin(ImplSourceBuiltinData<N>),
|
||||
Builtin(ImplSourceBuiltinData<N>),
|
||||
|
||||
/// ImplSource automatically generated for a closure. The `DefId` is the ID
|
||||
/// of the closure expression. This is a `ImplSourceUserDefined` in spirit, but the
|
||||
/// of the closure expression. This is a `ImplSource::UserDefined` in spirit, but the
|
||||
/// impl is generated by the compiler and does not appear in the source.
|
||||
ImplSourceClosure(ImplSourceClosureData<'tcx, N>),
|
||||
Closure(ImplSourceClosureData<'tcx, N>),
|
||||
|
||||
/// Same as above, but for a function pointer type with the given signature.
|
||||
ImplSourceFnPointer(ImplSourceFnPointerData<'tcx, N>),
|
||||
FnPointer(ImplSourceFnPointerData<'tcx, N>),
|
||||
|
||||
/// ImplSource for a builtin `DeterminantKind` trait implementation.
|
||||
ImplSourceDiscriminantKind(ImplSourceDiscriminantKindData),
|
||||
DiscriminantKind(ImplSourceDiscriminantKindData),
|
||||
|
||||
/// ImplSource automatically generated for a generator.
|
||||
ImplSourceGenerator(ImplSourceGeneratorData<'tcx, N>),
|
||||
Generator(ImplSourceGeneratorData<'tcx, N>),
|
||||
|
||||
/// ImplSource for a trait alias.
|
||||
ImplSourceTraitAlias(ImplSourceTraitAliasData<'tcx, N>),
|
||||
TraitAlias(ImplSourceTraitAliasData<'tcx, N>),
|
||||
}
|
||||
|
||||
impl<'tcx, N> ImplSource<'tcx, N> {
|
||||
pub fn nested_obligations(self) -> Vec<N> {
|
||||
match self {
|
||||
ImplSourceUserDefined(i) => i.nested,
|
||||
ImplSourceParam(n) => n,
|
||||
ImplSourceBuiltin(i) => i.nested,
|
||||
ImplSourceAutoImpl(d) => d.nested,
|
||||
ImplSourceClosure(c) => c.nested,
|
||||
ImplSourceGenerator(c) => c.nested,
|
||||
ImplSourceObject(d) => d.nested,
|
||||
ImplSourceFnPointer(d) => d.nested,
|
||||
ImplSourceDiscriminantKind(ImplSourceDiscriminantKindData) => Vec::new(),
|
||||
ImplSourceTraitAlias(d) => d.nested,
|
||||
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::Object(d) => d.nested,
|
||||
ImplSource::FnPointer(d) => d.nested,
|
||||
ImplSource::DiscriminantKind(ImplSourceDiscriminantKindData) => Vec::new(),
|
||||
ImplSource::TraitAlias(d) => d.nested,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn borrow_nested_obligations(&self) -> &[N] {
|
||||
match &self {
|
||||
ImplSourceUserDefined(i) => &i.nested[..],
|
||||
ImplSourceParam(n) => &n[..],
|
||||
ImplSourceBuiltin(i) => &i.nested[..],
|
||||
ImplSourceAutoImpl(d) => &d.nested[..],
|
||||
ImplSourceClosure(c) => &c.nested[..],
|
||||
ImplSourceGenerator(c) => &c.nested[..],
|
||||
ImplSourceObject(d) => &d.nested[..],
|
||||
ImplSourceFnPointer(d) => &d.nested[..],
|
||||
ImplSourceDiscriminantKind(ImplSourceDiscriminantKindData) => &[],
|
||||
ImplSourceTraitAlias(d) => &d.nested[..],
|
||||
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::Object(d) => &d.nested[..],
|
||||
ImplSource::FnPointer(d) => &d.nested[..],
|
||||
ImplSource::DiscriminantKind(ImplSourceDiscriminantKindData) => &[],
|
||||
ImplSource::TraitAlias(d) => &d.nested[..],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -505,42 +504,42 @@ impl<'tcx, N> ImplSource<'tcx, N> {
|
|||
F: FnMut(N) -> M,
|
||||
{
|
||||
match self {
|
||||
ImplSourceUserDefined(i) => ImplSourceUserDefined(ImplSourceUserDefinedData {
|
||||
ImplSource::UserDefined(i) => ImplSource::UserDefined(ImplSourceUserDefinedData {
|
||||
impl_def_id: i.impl_def_id,
|
||||
substs: i.substs,
|
||||
nested: i.nested.into_iter().map(f).collect(),
|
||||
}),
|
||||
ImplSourceParam(n) => ImplSourceParam(n.into_iter().map(f).collect()),
|
||||
ImplSourceBuiltin(i) => ImplSourceBuiltin(ImplSourceBuiltinData {
|
||||
ImplSource::Param(n) => ImplSource::Param(n.into_iter().map(f).collect()),
|
||||
ImplSource::Builtin(i) => ImplSource::Builtin(ImplSourceBuiltinData {
|
||||
nested: i.nested.into_iter().map(f).collect(),
|
||||
}),
|
||||
ImplSourceObject(o) => ImplSourceObject(ImplSourceObjectData {
|
||||
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(),
|
||||
}),
|
||||
ImplSourceAutoImpl(d) => ImplSourceAutoImpl(ImplSourceAutoImplData {
|
||||
ImplSource::AutoImpl(d) => ImplSource::AutoImpl(ImplSourceAutoImplData {
|
||||
trait_def_id: d.trait_def_id,
|
||||
nested: d.nested.into_iter().map(f).collect(),
|
||||
}),
|
||||
ImplSourceClosure(c) => ImplSourceClosure(ImplSourceClosureData {
|
||||
ImplSource::Closure(c) => ImplSource::Closure(ImplSourceClosureData {
|
||||
closure_def_id: c.closure_def_id,
|
||||
substs: c.substs,
|
||||
nested: c.nested.into_iter().map(f).collect(),
|
||||
}),
|
||||
ImplSourceGenerator(c) => ImplSourceGenerator(ImplSourceGeneratorData {
|
||||
ImplSource::Generator(c) => ImplSource::Generator(ImplSourceGeneratorData {
|
||||
generator_def_id: c.generator_def_id,
|
||||
substs: c.substs,
|
||||
nested: c.nested.into_iter().map(f).collect(),
|
||||
}),
|
||||
ImplSourceFnPointer(p) => ImplSourceFnPointer(ImplSourceFnPointerData {
|
||||
ImplSource::FnPointer(p) => ImplSource::FnPointer(ImplSourceFnPointerData {
|
||||
fn_ty: p.fn_ty,
|
||||
nested: p.nested.into_iter().map(f).collect(),
|
||||
}),
|
||||
ImplSourceDiscriminantKind(ImplSourceDiscriminantKindData) => {
|
||||
ImplSourceDiscriminantKind(ImplSourceDiscriminantKindData)
|
||||
ImplSource::DiscriminantKind(ImplSourceDiscriminantKindData) => {
|
||||
ImplSource::DiscriminantKind(ImplSourceDiscriminantKindData)
|
||||
}
|
||||
ImplSourceTraitAlias(d) => ImplSourceTraitAlias(ImplSourceTraitAliasData {
|
||||
ImplSource::TraitAlias(d) => ImplSource::TraitAlias(ImplSourceTraitAliasData {
|
||||
alias_def_id: d.alias_def_id,
|
||||
substs: d.substs,
|
||||
nested: d.nested.into_iter().map(f).collect(),
|
||||
|
|
|
@ -7,25 +7,25 @@ use std::fmt;
|
|||
impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSource<'tcx, N> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match *self {
|
||||
super::ImplSourceUserDefined(ref v) => write!(f, "{:?}", v),
|
||||
super::ImplSource::UserDefined(ref v) => write!(f, "{:?}", v),
|
||||
|
||||
super::ImplSourceAutoImpl(ref t) => write!(f, "{:?}", t),
|
||||
super::ImplSource::AutoImpl(ref t) => write!(f, "{:?}", t),
|
||||
|
||||
super::ImplSourceClosure(ref d) => write!(f, "{:?}", d),
|
||||
super::ImplSource::Closure(ref d) => write!(f, "{:?}", d),
|
||||
|
||||
super::ImplSourceGenerator(ref d) => write!(f, "{:?}", d),
|
||||
super::ImplSource::Generator(ref d) => write!(f, "{:?}", d),
|
||||
|
||||
super::ImplSourceFnPointer(ref d) => write!(f, "ImplSourceFnPointer({:?})", d),
|
||||
super::ImplSource::FnPointer(ref d) => write!(f, "({:?})", d),
|
||||
|
||||
super::ImplSourceDiscriminantKind(ref d) => write!(f, "{:?}", d),
|
||||
super::ImplSource::DiscriminantKind(ref d) => write!(f, "{:?}", d),
|
||||
|
||||
super::ImplSourceObject(ref d) => write!(f, "{:?}", d),
|
||||
super::ImplSource::Object(ref d) => write!(f, "{:?}", d),
|
||||
|
||||
super::ImplSourceParam(ref n) => write!(f, "ImplSourceParam({:?})", n),
|
||||
super::ImplSource::Param(ref n) => write!(f, "ImplSourceParamData({:?})", n),
|
||||
|
||||
super::ImplSourceBuiltin(ref d) => write!(f, "{:?}", d),
|
||||
super::ImplSource::Builtin(ref d) => write!(f, "{:?}", d),
|
||||
|
||||
super::ImplSourceTraitAlias(ref d) => write!(f, "{:?}", d),
|
||||
super::ImplSource::TraitAlias(ref d) => write!(f, "{:?}", d),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceTraitAliasData<'tcx,
|
|||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"ImplSourceTraitAlias(alias_def_id={:?}, substs={:?}, nested={:?})",
|
||||
"ImplSourceTraitAliasData(alias_def_id={:?}, substs={:?}, nested={:?})",
|
||||
self.alias_def_id, self.substs, self.nested
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue