Remove some ImplSource candidates
This commit is contained in:
parent
0cc541e4b2
commit
1704481bfa
4 changed files with 26 additions and 50 deletions
|
@ -662,10 +662,10 @@ pub enum ImplSource<'tcx, N> {
|
||||||
Object(ImplSourceObjectData<'tcx, N>),
|
Object(ImplSourceObjectData<'tcx, N>),
|
||||||
|
|
||||||
/// Successful resolution for a builtin trait.
|
/// Successful resolution for a builtin trait.
|
||||||
Builtin(ImplSourceBuiltinData<N>),
|
Builtin(Vec<N>),
|
||||||
|
|
||||||
/// ImplSource for trait upcasting coercion
|
/// ImplSource for trait upcasting coercion
|
||||||
TraitUpcasting(ImplSourceTraitUpcastingData<'tcx, N>),
|
TraitUpcasting(ImplSourceTraitUpcastingData<N>),
|
||||||
|
|
||||||
/// ImplSource automatically generated for a closure. The `DefId` is the ID
|
/// ImplSource automatically generated for a closure. The `DefId` is the ID
|
||||||
/// of the closure expression. This is an `ImplSource::UserDefined` in spirit, but the
|
/// 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> {
|
pub fn nested_obligations(self) -> Vec<N> {
|
||||||
match self {
|
match self {
|
||||||
ImplSource::UserDefined(i) => i.nested,
|
ImplSource::UserDefined(i) => i.nested,
|
||||||
ImplSource::Param(n, _) => n,
|
ImplSource::Param(n, _) | ImplSource::Builtin(n) => n,
|
||||||
ImplSource::Builtin(i) => i.nested,
|
|
||||||
ImplSource::AutoImpl(d) => d.nested,
|
ImplSource::AutoImpl(d) => d.nested,
|
||||||
ImplSource::Closure(c) => c.nested,
|
ImplSource::Closure(c) => c.nested,
|
||||||
ImplSource::Generator(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] {
|
pub fn borrow_nested_obligations(&self) -> &[N] {
|
||||||
match self {
|
match self {
|
||||||
ImplSource::UserDefined(i) => &i.nested,
|
ImplSource::UserDefined(i) => &i.nested,
|
||||||
ImplSource::Param(n, _) => n,
|
ImplSource::Param(n, _) | ImplSource::Builtin(n) => n,
|
||||||
ImplSource::Builtin(i) => &i.nested,
|
|
||||||
ImplSource::AutoImpl(d) => &d.nested,
|
ImplSource::AutoImpl(d) => &d.nested,
|
||||||
ImplSource::Closure(c) => &c.nested,
|
ImplSource::Closure(c) => &c.nested,
|
||||||
ImplSource::Generator(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] {
|
pub fn borrow_nested_obligations_mut(&mut self) -> &mut [N] {
|
||||||
match self {
|
match self {
|
||||||
ImplSource::UserDefined(i) => &mut i.nested,
|
ImplSource::UserDefined(i) => &mut i.nested,
|
||||||
ImplSource::Param(n, _) => n,
|
ImplSource::Param(n, _) | ImplSource::Builtin(n) => n,
|
||||||
ImplSource::Builtin(i) => &mut i.nested,
|
|
||||||
ImplSource::AutoImpl(d) => &mut d.nested,
|
ImplSource::AutoImpl(d) => &mut d.nested,
|
||||||
ImplSource::Closure(c) => &mut c.nested,
|
ImplSource::Closure(c) => &mut c.nested,
|
||||||
ImplSource::Generator(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(),
|
nested: i.nested.into_iter().map(f).collect(),
|
||||||
}),
|
}),
|
||||||
ImplSource::Param(n, ct) => ImplSource::Param(n.into_iter().map(f).collect(), ct),
|
ImplSource::Param(n, ct) => ImplSource::Param(n.into_iter().map(f).collect(), ct),
|
||||||
ImplSource::Builtin(i) => ImplSource::Builtin(ImplSourceBuiltinData {
|
ImplSource::Builtin(n) => ImplSource::Builtin(n.into_iter().map(f).collect()),
|
||||||
nested: i.nested.into_iter().map(f).collect(),
|
|
||||||
}),
|
|
||||||
ImplSource::Object(o) => ImplSource::Object(ImplSourceObjectData {
|
ImplSource::Object(o) => ImplSource::Object(ImplSourceObjectData {
|
||||||
upcast_trait_ref: o.upcast_trait_ref,
|
upcast_trait_ref: o.upcast_trait_ref,
|
||||||
vtable_base: o.vtable_base,
|
vtable_base: o.vtable_base,
|
||||||
|
@ -789,7 +784,6 @@ impl<'tcx, N> ImplSource<'tcx, N> {
|
||||||
}),
|
}),
|
||||||
ImplSource::TraitUpcasting(d) => {
|
ImplSource::TraitUpcasting(d) => {
|
||||||
ImplSource::TraitUpcasting(ImplSourceTraitUpcastingData {
|
ImplSource::TraitUpcasting(ImplSourceTraitUpcastingData {
|
||||||
upcast_trait_ref: d.upcast_trait_ref,
|
|
||||||
vtable_vptr_slot: d.vtable_vptr_slot,
|
vtable_vptr_slot: d.vtable_vptr_slot,
|
||||||
nested: d.nested.into_iter().map(f).collect(),
|
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(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Lift)]
|
||||||
#[derive(TypeFoldable, TypeVisitable)]
|
#[derive(TypeFoldable, TypeVisitable)]
|
||||||
pub struct ImplSourceTraitUpcastingData<'tcx, N> {
|
pub struct ImplSourceTraitUpcastingData<N> {
|
||||||
/// `Foo` upcast to the obligation trait. This will be some supertrait of `Foo`.
|
|
||||||
pub upcast_trait_ref: ty::PolyTraitRef<'tcx>,
|
|
||||||
|
|
||||||
/// The vtable is formed by concatenating together the method lists of
|
/// The vtable is formed by concatenating together the method lists of
|
||||||
/// the base object trait and all supertraits, pointers to supertrait vtable will
|
/// 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
|
/// 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>,
|
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(PartialEq, Eq, Clone, TyEncodable, TyDecodable, HashStable, Lift)]
|
||||||
#[derive(TypeFoldable, TypeVisitable)]
|
#[derive(TypeFoldable, TypeVisitable)]
|
||||||
pub struct ImplSourceObjectData<'tcx, N> {
|
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> {
|
impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceTraitUpcastingData<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> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"ImplSourceTraitUpcastingData(upcast={:?}, vtable_vptr_slot={:?}, nested={:?})",
|
"ImplSourceTraitUpcastingData(vtable_vptr_slot={:?}, nested={:?})",
|
||||||
self.upcast_trait_ref, self.vtable_vptr_slot, self.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::at::At;
|
||||||
use rustc_infer::infer::resolve::OpportunisticRegionResolver;
|
use rustc_infer::infer::resolve::OpportunisticRegionResolver;
|
||||||
use rustc_infer::infer::DefineOpaqueTypes;
|
use rustc_infer::infer::DefineOpaqueTypes;
|
||||||
use rustc_infer::traits::ImplSourceBuiltinData;
|
|
||||||
use rustc_infer::traits::ObligationCauseCode;
|
use rustc_infer::traits::ObligationCauseCode;
|
||||||
use rustc_middle::traits::select::OverflowError;
|
use rustc_middle::traits::select::OverflowError;
|
||||||
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
|
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
|
||||||
|
@ -2106,7 +2105,7 @@ fn confirm_future_candidate<'cx, 'tcx>(
|
||||||
fn confirm_builtin_candidate<'cx, 'tcx>(
|
fn confirm_builtin_candidate<'cx, 'tcx>(
|
||||||
selcx: &mut SelectionContext<'cx, 'tcx>,
|
selcx: &mut SelectionContext<'cx, 'tcx>,
|
||||||
obligation: &ProjectionTyObligation<'tcx>,
|
obligation: &ProjectionTyObligation<'tcx>,
|
||||||
data: ImplSourceBuiltinData<PredicateObligation<'tcx>>,
|
data: Vec<PredicateObligation<'tcx>>,
|
||||||
) -> Progress<'tcx> {
|
) -> Progress<'tcx> {
|
||||||
let tcx = selcx.tcx();
|
let tcx = selcx.tcx();
|
||||||
let self_ty = obligation.predicate.self_ty();
|
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)
|
confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
|
||||||
.with_addl_obligations(obligations)
|
.with_addl_obligations(obligations)
|
||||||
.with_addl_obligations(data.nested)
|
.with_addl_obligations(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn confirm_fn_pointer_candidate<'cx, 'tcx>(
|
fn confirm_fn_pointer_candidate<'cx, 'tcx>(
|
||||||
|
|
|
@ -27,12 +27,11 @@ use crate::traits::vtable::{
|
||||||
};
|
};
|
||||||
use crate::traits::{
|
use crate::traits::{
|
||||||
BuiltinDerivedObligation, ImplDerivedObligation, ImplDerivedObligationCause, ImplSource,
|
BuiltinDerivedObligation, ImplDerivedObligation, ImplDerivedObligationCause, ImplSource,
|
||||||
ImplSourceAutoImplData, ImplSourceBuiltinData, ImplSourceClosureData,
|
ImplSourceAutoImplData, ImplSourceClosureData, ImplSourceConstDestructData,
|
||||||
ImplSourceConstDestructData, ImplSourceFnPointerData, ImplSourceFutureData,
|
ImplSourceFnPointerData, ImplSourceFutureData, ImplSourceGeneratorData, ImplSourceObjectData,
|
||||||
ImplSourceGeneratorData, ImplSourceObjectData, ImplSourceTraitAliasData,
|
ImplSourceTraitAliasData, ImplSourceTraitUpcastingData, ImplSourceUserDefinedData, Normalized,
|
||||||
ImplSourceTraitUpcastingData, ImplSourceUserDefinedData, Normalized, Obligation,
|
Obligation, ObligationCause, OutputTypeParameterMismatch, PredicateObligation, Selection,
|
||||||
ObligationCause, OutputTypeParameterMismatch, PredicateObligation, Selection, SelectionError,
|
SelectionError, TraitNotObjectSafe, TraitObligation, Unimplemented,
|
||||||
TraitNotObjectSafe, TraitObligation, Unimplemented,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::BuiltinImplConditions;
|
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 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
|
// 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.
|
// 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 => {
|
BuiltinUnsizeCandidate => {
|
||||||
|
@ -244,7 +243,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
&mut self,
|
&mut self,
|
||||||
obligation: &TraitObligation<'tcx>,
|
obligation: &TraitObligation<'tcx>,
|
||||||
has_nested: bool,
|
has_nested: bool,
|
||||||
) -> ImplSourceBuiltinData<PredicateObligation<'tcx>> {
|
) -> Vec<PredicateObligation<'tcx>> {
|
||||||
debug!(?obligation, ?has_nested, "confirm_builtin_candidate");
|
debug!(?obligation, ?has_nested, "confirm_builtin_candidate");
|
||||||
|
|
||||||
let lang_items = self.tcx().lang_items();
|
let lang_items = self.tcx().lang_items();
|
||||||
|
@ -277,14 +276,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
|
|
||||||
debug!(?obligations);
|
debug!(?obligations);
|
||||||
|
|
||||||
ImplSourceBuiltinData { nested: obligations }
|
obligations
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", skip(self))]
|
#[instrument(level = "debug", skip(self))]
|
||||||
fn confirm_transmutability_candidate(
|
fn confirm_transmutability_candidate(
|
||||||
&mut self,
|
&mut self,
|
||||||
obligation: &TraitObligation<'tcx>,
|
obligation: &TraitObligation<'tcx>,
|
||||||
) -> Result<ImplSourceBuiltinData<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
|
) -> Result<Vec<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
|
||||||
use rustc_transmute::{Answer, Condition};
|
use rustc_transmute::{Answer, Condition};
|
||||||
#[instrument(level = "debug", skip(tcx, obligation, predicate))]
|
#[instrument(level = "debug", skip(tcx, obligation, predicate))]
|
||||||
fn flatten_answer_tree<'tcx>(
|
fn flatten_answer_tree<'tcx>(
|
||||||
|
@ -369,7 +368,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
debug!(?fully_flattened);
|
debug!(?fully_flattened);
|
||||||
Ok(ImplSourceBuiltinData { nested: fully_flattened })
|
Ok(fully_flattened)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This handles the case where an `auto trait Foo` impl is being used.
|
/// 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,
|
&mut self,
|
||||||
obligation: &TraitObligation<'tcx>,
|
obligation: &TraitObligation<'tcx>,
|
||||||
idx: usize,
|
idx: usize,
|
||||||
) -> Result<ImplSourceTraitUpcastingData<'tcx, PredicateObligation<'tcx>>, SelectionError<'tcx>>
|
) -> Result<ImplSourceTraitUpcastingData<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
|
||||||
{
|
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
|
|
||||||
// `assemble_candidates_for_unsizing` should ensure there are no late-bound
|
// `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 =
|
let vtable_vptr_slot =
|
||||||
prepare_vtable_segments(tcx, source_trait_ref, vtable_segment_callback).unwrap();
|
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(
|
fn confirm_builtin_unsize_candidate(
|
||||||
&mut self,
|
&mut self,
|
||||||
obligation: &TraitObligation<'tcx>,
|
obligation: &TraitObligation<'tcx>,
|
||||||
) -> Result<ImplSourceBuiltinData<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
|
) -> Result<Vec<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
|
|
||||||
// `assemble_candidates_for_unsizing` should ensure there are no late-bound
|
// `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}"),
|
_ => bug!("source: {source}, target: {target}"),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(ImplSourceBuiltinData { nested })
|
Ok(nested)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn confirm_const_destruct_candidate(
|
fn confirm_const_destruct_candidate(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue