Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove enum name from ImplSource variants #77155

Merged
merged 1 commit into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 44 additions & 45 deletions compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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])
/// }
/// ```
///
Expand All @@ -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[..],
}
}

Expand All @@ -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(),
Expand Down
22 changes: 11 additions & 11 deletions compiler/rustc_middle/src/traits/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
Expand Down Expand Up @@ -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
)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/monomorphize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn custom_coerce_unsize_info<'tcx>(
});

match tcx.codegen_fulfill_obligation((ty::ParamEnv::reveal_all(), trait_ref)) {
Ok(traits::ImplSourceUserDefined(traits::ImplSourceUserDefinedData {
Ok(traits::ImplSource::UserDefined(traits::ImplSourceUserDefinedData {
impl_def_id,
..
})) => tcx.coerce_unsized_info(impl_def_id).custom_kind.unwrap(),
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_trait_selection/src/traits/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
));

match result {
Ok(Some(ImplSource::ImplSourceUserDefined(_))) => {
Ok(Some(ImplSource::UserDefined(_))) => {
debug!(
"find_auto_trait_generics({:?}): \
manual impl found, bailing out",
Expand Down Expand Up @@ -315,9 +315,8 @@ impl AutoTraitFinder<'tcx> {
// If we see an explicit negative impl (e.g., `impl !Send for MyStruct`),
// we immediately bail out, since it's impossible for us to continue.

if let ImplSource::ImplSourceUserDefined(ImplSourceUserDefinedData {
impl_def_id,
..
if let ImplSource::UserDefined(ImplSourceUserDefinedData {
impl_def_id, ..
}) = impl_source
{
// Blame 'tidy' for the weird bracket placement.
Expand Down
38 changes: 19 additions & 19 deletions compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,15 +1000,15 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
};

let eligible = match &impl_source {
super::ImplSourceClosure(_)
| super::ImplSourceGenerator(_)
| super::ImplSourceFnPointer(_)
| super::ImplSourceObject(_)
| super::ImplSourceTraitAlias(_) => {
super::ImplSource::Closure(_)
| super::ImplSource::Generator(_)
| super::ImplSource::FnPointer(_)
| super::ImplSource::Object(_)
| super::ImplSource::TraitAlias(_) => {
debug!("assemble_candidates_from_impls: impl_source={:?}", impl_source);
true
}
super::ImplSourceUserDefined(impl_data) => {
super::ImplSource::UserDefined(impl_data) => {
// We have to be careful when projecting out of an
// impl because of specialization. If we are not in
// codegen (i.e., projection mode is not "any"), and the
Expand Down Expand Up @@ -1060,7 +1060,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
}
}
}
super::ImplSourceDiscriminantKind(..) => {
super::ImplSource::DiscriminantKind(..) => {
// While `DiscriminantKind` is automatically implemented for every type,
// the concrete discriminant may not be known yet.
//
Expand Down Expand Up @@ -1100,7 +1100,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
| ty::Error(_) => false,
}
}
super::ImplSourceParam(..) => {
super::ImplSource::Param(..) => {
// This case tell us nothing about the value of an
// associated type. Consider:
//
Expand Down Expand Up @@ -1128,7 +1128,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
// in `assemble_candidates_from_param_env`.
false
}
super::ImplSourceAutoImpl(..) | super::ImplSourceBuiltin(..) => {
super::ImplSource::AutoImpl(..) | super::ImplSource::Builtin(..) => {
// These traits have no associated types.
selcx.tcx().sess.delay_span_bug(
obligation.cause.span,
Expand Down Expand Up @@ -1186,20 +1186,20 @@ fn confirm_select_candidate<'cx, 'tcx>(
impl_source: Selection<'tcx>,
) -> Progress<'tcx> {
match impl_source {
super::ImplSourceUserDefined(data) => confirm_impl_candidate(selcx, obligation, data),
super::ImplSourceGenerator(data) => confirm_generator_candidate(selcx, obligation, data),
super::ImplSourceClosure(data) => confirm_closure_candidate(selcx, obligation, data),
super::ImplSourceFnPointer(data) => confirm_fn_pointer_candidate(selcx, obligation, data),
super::ImplSourceDiscriminantKind(data) => {
super::ImplSource::UserDefined(data) => confirm_impl_candidate(selcx, obligation, data),
super::ImplSource::Generator(data) => confirm_generator_candidate(selcx, obligation, data),
super::ImplSource::Closure(data) => confirm_closure_candidate(selcx, obligation, data),
super::ImplSource::FnPointer(data) => confirm_fn_pointer_candidate(selcx, obligation, data),
super::ImplSource::DiscriminantKind(data) => {
confirm_discriminant_kind_candidate(selcx, obligation, data)
}
super::ImplSourceObject(_) => {
super::ImplSource::Object(_) => {
confirm_object_candidate(selcx, obligation, obligation_trait_ref)
}
super::ImplSourceAutoImpl(..)
| super::ImplSourceParam(..)
| super::ImplSourceBuiltin(..)
| super::ImplSourceTraitAlias(..) =>
super::ImplSource::AutoImpl(..)
| super::ImplSource::Param(..)
| super::ImplSource::Builtin(..)
| super::ImplSource::TraitAlias(..) =>
// we don't create Select candidates with this kind of resolution
{
span_bug!(
Expand Down
Loading