Skip to content

Commit 1704481

Browse files
Remove some ImplSource candidates
1 parent 0cc541e commit 1704481

File tree

4 files changed

+26
-50
lines changed

4 files changed

+26
-50
lines changed

compiler/rustc_middle/src/traits/mod.rs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -662,10 +662,10 @@ pub enum ImplSource<'tcx, N> {
662662
Object(ImplSourceObjectData<'tcx, N>),
663663

664664
/// Successful resolution for a builtin trait.
665-
Builtin(ImplSourceBuiltinData<N>),
665+
Builtin(Vec<N>),
666666

667667
/// ImplSource for trait upcasting coercion
668-
TraitUpcasting(ImplSourceTraitUpcastingData<'tcx, N>),
668+
TraitUpcasting(ImplSourceTraitUpcastingData<N>),
669669

670670
/// ImplSource automatically generated for a closure. The `DefId` is the ID
671671
/// of the closure expression. This is an `ImplSource::UserDefined` in spirit, but the
@@ -692,8 +692,7 @@ impl<'tcx, N> ImplSource<'tcx, N> {
692692
pub fn nested_obligations(self) -> Vec<N> {
693693
match self {
694694
ImplSource::UserDefined(i) => i.nested,
695-
ImplSource::Param(n, _) => n,
696-
ImplSource::Builtin(i) => i.nested,
695+
ImplSource::Param(n, _) | ImplSource::Builtin(n) => n,
697696
ImplSource::AutoImpl(d) => d.nested,
698697
ImplSource::Closure(c) => c.nested,
699698
ImplSource::Generator(c) => c.nested,
@@ -709,8 +708,7 @@ impl<'tcx, N> ImplSource<'tcx, N> {
709708
pub fn borrow_nested_obligations(&self) -> &[N] {
710709
match self {
711710
ImplSource::UserDefined(i) => &i.nested,
712-
ImplSource::Param(n, _) => n,
713-
ImplSource::Builtin(i) => &i.nested,
711+
ImplSource::Param(n, _) | ImplSource::Builtin(n) => n,
714712
ImplSource::AutoImpl(d) => &d.nested,
715713
ImplSource::Closure(c) => &c.nested,
716714
ImplSource::Generator(c) => &c.nested,
@@ -726,8 +724,7 @@ impl<'tcx, N> ImplSource<'tcx, N> {
726724
pub fn borrow_nested_obligations_mut(&mut self) -> &mut [N] {
727725
match self {
728726
ImplSource::UserDefined(i) => &mut i.nested,
729-
ImplSource::Param(n, _) => n,
730-
ImplSource::Builtin(i) => &mut i.nested,
727+
ImplSource::Param(n, _) | ImplSource::Builtin(n) => n,
731728
ImplSource::AutoImpl(d) => &mut d.nested,
732729
ImplSource::Closure(c) => &mut c.nested,
733730
ImplSource::Generator(c) => &mut c.nested,
@@ -751,9 +748,7 @@ impl<'tcx, N> ImplSource<'tcx, N> {
751748
nested: i.nested.into_iter().map(f).collect(),
752749
}),
753750
ImplSource::Param(n, ct) => ImplSource::Param(n.into_iter().map(f).collect(), ct),
754-
ImplSource::Builtin(i) => ImplSource::Builtin(ImplSourceBuiltinData {
755-
nested: i.nested.into_iter().map(f).collect(),
756-
}),
751+
ImplSource::Builtin(n) => ImplSource::Builtin(n.into_iter().map(f).collect()),
757752
ImplSource::Object(o) => ImplSource::Object(ImplSourceObjectData {
758753
upcast_trait_ref: o.upcast_trait_ref,
759754
vtable_base: o.vtable_base,
@@ -789,7 +784,6 @@ impl<'tcx, N> ImplSource<'tcx, N> {
789784
}),
790785
ImplSource::TraitUpcasting(d) => {
791786
ImplSource::TraitUpcasting(ImplSourceTraitUpcastingData {
792-
upcast_trait_ref: d.upcast_trait_ref,
793787
vtable_vptr_slot: d.vtable_vptr_slot,
794788
nested: d.nested.into_iter().map(f).collect(),
795789
})
@@ -860,10 +854,7 @@ pub struct ImplSourceAutoImplData<N> {
860854

861855
#[derive(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Lift)]
862856
#[derive(TypeFoldable, TypeVisitable)]
863-
pub struct ImplSourceTraitUpcastingData<'tcx, N> {
864-
/// `Foo` upcast to the obligation trait. This will be some supertrait of `Foo`.
865-
pub upcast_trait_ref: ty::PolyTraitRef<'tcx>,
866-
857+
pub struct ImplSourceTraitUpcastingData<N> {
867858
/// The vtable is formed by concatenating together the method lists of
868859
/// the base object trait and all supertraits, pointers to supertrait vtable will
869860
/// be provided when necessary; this is the position of `upcast_trait_ref`'s vtable
@@ -873,12 +864,6 @@ pub struct ImplSourceTraitUpcastingData<'tcx, N> {
873864
pub nested: Vec<N>,
874865
}
875866

876-
#[derive(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Lift)]
877-
#[derive(TypeFoldable, TypeVisitable)]
878-
pub struct ImplSourceBuiltinData<N> {
879-
pub nested: Vec<N>,
880-
}
881-
882867
#[derive(PartialEq, Eq, Clone, TyEncodable, TyDecodable, HashStable, Lift)]
883868
#[derive(TypeFoldable, TypeVisitable)]
884869
pub struct ImplSourceObjectData<'tcx, N> {

compiler/rustc_middle/src/traits/structural_impls.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,12 @@ impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceClosureData<'tcx, N>
7676
}
7777
}
7878

79-
impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceBuiltinData<N> {
80-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
81-
write!(f, "ImplSourceBuiltinData(nested={:?})", self.nested)
82-
}
83-
}
84-
85-
impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceTraitUpcastingData<'tcx, N> {
79+
impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceTraitUpcastingData<N> {
8680
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8781
write!(
8882
f,
89-
"ImplSourceTraitUpcastingData(upcast={:?}, vtable_vptr_slot={:?}, nested={:?})",
90-
self.upcast_trait_ref, self.vtable_vptr_slot, self.nested
83+
"ImplSourceTraitUpcastingData(vtable_vptr_slot={:?}, nested={:?})",
84+
self.vtable_vptr_slot, self.nested
9185
)
9286
}
9387
}

compiler/rustc_trait_selection/src/traits/project.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use rustc_hir::lang_items::LangItem;
3030
use rustc_infer::infer::at::At;
3131
use rustc_infer::infer::resolve::OpportunisticRegionResolver;
3232
use rustc_infer::infer::DefineOpaqueTypes;
33-
use rustc_infer::traits::ImplSourceBuiltinData;
3433
use rustc_infer::traits::ObligationCauseCode;
3534
use rustc_middle::traits::select::OverflowError;
3635
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
@@ -2106,7 +2105,7 @@ fn confirm_future_candidate<'cx, 'tcx>(
21062105
fn confirm_builtin_candidate<'cx, 'tcx>(
21072106
selcx: &mut SelectionContext<'cx, 'tcx>,
21082107
obligation: &ProjectionTyObligation<'tcx>,
2109-
data: ImplSourceBuiltinData<PredicateObligation<'tcx>>,
2108+
data: Vec<PredicateObligation<'tcx>>,
21102109
) -> Progress<'tcx> {
21112110
let tcx = selcx.tcx();
21122111
let self_ty = obligation.predicate.self_ty();
@@ -2154,7 +2153,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
21542153

21552154
confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
21562155
.with_addl_obligations(obligations)
2157-
.with_addl_obligations(data.nested)
2156+
.with_addl_obligations(data)
21582157
}
21592158

21602159
fn confirm_fn_pointer_candidate<'cx, 'tcx>(

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ use crate::traits::vtable::{
2727
};
2828
use crate::traits::{
2929
BuiltinDerivedObligation, ImplDerivedObligation, ImplDerivedObligationCause, ImplSource,
30-
ImplSourceAutoImplData, ImplSourceBuiltinData, ImplSourceClosureData,
31-
ImplSourceConstDestructData, ImplSourceFnPointerData, ImplSourceFutureData,
32-
ImplSourceGeneratorData, ImplSourceObjectData, ImplSourceTraitAliasData,
33-
ImplSourceTraitUpcastingData, ImplSourceUserDefinedData, Normalized, Obligation,
34-
ObligationCause, OutputTypeParameterMismatch, PredicateObligation, Selection, SelectionError,
35-
TraitNotObjectSafe, TraitObligation, Unimplemented,
30+
ImplSourceAutoImplData, ImplSourceClosureData, ImplSourceConstDestructData,
31+
ImplSourceFnPointerData, ImplSourceFutureData, ImplSourceGeneratorData, ImplSourceObjectData,
32+
ImplSourceTraitAliasData, ImplSourceTraitUpcastingData, ImplSourceUserDefinedData, Normalized,
33+
Obligation, ObligationCause, OutputTypeParameterMismatch, PredicateObligation, Selection,
34+
SelectionError, TraitNotObjectSafe, TraitObligation, Unimplemented,
3635
};
3736

3837
use super::BuiltinImplConditions;
@@ -114,7 +113,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
114113
// This indicates something like `Trait + Send: Send`. In this case, we know that
115114
// this holds because that's what the object type is telling us, and there's really
116115
// no additional obligations to prove and no types in particular to unify, etc.
117-
ImplSource::Param(Vec::new(), ty::BoundConstness::NotConst)
116+
ImplSource::Builtin(Vec::new())
118117
}
119118

120119
BuiltinUnsizeCandidate => {
@@ -244,7 +243,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
244243
&mut self,
245244
obligation: &TraitObligation<'tcx>,
246245
has_nested: bool,
247-
) -> ImplSourceBuiltinData<PredicateObligation<'tcx>> {
246+
) -> Vec<PredicateObligation<'tcx>> {
248247
debug!(?obligation, ?has_nested, "confirm_builtin_candidate");
249248

250249
let lang_items = self.tcx().lang_items();
@@ -277,14 +276,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
277276

278277
debug!(?obligations);
279278

280-
ImplSourceBuiltinData { nested: obligations }
279+
obligations
281280
}
282281

283282
#[instrument(level = "debug", skip(self))]
284283
fn confirm_transmutability_candidate(
285284
&mut self,
286285
obligation: &TraitObligation<'tcx>,
287-
) -> Result<ImplSourceBuiltinData<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
286+
) -> Result<Vec<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
288287
use rustc_transmute::{Answer, Condition};
289288
#[instrument(level = "debug", skip(tcx, obligation, predicate))]
290289
fn flatten_answer_tree<'tcx>(
@@ -369,7 +368,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
369368
};
370369

371370
debug!(?fully_flattened);
372-
Ok(ImplSourceBuiltinData { nested: fully_flattened })
371+
Ok(fully_flattened)
373372
}
374373

375374
/// This handles the case where an `auto trait Foo` impl is being used.
@@ -912,8 +911,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
912911
&mut self,
913912
obligation: &TraitObligation<'tcx>,
914913
idx: usize,
915-
) -> Result<ImplSourceTraitUpcastingData<'tcx, PredicateObligation<'tcx>>, SelectionError<'tcx>>
916-
{
914+
) -> Result<ImplSourceTraitUpcastingData<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
917915
let tcx = self.tcx();
918916

919917
// `assemble_candidates_for_unsizing` should ensure there are no late-bound
@@ -1010,13 +1008,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10101008
let vtable_vptr_slot =
10111009
prepare_vtable_segments(tcx, source_trait_ref, vtable_segment_callback).unwrap();
10121010

1013-
Ok(ImplSourceTraitUpcastingData { upcast_trait_ref, vtable_vptr_slot, nested })
1011+
Ok(ImplSourceTraitUpcastingData { vtable_vptr_slot, nested })
10141012
}
10151013

10161014
fn confirm_builtin_unsize_candidate(
10171015
&mut self,
10181016
obligation: &TraitObligation<'tcx>,
1019-
) -> Result<ImplSourceBuiltinData<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
1017+
) -> Result<Vec<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
10201018
let tcx = self.tcx();
10211019

10221020
// `assemble_candidates_for_unsizing` should ensure there are no late-bound
@@ -1217,7 +1215,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12171215
_ => bug!("source: {source}, target: {target}"),
12181216
};
12191217

1220-
Ok(ImplSourceBuiltinData { nested })
1218+
Ok(nested)
12211219
}
12221220

12231221
fn confirm_const_destruct_candidate(

0 commit comments

Comments
 (0)