Skip to content

Commit

Permalink
Rename traits::ImplSourceImpl to ImplSourceUserDefined.
Browse files Browse the repository at this point in the history
  • Loading branch information
anyska committed Jun 5, 2020
1 parent e01896a commit 00c19ad
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 39 deletions.
14 changes: 7 additions & 7 deletions src/librustc_middle/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,11 @@ pub type SelectionResult<'tcx, T> = Result<Option<T>, SelectionError<'tcx>>;
///
/// ### The type parameter `N`
///
/// See explanation on `ImplSourceImplData`.
/// See explanation on `ImplSourceUserDefinedData`.
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable, TypeFoldable)]
pub enum ImplSource<'tcx, N> {
/// ImplSource identifying a particular impl.
ImplSourceImpl(ImplSourceImplData<'tcx, N>),
ImplSourceUserDefined(ImplSourceUserDefinedData<'tcx, N>),

/// ImplSource for auto trait implementations.
/// This carries the information and nested obligations with regards
Expand All @@ -399,7 +399,7 @@ pub enum ImplSource<'tcx, N> {
ImplSourceBuiltin(ImplSourceBuiltinData<N>),

/// ImplSource automatically generated for a closure. The `DefId` is the ID
/// of the closure expression. This is a `ImplSourceImpl` in spirit, but the
/// of the closure expression. This is a `ImplSourceUserDefined` in spirit, but the
/// impl is generated by the compiler and does not appear in the source.
ImplSourceClosure(ImplSourceClosureData<'tcx, N>),

Expand All @@ -419,7 +419,7 @@ pub enum ImplSource<'tcx, N> {
impl<'tcx, N> ImplSource<'tcx, N> {
pub fn nested_obligations(self) -> Vec<N> {
match self {
ImplSourceImpl(i) => i.nested,
ImplSourceUserDefined(i) => i.nested,
ImplSourceParam(n) => n,
ImplSourceBuiltin(i) => i.nested,
ImplSourceAutoImpl(d) => d.nested,
Expand All @@ -434,7 +434,7 @@ impl<'tcx, N> ImplSource<'tcx, N> {

pub fn borrow_nested_obligations(&self) -> &[N] {
match &self {
ImplSourceImpl(i) => &i.nested[..],
ImplSourceUserDefined(i) => &i.nested[..],
ImplSourceParam(n) => &n[..],
ImplSourceBuiltin(i) => &i.nested[..],
ImplSourceAutoImpl(d) => &d.nested[..],
Expand All @@ -452,7 +452,7 @@ impl<'tcx, N> ImplSource<'tcx, N> {
F: FnMut(N) -> M,
{
match self {
ImplSourceImpl(i) => ImplSourceImpl(ImplSourceImplData {
ImplSourceUserDefined(i) => ImplSourceUserDefined(ImplSourceUserDefinedData {
impl_def_id: i.impl_def_id,
substs: i.substs,
nested: i.nested.into_iter().map(f).collect(),
Expand Down Expand Up @@ -507,7 +507,7 @@ impl<'tcx, N> ImplSource<'tcx, N> {
/// is `()`, because codegen only requires a shallow resolution of an
/// impl, and nested obligations are satisfied later.
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable, TypeFoldable)]
pub struct ImplSourceImplData<'tcx, N> {
pub struct ImplSourceUserDefinedData<'tcx, N> {
pub impl_def_id: DefId,
pub substs: SubstsRef<'tcx>,
pub nested: Vec<N>,
Expand Down
24 changes: 13 additions & 11 deletions src/librustc_middle/traits/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::rc::Rc;
impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSource<'tcx, N> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
super::ImplSourceImpl(ref v) => write!(f, "{:?}", v),
super::ImplSourceUserDefined(ref v) => write!(f, "{:?}", v),

super::ImplSourceAutoImpl(ref t) => write!(f, "{:?}", t),

Expand All @@ -32,11 +32,11 @@ impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSource<'tcx, N> {
}
}

impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceImplData<'tcx, N> {
impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceUserDefinedData<'tcx, N> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"ImplSourceImplData(impl_def_id={:?}, substs={:?}, nested={:?})",
"ImplSourceUserDefinedData(impl_def_id={:?}, substs={:?}, nested={:?})",
self.impl_def_id, self.substs, self.nested
)
}
Expand Down Expand Up @@ -245,15 +245,17 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ImplSource<'a, ()> {
type Lifted = traits::ImplSource<'tcx, ()>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
match self.clone() {
traits::ImplSourceImpl(traits::ImplSourceImplData { impl_def_id, substs, nested }) => {
tcx.lift(&substs).map(|substs| {
traits::ImplSourceImpl(traits::ImplSourceImplData {
impl_def_id,
substs,
nested,
})
traits::ImplSourceUserDefined(traits::ImplSourceUserDefinedData {
impl_def_id,
substs,
nested,
}) => tcx.lift(&substs).map(|substs| {
traits::ImplSourceUserDefined(traits::ImplSourceUserDefinedData {
impl_def_id,
substs,
nested,
})
}
}),
traits::ImplSourceAutoImpl(t) => Some(traits::ImplSourceAutoImpl(t)),
traits::ImplSourceGenerator(traits::ImplSourceGeneratorData {
generator_def_id,
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_mir/monomorphize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ pub fn custom_coerce_unsize_info<'tcx>(
});

match tcx.codegen_fulfill_obligation((ty::ParamEnv::reveal_all(), trait_ref)) {
Ok(traits::ImplSourceImpl(traits::ImplSourceImplData { impl_def_id, .. })) => {
tcx.coerce_unsized_info(impl_def_id).custom_kind.unwrap()
}
Ok(traits::ImplSourceUserDefined(traits::ImplSourceUserDefinedData {
impl_def_id,
..
})) => tcx.coerce_unsized_info(impl_def_id).custom_kind.unwrap(),
impl_source => {
bug!("invalid `CoerceUnsized` impl_source: {:?}", impl_source);
}
Expand Down
8 changes: 5 additions & 3 deletions src/librustc_trait_selection/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::ImplSourceImpl(_))) => {
Ok(Some(ImplSource::ImplSourceUserDefined(_))) => {
debug!(
"find_auto_trait_generics({:?}): \
manual impl found, bailing out",
Expand Down Expand Up @@ -308,8 +308,10 @@ 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::ImplSourceImpl(ImplSourceImplData { impl_def_id, .. }) =
impl_source
if let ImplSource::ImplSourceUserDefined(ImplSourceUserDefinedData {
impl_def_id,
..
}) = impl_source
{
// Blame 'tidy' for the weird bracket placement.
if infcx.tcx.impl_polarity(*impl_def_id) == ty::ImplPolarity::Negative {
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_trait_selection/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::SelectionContext;
use super::SelectionError;
use super::{
ImplSourceClosureData, ImplSourceDiscriminantKindData, ImplSourceFnPointerData,
ImplSourceGeneratorData, ImplSourceImplData,
ImplSourceGeneratorData, ImplSourceUserDefinedData,
};
use super::{Normalized, NormalizedTy, ProjectionCacheEntry, ProjectionCacheKey};

Expand Down Expand Up @@ -996,7 +996,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
debug!("assemble_candidates_from_impls: impl_source={:?}", impl_source);
true
}
super::ImplSourceImpl(impl_data) => {
super::ImplSourceUserDefined(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 @@ -1165,7 +1165,7 @@ fn confirm_select_candidate<'cx, 'tcx>(
impl_source: Selection<'tcx>,
) -> Progress<'tcx> {
match impl_source {
super::ImplSourceImpl(data) => confirm_impl_candidate(selcx, obligation, data),
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),
Expand Down Expand Up @@ -1449,11 +1449,11 @@ fn confirm_param_env_candidate<'cx, 'tcx>(
fn confirm_impl_candidate<'cx, 'tcx>(
selcx: &mut SelectionContext<'cx, 'tcx>,
obligation: &ProjectionTyObligation<'tcx>,
impl_impl_source: ImplSourceImplData<'tcx, PredicateObligation<'tcx>>,
impl_impl_source: ImplSourceUserDefinedData<'tcx, PredicateObligation<'tcx>>,
) -> Progress<'tcx> {
let tcx = selcx.tcx();

let ImplSourceImplData { impl_def_id, substs, nested } = impl_impl_source;
let ImplSourceUserDefinedData { impl_def_id, substs, nested } = impl_impl_source;
let assoc_item_id = obligation.predicate.item_def_id;
let trait_def_id = tcx.trait_id_of_impl(impl_def_id).unwrap();

Expand Down
14 changes: 7 additions & 7 deletions src/librustc_trait_selection/traits/select/confirmation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ use crate::traits::TraitNotObjectSafe;
use crate::traits::{BuiltinDerivedObligation, ImplDerivedObligation};
use crate::traits::{
ImplSourceAutoImpl, ImplSourceBuiltin, ImplSourceClosure, ImplSourceDiscriminantKind,
ImplSourceFnPointer, ImplSourceGenerator, ImplSourceImpl, ImplSourceObject, ImplSourceParam,
ImplSourceTraitAlias,
ImplSourceFnPointer, ImplSourceGenerator, ImplSourceObject, ImplSourceParam,
ImplSourceTraitAlias, ImplSourceUserDefined,
};
use crate::traits::{
ImplSourceAutoImplData, ImplSourceBuiltinData, ImplSourceClosureData,
ImplSourceDiscriminantKindData, ImplSourceFnPointerData, ImplSourceGeneratorData,
ImplSourceImplData, ImplSourceObjectData, ImplSourceTraitAliasData,
ImplSourceObjectData, ImplSourceTraitAliasData, ImplSourceUserDefinedData,
};
use crate::traits::{ObjectCastObligation, PredicateObligation, TraitObligation};
use crate::traits::{Obligation, ObligationCause};
Expand Down Expand Up @@ -64,7 +64,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}

ImplCandidate(impl_def_id) => {
Ok(ImplSourceImpl(self.confirm_impl_candidate(obligation, impl_def_id)))
Ok(ImplSourceUserDefined(self.confirm_impl_candidate(obligation, impl_def_id)))
}

AutoImplCandidate(trait_def_id) => {
Expand Down Expand Up @@ -260,7 +260,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
&mut self,
obligation: &TraitObligation<'tcx>,
impl_def_id: DefId,
) -> ImplSourceImplData<'tcx, PredicateObligation<'tcx>> {
) -> ImplSourceUserDefinedData<'tcx, PredicateObligation<'tcx>> {
debug!("confirm_impl_candidate({:?},{:?})", obligation, impl_def_id);

// First, create the substitutions by matching the impl again,
Expand Down Expand Up @@ -288,7 +288,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
cause: ObligationCause<'tcx>,
recursion_depth: usize,
param_env: ty::ParamEnv<'tcx>,
) -> ImplSourceImplData<'tcx, PredicateObligation<'tcx>> {
) -> ImplSourceUserDefinedData<'tcx, PredicateObligation<'tcx>> {
debug!(
"vtable_impl(impl_def_id={:?}, substs={:?}, recursion_depth={})",
impl_def_id, substs, recursion_depth,
Expand All @@ -314,7 +314,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// e.g., `impl<U: Tr, V: Iterator<Item=U>> Foo<<U as Tr>::T> for V`
impl_obligations.append(&mut substs.obligations);

ImplSourceImplData { impl_def_id, substs: substs.value, nested: impl_obligations }
ImplSourceUserDefinedData { impl_def_id, substs: substs.value, nested: impl_obligations }
}

fn confirm_object_candidate(
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ fn resolve_associated_item<'tcx>(
// Now that we know which impl is being used, we can dispatch to
// the actual function:
Ok(match vtbl {
traits::ImplSourceImpl(impl_data) => {
traits::ImplSourceUserDefined(impl_data) => {
debug!(
"resolving ImplSourceImpl: {:?}, {:?}, {:?}, {:?}",
"resolving ImplSourceUserDefined: {:?}, {:?}, {:?}, {:?}",
param_env, trait_item, rcvr_substs, impl_data
);
assert!(!rcvr_substs.needs_infer());
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
.at(&ObligationCause::dummy(), self.param_env)
.sup(candidate.xform_self_ty, self_ty);
match self.select_trait_candidate(trait_ref) {
Ok(Some(traits::ImplSource::ImplSourceImpl(ref impl_data))) => {
Ok(Some(traits::ImplSource::ImplSourceUserDefined(ref impl_data))) => {
// If only a single impl matches, make the error message point
// to that impl.
ImplSource(impl_data.impl_def_id)
Expand Down

0 comments on commit 00c19ad

Please sign in to comment.