Skip to content

Commit

Permalink
yeet ImplSource::TraitAlias too
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jun 20, 2023
1 parent db235a0 commit 42571c4
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 45 deletions.
19 changes: 0 additions & 19 deletions compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,9 +660,6 @@ pub enum ImplSource<'tcx, N> {

/// ImplSource for trait upcasting coercion
TraitUpcasting(ImplSourceTraitUpcastingData<N>),

/// ImplSource for a trait alias.
TraitAlias(ImplSourceTraitAliasData<'tcx, N>),
}

impl<'tcx, N> ImplSource<'tcx, N> {
Expand All @@ -671,7 +668,6 @@ impl<'tcx, N> ImplSource<'tcx, N> {
ImplSource::UserDefined(i) => i.nested,
ImplSource::Param(n, _) | ImplSource::Builtin(n) => n,
ImplSource::Object(d) => d.nested,
ImplSource::TraitAlias(d) => d.nested,
ImplSource::TraitUpcasting(d) => d.nested,
}
}
Expand All @@ -681,7 +677,6 @@ impl<'tcx, N> ImplSource<'tcx, N> {
ImplSource::UserDefined(i) => &i.nested,
ImplSource::Param(n, _) | ImplSource::Builtin(n) => &n,
ImplSource::Object(d) => &d.nested,
ImplSource::TraitAlias(d) => &d.nested,
ImplSource::TraitUpcasting(d) => &d.nested,
}
}
Expand All @@ -691,7 +686,6 @@ impl<'tcx, N> ImplSource<'tcx, N> {
ImplSource::UserDefined(i) => &mut i.nested,
ImplSource::Param(n, _) | ImplSource::Builtin(n) => n,
ImplSource::Object(d) => &mut d.nested,
ImplSource::TraitAlias(d) => &mut d.nested,
ImplSource::TraitUpcasting(d) => &mut d.nested,
}
}
Expand All @@ -713,11 +707,6 @@ impl<'tcx, N> ImplSource<'tcx, N> {
vtable_base: o.vtable_base,
nested: o.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 {
vtable_vptr_slot: d.vtable_vptr_slot,
Expand Down Expand Up @@ -773,14 +762,6 @@ pub struct ImplSourceObjectData<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.
Expand Down
12 changes: 0 additions & 12 deletions compiler/rustc_middle/src/traits/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSource<'tcx, N> {
write!(f, "ImplSourceParamData({:?}, {:?})", n, ct)
}

super::ImplSource::TraitAlias(ref d) => write!(f, "{:?}", d),

super::ImplSource::TraitUpcasting(ref d) => write!(f, "{:?}", d),
}
}
Expand Down Expand Up @@ -53,13 +51,3 @@ impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceObjectData<N> {
)
}
}

impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceTraitAliasData<'tcx, 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
)
}
}
4 changes: 1 addition & 3 deletions compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,6 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
};

let eligible = match &impl_source {
super::ImplSource::TraitAlias(_) => true,
super::ImplSource::UserDefined(impl_data) => {
// We have to be careful when projecting out of an
// impl because of specialization. If we are not in
Expand Down Expand Up @@ -2013,8 +2012,7 @@ fn confirm_select_candidate<'cx, 'tcx>(
}
super::ImplSource::Object(_)
| super::ImplSource::Param(..)
| super::ImplSource::TraitUpcasting(_)
| super::ImplSource::TraitAlias(..) => {
| super::ImplSource::TraitUpcasting(_) => {
// we don't create Select candidates with this kind of resolution
span_bug!(
obligation.cause.span,
Expand Down
14 changes: 6 additions & 8 deletions compiler/rustc_trait_selection/src/traits/select/confirmation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ use crate::traits::vtable::{
};
use crate::traits::{
BuiltinDerivedObligation, ImplDerivedObligation, ImplDerivedObligationCause, ImplSource,
ImplSourceObjectData, ImplSourceTraitAliasData, ImplSourceTraitUpcastingData,
ImplSourceUserDefinedData, Normalized, Obligation, ObligationCause,
OutputTypeParameterMismatch, PredicateObligation, Selection, SelectionError,
TraitNotObjectSafe, TraitObligation, Unimplemented,
ImplSourceObjectData, ImplSourceTraitUpcastingData, ImplSourceUserDefinedData, Normalized,
Obligation, ObligationCause, OutputTypeParameterMismatch, PredicateObligation, Selection,
SelectionError, TraitNotObjectSafe, TraitObligation, Unimplemented,
};

use super::BuiltinImplConditions;
Expand Down Expand Up @@ -105,7 +104,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {

TraitAliasCandidate => {
let data = self.confirm_trait_alias_candidate(obligation);
ImplSource::TraitAlias(data)
ImplSource::Builtin(data)
}

BuiltinObjectCandidate => {
Expand Down Expand Up @@ -721,10 +720,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
fn confirm_trait_alias_candidate(
&mut self,
obligation: &TraitObligation<'tcx>,
) -> ImplSourceTraitAliasData<'tcx, PredicateObligation<'tcx>> {
) -> Vec<PredicateObligation<'tcx>> {
debug!(?obligation, "confirm_trait_alias_candidate");

let alias_def_id = obligation.predicate.def_id();
let predicate = self.infcx.instantiate_binder_with_placeholders(obligation.predicate);
let trait_ref = predicate.trait_ref;
let trait_def_id = trait_ref.def_id;
Expand All @@ -741,7 +739,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {

debug!(?trait_def_id, ?trait_obligations, "trait alias obligations");

ImplSourceTraitAliasData { alias_def_id, substs, nested: trait_obligations }
trait_obligations
}

fn confirm_generator_candidate(
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_ty_utils/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,7 @@ fn resolve_associated_item<'tcx>(
None
}
}
traits::ImplSource::Param(..)
| traits::ImplSource::TraitAlias(..)
| traits::ImplSource::TraitUpcasting(_) => None,
traits::ImplSource::Param(..) | traits::ImplSource::TraitUpcasting(_) => None,
})
}

Expand Down

0 comments on commit 42571c4

Please sign in to comment.