Skip to content

Commit 9e68b6f

Browse files
Simplify some impl source candidates
1 parent 1704481 commit 9e68b6f

File tree

6 files changed

+18
-81
lines changed

6 files changed

+18
-81
lines changed

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl Qualif for NeedsNonConstDrop {
172172

173173
if !matches!(
174174
impl_src,
175-
ImplSource::ConstDestruct(_) | ImplSource::Param(_, ty::BoundConstness::ConstIfConst)
175+
ImplSource::Builtin(_) | ImplSource::Param(_, ty::BoundConstness::ConstIfConst)
176176
) {
177177
// If our const destruct candidate is not ConstDestruct or implied by the param env,
178178
// then it's bad

compiler/rustc_middle/src/traits/mod.rs

-37
Original file line numberDiff line numberDiff line change
@@ -646,12 +646,6 @@ pub enum ImplSource<'tcx, N> {
646646
/// ImplSource identifying a particular impl.
647647
UserDefined(ImplSourceUserDefinedData<'tcx, N>),
648648

649-
/// ImplSource for auto trait implementations.
650-
/// This carries the information and nested obligations with regards
651-
/// to an auto implementation for a trait `Trait`. The nested obligations
652-
/// ensure the trait implementation holds for all the constituent types.
653-
AutoImpl(ImplSourceAutoImplData<N>),
654-
655649
/// Successful resolution to an obligation provided by the caller
656650
/// for some type parameter. The `Vec<N>` represents the
657651
/// obligations incurred from normalizing the where-clause (if
@@ -683,57 +677,48 @@ pub enum ImplSource<'tcx, N> {
683677

684678
/// ImplSource for a trait alias.
685679
TraitAlias(ImplSourceTraitAliasData<'tcx, N>),
686-
687-
/// ImplSource for a `const Drop` implementation.
688-
ConstDestruct(ImplSourceConstDestructData<N>),
689680
}
690681

691682
impl<'tcx, N> ImplSource<'tcx, N> {
692683
pub fn nested_obligations(self) -> Vec<N> {
693684
match self {
694685
ImplSource::UserDefined(i) => i.nested,
695686
ImplSource::Param(n, _) | ImplSource::Builtin(n) => n,
696-
ImplSource::AutoImpl(d) => d.nested,
697687
ImplSource::Closure(c) => c.nested,
698688
ImplSource::Generator(c) => c.nested,
699689
ImplSource::Future(c) => c.nested,
700690
ImplSource::Object(d) => d.nested,
701691
ImplSource::FnPointer(d) => d.nested,
702692
ImplSource::TraitAlias(d) => d.nested,
703693
ImplSource::TraitUpcasting(d) => d.nested,
704-
ImplSource::ConstDestruct(i) => i.nested,
705694
}
706695
}
707696

708697
pub fn borrow_nested_obligations(&self) -> &[N] {
709698
match self {
710699
ImplSource::UserDefined(i) => &i.nested,
711700
ImplSource::Param(n, _) | ImplSource::Builtin(n) => n,
712-
ImplSource::AutoImpl(d) => &d.nested,
713701
ImplSource::Closure(c) => &c.nested,
714702
ImplSource::Generator(c) => &c.nested,
715703
ImplSource::Future(c) => &c.nested,
716704
ImplSource::Object(d) => &d.nested,
717705
ImplSource::FnPointer(d) => &d.nested,
718706
ImplSource::TraitAlias(d) => &d.nested,
719707
ImplSource::TraitUpcasting(d) => &d.nested,
720-
ImplSource::ConstDestruct(i) => &i.nested,
721708
}
722709
}
723710

724711
pub fn borrow_nested_obligations_mut(&mut self) -> &mut [N] {
725712
match self {
726713
ImplSource::UserDefined(i) => &mut i.nested,
727714
ImplSource::Param(n, _) | ImplSource::Builtin(n) => n,
728-
ImplSource::AutoImpl(d) => &mut d.nested,
729715
ImplSource::Closure(c) => &mut c.nested,
730716
ImplSource::Generator(c) => &mut c.nested,
731717
ImplSource::Future(c) => &mut c.nested,
732718
ImplSource::Object(d) => &mut d.nested,
733719
ImplSource::FnPointer(d) => &mut d.nested,
734720
ImplSource::TraitAlias(d) => &mut d.nested,
735721
ImplSource::TraitUpcasting(d) => &mut d.nested,
736-
ImplSource::ConstDestruct(i) => &mut i.nested,
737722
}
738723
}
739724

@@ -754,10 +739,6 @@ impl<'tcx, N> ImplSource<'tcx, N> {
754739
vtable_base: o.vtable_base,
755740
nested: o.nested.into_iter().map(f).collect(),
756741
}),
757-
ImplSource::AutoImpl(d) => ImplSource::AutoImpl(ImplSourceAutoImplData {
758-
trait_def_id: d.trait_def_id,
759-
nested: d.nested.into_iter().map(f).collect(),
760-
}),
761742
ImplSource::Closure(c) => ImplSource::Closure(ImplSourceClosureData {
762743
closure_def_id: c.closure_def_id,
763744
substs: c.substs,
@@ -788,11 +769,6 @@ impl<'tcx, N> ImplSource<'tcx, N> {
788769
nested: d.nested.into_iter().map(f).collect(),
789770
})
790771
}
791-
ImplSource::ConstDestruct(i) => {
792-
ImplSource::ConstDestruct(ImplSourceConstDestructData {
793-
nested: i.nested.into_iter().map(f).collect(),
794-
})
795-
}
796772
}
797773
}
798774
}
@@ -845,13 +821,6 @@ pub struct ImplSourceClosureData<'tcx, N> {
845821
pub nested: Vec<N>,
846822
}
847823

848-
#[derive(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Lift)]
849-
#[derive(TypeFoldable, TypeVisitable)]
850-
pub struct ImplSourceAutoImplData<N> {
851-
pub trait_def_id: DefId,
852-
pub nested: Vec<N>,
853-
}
854-
855824
#[derive(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Lift)]
856825
#[derive(TypeFoldable, TypeVisitable)]
857826
pub struct ImplSourceTraitUpcastingData<N> {
@@ -886,12 +855,6 @@ pub struct ImplSourceFnPointerData<'tcx, N> {
886855
pub nested: Vec<N>,
887856
}
888857

889-
#[derive(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Lift)]
890-
#[derive(TypeFoldable, TypeVisitable)]
891-
pub struct ImplSourceConstDestructData<N> {
892-
pub nested: Vec<N>,
893-
}
894-
895858
#[derive(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, Lift)]
896859
#[derive(TypeFoldable, TypeVisitable)]
897860
pub struct ImplSourceTraitAliasData<'tcx, N> {

compiler/rustc_middle/src/traits/structural_impls.rs

-20
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSource<'tcx, N> {
99
match *self {
1010
super::ImplSource::UserDefined(ref v) => write!(f, "{:?}", v),
1111

12-
super::ImplSource::AutoImpl(ref t) => write!(f, "{:?}", t),
13-
1412
super::ImplSource::Closure(ref d) => write!(f, "{:?}", d),
1513

1614
super::ImplSource::Generator(ref d) => write!(f, "{:?}", d),
@@ -30,8 +28,6 @@ impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSource<'tcx, N> {
3028
super::ImplSource::TraitAlias(ref d) => write!(f, "{:?}", d),
3129

3230
super::ImplSource::TraitUpcasting(ref d) => write!(f, "{:?}", d),
33-
34-
super::ImplSource::ConstDestruct(ref d) => write!(f, "{:?}", d),
3531
}
3632
}
3733
}
@@ -86,16 +82,6 @@ impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceTraitUpcastingData<N> {
8682
}
8783
}
8884

89-
impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceAutoImplData<N> {
90-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
91-
write!(
92-
f,
93-
"ImplSourceAutoImplData(trait_def_id={:?}, nested={:?})",
94-
self.trait_def_id, self.nested
95-
)
96-
}
97-
}
98-
9985
impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceObjectData<'tcx, N> {
10086
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10187
write!(
@@ -121,9 +107,3 @@ impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceTraitAliasData<'tcx,
121107
)
122108
}
123109
}
124-
125-
impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceConstDestructData<N> {
126-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
127-
write!(f, "ImplSourceConstDestructData(nested={:?})", self.nested)
128-
}
129-
}

compiler/rustc_trait_selection/src/traits/project.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1929,9 +1929,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
19291929
// why we special case object types.
19301930
false
19311931
}
1932-
super::ImplSource::AutoImpl(..)
1933-
| super::ImplSource::TraitUpcasting(_)
1934-
| super::ImplSource::ConstDestruct(_) => {
1932+
| super::ImplSource::TraitUpcasting(_) => {
19351933
// These traits have no associated types.
19361934
selcx.tcx().sess.delay_span_bug(
19371935
obligation.cause.span,
@@ -2001,11 +1999,9 @@ fn confirm_select_candidate<'cx, 'tcx>(
20011999
super::ImplSource::FnPointer(data) => confirm_fn_pointer_candidate(selcx, obligation, data),
20022000
super::ImplSource::Builtin(data) => confirm_builtin_candidate(selcx, obligation, data),
20032001
super::ImplSource::Object(_)
2004-
| super::ImplSource::AutoImpl(..)
20052002
| super::ImplSource::Param(..)
20062003
| super::ImplSource::TraitUpcasting(_)
2007-
| super::ImplSource::TraitAlias(..)
2008-
| super::ImplSource::ConstDestruct(_) => {
2004+
| super::ImplSource::TraitAlias(..) => {
20092005
// we don't create Select candidates with this kind of resolution
20102006
span_bug!(
20112007
obligation.cause.span,

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

+13-13
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ use crate::traits::vtable::{
2727
};
2828
use crate::traits::{
2929
BuiltinDerivedObligation, ImplDerivedObligation, ImplDerivedObligationCause, ImplSource,
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,
30+
ImplSourceClosureData, ImplSourceFnPointerData, ImplSourceFutureData, ImplSourceGeneratorData,
31+
ImplSourceObjectData, ImplSourceTraitAliasData, ImplSourceTraitUpcastingData,
32+
ImplSourceUserDefinedData, Normalized, Obligation, ObligationCause,
33+
OutputTypeParameterMismatch, PredicateObligation, Selection, SelectionError,
34+
TraitNotObjectSafe, TraitObligation, Unimplemented,
3535
};
3636

3737
use super::BuiltinImplConditions;
@@ -71,7 +71,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
7171

7272
AutoImplCandidate => {
7373
let data = self.confirm_auto_impl_candidate(obligation);
74-
ImplSource::AutoImpl(data)
74+
ImplSource::Builtin(data)
7575
}
7676

7777
ProjectionCandidate(idx, constness) => {
@@ -128,7 +128,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
128128

129129
ConstDestructCandidate(def_id) => {
130130
let data = self.confirm_const_destruct_candidate(obligation, def_id)?;
131-
ImplSource::ConstDestruct(data)
131+
ImplSource::Builtin(data)
132132
}
133133
};
134134

@@ -379,7 +379,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
379379
fn confirm_auto_impl_candidate(
380380
&mut self,
381381
obligation: &TraitObligation<'tcx>,
382-
) -> ImplSourceAutoImplData<PredicateObligation<'tcx>> {
382+
) -> Vec<PredicateObligation<'tcx>> {
383383
debug!(?obligation, "confirm_auto_impl_candidate");
384384

385385
let self_ty = self.infcx.shallow_resolve(obligation.predicate.self_ty());
@@ -393,7 +393,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
393393
obligation: &TraitObligation<'tcx>,
394394
trait_def_id: DefId,
395395
nested: ty::Binder<'tcx, Vec<Ty<'tcx>>>,
396-
) -> ImplSourceAutoImplData<PredicateObligation<'tcx>> {
396+
) -> Vec<PredicateObligation<'tcx>> {
397397
debug!(?nested, "vtable_auto_impl");
398398
ensure_sufficient_stack(|| {
399399
let cause = obligation.derived_cause(BuiltinDerivedObligation);
@@ -423,7 +423,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
423423

424424
debug!(?obligations, "vtable_auto_impl");
425425

426-
ImplSourceAutoImplData { trait_def_id, nested: obligations }
426+
obligations
427427
})
428428
}
429429

@@ -1222,10 +1222,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12221222
&mut self,
12231223
obligation: &TraitObligation<'tcx>,
12241224
impl_def_id: Option<DefId>,
1225-
) -> Result<ImplSourceConstDestructData<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
1225+
) -> Result<Vec<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
12261226
// `~const Destruct` in a non-const environment is always trivially true, since our type is `Drop`
12271227
if !obligation.is_const() {
1228-
return Ok(ImplSourceConstDestructData { nested: vec![] });
1228+
return Ok(vec![]);
12291229
}
12301230

12311231
let drop_trait = self.tcx().require_lang_item(LangItem::Drop, None);
@@ -1379,6 +1379,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13791379
}
13801380
}
13811381

1382-
Ok(ImplSourceConstDestructData { nested })
1382+
Ok(nested)
13831383
}
13841384
}

compiler/rustc_ty_utils/src/instance.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,9 @@ fn resolve_associated_item<'tcx>(
312312
None
313313
}
314314
}
315-
traits::ImplSource::AutoImpl(..)
316-
| traits::ImplSource::Param(..)
315+
traits::ImplSource::Param(..)
317316
| traits::ImplSource::TraitAlias(..)
318-
| traits::ImplSource::TraitUpcasting(_)
319-
| traits::ImplSource::ConstDestruct(_) => None,
317+
| traits::ImplSource::TraitUpcasting(_) => None,
320318
})
321319
}
322320

0 commit comments

Comments
 (0)