mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
Remove some ImplSource candidates
This commit is contained in:
parent
0cc541e4b2
commit
1704481bfa
@ -662,10 +662,10 @@ pub enum ImplSource<'tcx, N> {
|
||||
Object(ImplSourceObjectData<'tcx, N>),
|
||||
|
||||
/// Successful resolution for a builtin trait.
|
||||
Builtin(ImplSourceBuiltinData<N>),
|
||||
Builtin(Vec<N>),
|
||||
|
||||
/// ImplSource for trait upcasting coercion
|
||||
TraitUpcasting(ImplSourceTraitUpcastingData<'tcx, N>),
|
||||
TraitUpcasting(ImplSourceTraitUpcastingData<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
|
||||
@ -692,8 +692,7 @@ 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::Param(n, _) | ImplSource::Builtin(n) => n,
|
||||
ImplSource::AutoImpl(d) => d.nested,
|
||||
ImplSource::Closure(c) => c.nested,
|
||||
ImplSource::Generator(c) => c.nested,
|
||||
@ -709,8 +708,7 @@ impl<'tcx, N> ImplSource<'tcx, N> {
|
||||
pub fn borrow_nested_obligations(&self) -> &[N] {
|
||||
match self {
|
||||
ImplSource::UserDefined(i) => &i.nested,
|
||||
ImplSource::Param(n, _) => n,
|
||||
ImplSource::Builtin(i) => &i.nested,
|
||||
ImplSource::Param(n, _) | ImplSource::Builtin(n) => n,
|
||||
ImplSource::AutoImpl(d) => &d.nested,
|
||||
ImplSource::Closure(c) => &c.nested,
|
||||
ImplSource::Generator(c) => &c.nested,
|
||||
@ -726,8 +724,7 @@ impl<'tcx, N> ImplSource<'tcx, N> {
|
||||
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::Param(n, _) | ImplSource::Builtin(n) => n,
|
||||
ImplSource::AutoImpl(d) => &mut d.nested,
|
||||
ImplSource::Closure(c) => &mut c.nested,
|
||||
ImplSource::Generator(c) => &mut c.nested,
|
||||
@ -751,9 +748,7 @@ 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,
|
||||
@ -789,7 +784,6 @@ impl<'tcx, N> ImplSource<'tcx, N> {
|
||||
}),
|
||||
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(),
|
||||
})
|
||||
@ -860,10 +854,7 @@ pub struct ImplSourceAutoImplData<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
|
||||
@ -873,12 +864,6 @@ 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> {
|
||||
|
@ -76,18 +76,12 @@ impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceClosureData<'tcx, N>
|
||||
}
|
||||
}
|
||||
|
||||
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> {
|
||||
impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceTraitUpcastingData<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
|
||||
"ImplSourceTraitUpcastingData(vtable_vptr_slot={:?}, nested={:?})",
|
||||
self.vtable_vptr_slot, self.nested
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ use rustc_hir::lang_items::LangItem;
|
||||
use rustc_infer::infer::at::At;
|
||||
use rustc_infer::infer::resolve::OpportunisticRegionResolver;
|
||||
use rustc_infer::infer::DefineOpaqueTypes;
|
||||
use rustc_infer::traits::ImplSourceBuiltinData;
|
||||
use rustc_infer::traits::ObligationCauseCode;
|
||||
use rustc_middle::traits::select::OverflowError;
|
||||
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
|
||||
@ -2106,7 +2105,7 @@ fn confirm_future_candidate<'cx, 'tcx>(
|
||||
fn confirm_builtin_candidate<'cx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
data: ImplSourceBuiltinData<PredicateObligation<'tcx>>,
|
||||
data: Vec<PredicateObligation<'tcx>>,
|
||||
) -> Progress<'tcx> {
|
||||
let tcx = selcx.tcx();
|
||||
let self_ty = obligation.predicate.self_ty();
|
||||
@ -2154,7 +2153,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
|
||||
|
||||
confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
|
||||
.with_addl_obligations(obligations)
|
||||
.with_addl_obligations(data.nested)
|
||||
.with_addl_obligations(data)
|
||||
}
|
||||
|
||||
fn confirm_fn_pointer_candidate<'cx, 'tcx>(
|
||||
|
@ -27,12 +27,11 @@ use crate::traits::vtable::{
|
||||
};
|
||||
use crate::traits::{
|
||||
BuiltinDerivedObligation, ImplDerivedObligation, ImplDerivedObligationCause, ImplSource,
|
||||
ImplSourceAutoImplData, ImplSourceBuiltinData, ImplSourceClosureData,
|
||||
ImplSourceConstDestructData, ImplSourceFnPointerData, ImplSourceFutureData,
|
||||
ImplSourceGeneratorData, ImplSourceObjectData, ImplSourceTraitAliasData,
|
||||
ImplSourceTraitUpcastingData, ImplSourceUserDefinedData, Normalized, Obligation,
|
||||
ObligationCause, OutputTypeParameterMismatch, PredicateObligation, Selection, SelectionError,
|
||||
TraitNotObjectSafe, TraitObligation, Unimplemented,
|
||||
ImplSourceAutoImplData, ImplSourceClosureData, ImplSourceConstDestructData,
|
||||
ImplSourceFnPointerData, ImplSourceFutureData, ImplSourceGeneratorData, ImplSourceObjectData,
|
||||
ImplSourceTraitAliasData, ImplSourceTraitUpcastingData, ImplSourceUserDefinedData, Normalized,
|
||||
Obligation, ObligationCause, OutputTypeParameterMismatch, PredicateObligation, Selection,
|
||||
SelectionError, TraitNotObjectSafe, TraitObligation, Unimplemented,
|
||||
};
|
||||
|
||||
use super::BuiltinImplConditions;
|
||||
@ -114,7 +113,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
// This indicates something like `Trait + Send: Send`. In this case, we know that
|
||||
// this holds because that's what the object type is telling us, and there's really
|
||||
// no additional obligations to prove and no types in particular to unify, etc.
|
||||
ImplSource::Param(Vec::new(), ty::BoundConstness::NotConst)
|
||||
ImplSource::Builtin(Vec::new())
|
||||
}
|
||||
|
||||
BuiltinUnsizeCandidate => {
|
||||
@ -244,7 +243,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
&mut self,
|
||||
obligation: &TraitObligation<'tcx>,
|
||||
has_nested: bool,
|
||||
) -> ImplSourceBuiltinData<PredicateObligation<'tcx>> {
|
||||
) -> Vec<PredicateObligation<'tcx>> {
|
||||
debug!(?obligation, ?has_nested, "confirm_builtin_candidate");
|
||||
|
||||
let lang_items = self.tcx().lang_items();
|
||||
@ -277,14 +276,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
|
||||
debug!(?obligations);
|
||||
|
||||
ImplSourceBuiltinData { nested: obligations }
|
||||
obligations
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
fn confirm_transmutability_candidate(
|
||||
&mut self,
|
||||
obligation: &TraitObligation<'tcx>,
|
||||
) -> Result<ImplSourceBuiltinData<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
|
||||
) -> Result<Vec<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
|
||||
use rustc_transmute::{Answer, Condition};
|
||||
#[instrument(level = "debug", skip(tcx, obligation, predicate))]
|
||||
fn flatten_answer_tree<'tcx>(
|
||||
@ -369,7 +368,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
};
|
||||
|
||||
debug!(?fully_flattened);
|
||||
Ok(ImplSourceBuiltinData { nested: fully_flattened })
|
||||
Ok(fully_flattened)
|
||||
}
|
||||
|
||||
/// This handles the case where an `auto trait Foo` impl is being used.
|
||||
@ -912,8 +911,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
&mut self,
|
||||
obligation: &TraitObligation<'tcx>,
|
||||
idx: usize,
|
||||
) -> Result<ImplSourceTraitUpcastingData<'tcx, PredicateObligation<'tcx>>, SelectionError<'tcx>>
|
||||
{
|
||||
) -> Result<ImplSourceTraitUpcastingData<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
|
||||
let tcx = self.tcx();
|
||||
|
||||
// `assemble_candidates_for_unsizing` should ensure there are no late-bound
|
||||
@ -1010,13 +1008,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
let vtable_vptr_slot =
|
||||
prepare_vtable_segments(tcx, source_trait_ref, vtable_segment_callback).unwrap();
|
||||
|
||||
Ok(ImplSourceTraitUpcastingData { upcast_trait_ref, vtable_vptr_slot, nested })
|
||||
Ok(ImplSourceTraitUpcastingData { vtable_vptr_slot, nested })
|
||||
}
|
||||
|
||||
fn confirm_builtin_unsize_candidate(
|
||||
&mut self,
|
||||
obligation: &TraitObligation<'tcx>,
|
||||
) -> Result<ImplSourceBuiltinData<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
|
||||
) -> Result<Vec<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
|
||||
let tcx = self.tcx();
|
||||
|
||||
// `assemble_candidates_for_unsizing` should ensure there are no late-bound
|
||||
@ -1217,7 +1215,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
_ => bug!("source: {source}, target: {target}"),
|
||||
};
|
||||
|
||||
Ok(ImplSourceBuiltinData { nested })
|
||||
Ok(nested)
|
||||
}
|
||||
|
||||
fn confirm_const_destruct_candidate(
|
||||
|
Loading…
Reference in New Issue
Block a user