Skip to content

Commit 19d9a59

Browse files
authored
Rollup merge of #77155 - lcnr:ImplSource, r=ecstatic-morse
remove enum name from ImplSource variants This is quite a lot cleaner in my opinion.
2 parents 578d8f2 + 1857184 commit 19d9a59

File tree

8 files changed

+104
-110
lines changed

8 files changed

+104
-110
lines changed

Diff for: compiler/rustc_middle/src/traits/mod.rs

+44-45
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ pub use self::select::{EvaluationCache, EvaluationResult, OverflowError, Selecti
2828

2929
pub type CanonicalChalkEnvironmentAndGoal<'tcx> = Canonical<'tcx, ChalkEnvironmentAndGoal<'tcx>>;
3030

31-
pub use self::ImplSource::*;
3231
pub use self::ObligationCauseCode::*;
3332

3433
pub use self::chalk::{ChalkEnvironmentAndGoal, RustInterner as ChalkRustInterner};
@@ -418,10 +417,10 @@ pub type SelectionResult<'tcx, T> = Result<Option<T>, SelectionError<'tcx>>;
418417
///
419418
/// // Case B: ImplSource must be provided by caller. This applies when
420419
/// // type is a type parameter.
421-
/// param.clone(); // ImplSourceParam
420+
/// param.clone(); // ImplSource::Param
422421
///
423422
/// // Case C: A mix of cases A and B.
424-
/// mixed.clone(); // ImplSource(Impl_1, [ImplSourceParam])
423+
/// mixed.clone(); // ImplSource(Impl_1, [ImplSource::Param])
425424
/// }
426425
/// ```
427426
///
@@ -431,72 +430,72 @@ pub type SelectionResult<'tcx, T> = Result<Option<T>, SelectionError<'tcx>>;
431430
#[derive(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, TypeFoldable, Lift)]
432431
pub enum ImplSource<'tcx, N> {
433432
/// ImplSource identifying a particular impl.
434-
ImplSourceUserDefined(ImplSourceUserDefinedData<'tcx, N>),
433+
UserDefined(ImplSourceUserDefinedData<'tcx, N>),
435434

436435
/// ImplSource for auto trait implementations.
437436
/// This carries the information and nested obligations with regards
438437
/// to an auto implementation for a trait `Trait`. The nested obligations
439438
/// ensure the trait implementation holds for all the constituent types.
440-
ImplSourceAutoImpl(ImplSourceAutoImplData<N>),
439+
AutoImpl(ImplSourceAutoImplData<N>),
441440

442441
/// Successful resolution to an obligation provided by the caller
443442
/// for some type parameter. The `Vec<N>` represents the
444443
/// obligations incurred from normalizing the where-clause (if
445444
/// any).
446-
ImplSourceParam(Vec<N>),
445+
Param(Vec<N>),
447446

448447
/// Virtual calls through an object.
449-
ImplSourceObject(ImplSourceObjectData<'tcx, N>),
448+
Object(ImplSourceObjectData<'tcx, N>),
450449

451450
/// Successful resolution for a builtin trait.
452-
ImplSourceBuiltin(ImplSourceBuiltinData<N>),
451+
Builtin(ImplSourceBuiltinData<N>),
453452

454453
/// ImplSource automatically generated for a closure. The `DefId` is the ID
455-
/// of the closure expression. This is a `ImplSourceUserDefined` in spirit, but the
454+
/// of the closure expression. This is a `ImplSource::UserDefined` in spirit, but the
456455
/// impl is generated by the compiler and does not appear in the source.
457-
ImplSourceClosure(ImplSourceClosureData<'tcx, N>),
456+
Closure(ImplSourceClosureData<'tcx, N>),
458457

459458
/// Same as above, but for a function pointer type with the given signature.
460-
ImplSourceFnPointer(ImplSourceFnPointerData<'tcx, N>),
459+
FnPointer(ImplSourceFnPointerData<'tcx, N>),
461460

462461
/// ImplSource for a builtin `DeterminantKind` trait implementation.
463-
ImplSourceDiscriminantKind(ImplSourceDiscriminantKindData),
462+
DiscriminantKind(ImplSourceDiscriminantKindData),
464463

465464
/// ImplSource automatically generated for a generator.
466-
ImplSourceGenerator(ImplSourceGeneratorData<'tcx, N>),
465+
Generator(ImplSourceGeneratorData<'tcx, N>),
467466

468467
/// ImplSource for a trait alias.
469-
ImplSourceTraitAlias(ImplSourceTraitAliasData<'tcx, N>),
468+
TraitAlias(ImplSourceTraitAliasData<'tcx, N>),
470469
}
471470

472471
impl<'tcx, N> ImplSource<'tcx, N> {
473472
pub fn nested_obligations(self) -> Vec<N> {
474473
match self {
475-
ImplSourceUserDefined(i) => i.nested,
476-
ImplSourceParam(n) => n,
477-
ImplSourceBuiltin(i) => i.nested,
478-
ImplSourceAutoImpl(d) => d.nested,
479-
ImplSourceClosure(c) => c.nested,
480-
ImplSourceGenerator(c) => c.nested,
481-
ImplSourceObject(d) => d.nested,
482-
ImplSourceFnPointer(d) => d.nested,
483-
ImplSourceDiscriminantKind(ImplSourceDiscriminantKindData) => Vec::new(),
484-
ImplSourceTraitAlias(d) => d.nested,
474+
ImplSource::UserDefined(i) => i.nested,
475+
ImplSource::Param(n) => n,
476+
ImplSource::Builtin(i) => i.nested,
477+
ImplSource::AutoImpl(d) => d.nested,
478+
ImplSource::Closure(c) => c.nested,
479+
ImplSource::Generator(c) => c.nested,
480+
ImplSource::Object(d) => d.nested,
481+
ImplSource::FnPointer(d) => d.nested,
482+
ImplSource::DiscriminantKind(ImplSourceDiscriminantKindData) => Vec::new(),
483+
ImplSource::TraitAlias(d) => d.nested,
485484
}
486485
}
487486

488487
pub fn borrow_nested_obligations(&self) -> &[N] {
489488
match &self {
490-
ImplSourceUserDefined(i) => &i.nested[..],
491-
ImplSourceParam(n) => &n[..],
492-
ImplSourceBuiltin(i) => &i.nested[..],
493-
ImplSourceAutoImpl(d) => &d.nested[..],
494-
ImplSourceClosure(c) => &c.nested[..],
495-
ImplSourceGenerator(c) => &c.nested[..],
496-
ImplSourceObject(d) => &d.nested[..],
497-
ImplSourceFnPointer(d) => &d.nested[..],
498-
ImplSourceDiscriminantKind(ImplSourceDiscriminantKindData) => &[],
499-
ImplSourceTraitAlias(d) => &d.nested[..],
489+
ImplSource::UserDefined(i) => &i.nested[..],
490+
ImplSource::Param(n) => &n[..],
491+
ImplSource::Builtin(i) => &i.nested[..],
492+
ImplSource::AutoImpl(d) => &d.nested[..],
493+
ImplSource::Closure(c) => &c.nested[..],
494+
ImplSource::Generator(c) => &c.nested[..],
495+
ImplSource::Object(d) => &d.nested[..],
496+
ImplSource::FnPointer(d) => &d.nested[..],
497+
ImplSource::DiscriminantKind(ImplSourceDiscriminantKindData) => &[],
498+
ImplSource::TraitAlias(d) => &d.nested[..],
500499
}
501500
}
502501

@@ -505,42 +504,42 @@ impl<'tcx, N> ImplSource<'tcx, N> {
505504
F: FnMut(N) -> M,
506505
{
507506
match self {
508-
ImplSourceUserDefined(i) => ImplSourceUserDefined(ImplSourceUserDefinedData {
507+
ImplSource::UserDefined(i) => ImplSource::UserDefined(ImplSourceUserDefinedData {
509508
impl_def_id: i.impl_def_id,
510509
substs: i.substs,
511510
nested: i.nested.into_iter().map(f).collect(),
512511
}),
513-
ImplSourceParam(n) => ImplSourceParam(n.into_iter().map(f).collect()),
514-
ImplSourceBuiltin(i) => ImplSourceBuiltin(ImplSourceBuiltinData {
512+
ImplSource::Param(n) => ImplSource::Param(n.into_iter().map(f).collect()),
513+
ImplSource::Builtin(i) => ImplSource::Builtin(ImplSourceBuiltinData {
515514
nested: i.nested.into_iter().map(f).collect(),
516515
}),
517-
ImplSourceObject(o) => ImplSourceObject(ImplSourceObjectData {
516+
ImplSource::Object(o) => ImplSource::Object(ImplSourceObjectData {
518517
upcast_trait_ref: o.upcast_trait_ref,
519518
vtable_base: o.vtable_base,
520519
nested: o.nested.into_iter().map(f).collect(),
521520
}),
522-
ImplSourceAutoImpl(d) => ImplSourceAutoImpl(ImplSourceAutoImplData {
521+
ImplSource::AutoImpl(d) => ImplSource::AutoImpl(ImplSourceAutoImplData {
523522
trait_def_id: d.trait_def_id,
524523
nested: d.nested.into_iter().map(f).collect(),
525524
}),
526-
ImplSourceClosure(c) => ImplSourceClosure(ImplSourceClosureData {
525+
ImplSource::Closure(c) => ImplSource::Closure(ImplSourceClosureData {
527526
closure_def_id: c.closure_def_id,
528527
substs: c.substs,
529528
nested: c.nested.into_iter().map(f).collect(),
530529
}),
531-
ImplSourceGenerator(c) => ImplSourceGenerator(ImplSourceGeneratorData {
530+
ImplSource::Generator(c) => ImplSource::Generator(ImplSourceGeneratorData {
532531
generator_def_id: c.generator_def_id,
533532
substs: c.substs,
534533
nested: c.nested.into_iter().map(f).collect(),
535534
}),
536-
ImplSourceFnPointer(p) => ImplSourceFnPointer(ImplSourceFnPointerData {
535+
ImplSource::FnPointer(p) => ImplSource::FnPointer(ImplSourceFnPointerData {
537536
fn_ty: p.fn_ty,
538537
nested: p.nested.into_iter().map(f).collect(),
539538
}),
540-
ImplSourceDiscriminantKind(ImplSourceDiscriminantKindData) => {
541-
ImplSourceDiscriminantKind(ImplSourceDiscriminantKindData)
539+
ImplSource::DiscriminantKind(ImplSourceDiscriminantKindData) => {
540+
ImplSource::DiscriminantKind(ImplSourceDiscriminantKindData)
542541
}
543-
ImplSourceTraitAlias(d) => ImplSourceTraitAlias(ImplSourceTraitAliasData {
542+
ImplSource::TraitAlias(d) => ImplSource::TraitAlias(ImplSourceTraitAliasData {
544543
alias_def_id: d.alias_def_id,
545544
substs: d.substs,
546545
nested: d.nested.into_iter().map(f).collect(),

Diff for: compiler/rustc_middle/src/traits/structural_impls.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@ use std::fmt;
77
impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSource<'tcx, N> {
88
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
99
match *self {
10-
super::ImplSourceUserDefined(ref v) => write!(f, "{:?}", v),
10+
super::ImplSource::UserDefined(ref v) => write!(f, "{:?}", v),
1111

12-
super::ImplSourceAutoImpl(ref t) => write!(f, "{:?}", t),
12+
super::ImplSource::AutoImpl(ref t) => write!(f, "{:?}", t),
1313

14-
super::ImplSourceClosure(ref d) => write!(f, "{:?}", d),
14+
super::ImplSource::Closure(ref d) => write!(f, "{:?}", d),
1515

16-
super::ImplSourceGenerator(ref d) => write!(f, "{:?}", d),
16+
super::ImplSource::Generator(ref d) => write!(f, "{:?}", d),
1717

18-
super::ImplSourceFnPointer(ref d) => write!(f, "ImplSourceFnPointer({:?})", d),
18+
super::ImplSource::FnPointer(ref d) => write!(f, "({:?})", d),
1919

20-
super::ImplSourceDiscriminantKind(ref d) => write!(f, "{:?}", d),
20+
super::ImplSource::DiscriminantKind(ref d) => write!(f, "{:?}", d),
2121

22-
super::ImplSourceObject(ref d) => write!(f, "{:?}", d),
22+
super::ImplSource::Object(ref d) => write!(f, "{:?}", d),
2323

24-
super::ImplSourceParam(ref n) => write!(f, "ImplSourceParam({:?})", n),
24+
super::ImplSource::Param(ref n) => write!(f, "ImplSourceParamData({:?})", n),
2525

26-
super::ImplSourceBuiltin(ref d) => write!(f, "{:?}", d),
26+
super::ImplSource::Builtin(ref d) => write!(f, "{:?}", d),
2727

28-
super::ImplSourceTraitAlias(ref d) => write!(f, "{:?}", d),
28+
super::ImplSource::TraitAlias(ref d) => write!(f, "{:?}", d),
2929
}
3030
}
3131
}
@@ -96,7 +96,7 @@ impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceTraitAliasData<'tcx,
9696
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
9797
write!(
9898
f,
99-
"ImplSourceTraitAlias(alias_def_id={:?}, substs={:?}, nested={:?})",
99+
"ImplSourceTraitAliasData(alias_def_id={:?}, substs={:?}, nested={:?})",
100100
self.alias_def_id, self.substs, self.nested
101101
)
102102
}

Diff for: compiler/rustc_mir/src/monomorphize/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn custom_coerce_unsize_info<'tcx>(
2121
});
2222

2323
match tcx.codegen_fulfill_obligation((ty::ParamEnv::reveal_all(), trait_ref)) {
24-
Ok(traits::ImplSourceUserDefined(traits::ImplSourceUserDefinedData {
24+
Ok(traits::ImplSource::UserDefined(traits::ImplSourceUserDefinedData {
2525
impl_def_id,
2626
..
2727
})) => tcx.coerce_unsized_info(impl_def_id).custom_kind.unwrap(),

Diff for: compiler/rustc_trait_selection/src/traits/auto_trait.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
9696
));
9797

9898
match result {
99-
Ok(Some(ImplSource::ImplSourceUserDefined(_))) => {
99+
Ok(Some(ImplSource::UserDefined(_))) => {
100100
debug!(
101101
"find_auto_trait_generics({:?}): \
102102
manual impl found, bailing out",
@@ -315,9 +315,8 @@ impl AutoTraitFinder<'tcx> {
315315
// If we see an explicit negative impl (e.g., `impl !Send for MyStruct`),
316316
// we immediately bail out, since it's impossible for us to continue.
317317

318-
if let ImplSource::ImplSourceUserDefined(ImplSourceUserDefinedData {
319-
impl_def_id,
320-
..
318+
if let ImplSource::UserDefined(ImplSourceUserDefinedData {
319+
impl_def_id, ..
321320
}) = impl_source
322321
{
323322
// Blame 'tidy' for the weird bracket placement.

Diff for: compiler/rustc_trait_selection/src/traits/project.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -1000,15 +1000,15 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
10001000
};
10011001

10021002
let eligible = match &impl_source {
1003-
super::ImplSourceClosure(_)
1004-
| super::ImplSourceGenerator(_)
1005-
| super::ImplSourceFnPointer(_)
1006-
| super::ImplSourceObject(_)
1007-
| super::ImplSourceTraitAlias(_) => {
1003+
super::ImplSource::Closure(_)
1004+
| super::ImplSource::Generator(_)
1005+
| super::ImplSource::FnPointer(_)
1006+
| super::ImplSource::Object(_)
1007+
| super::ImplSource::TraitAlias(_) => {
10081008
debug!("assemble_candidates_from_impls: impl_source={:?}", impl_source);
10091009
true
10101010
}
1011-
super::ImplSourceUserDefined(impl_data) => {
1011+
super::ImplSource::UserDefined(impl_data) => {
10121012
// We have to be careful when projecting out of an
10131013
// impl because of specialization. If we are not in
10141014
// codegen (i.e., projection mode is not "any"), and the
@@ -1060,7 +1060,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
10601060
}
10611061
}
10621062
}
1063-
super::ImplSourceDiscriminantKind(..) => {
1063+
super::ImplSource::DiscriminantKind(..) => {
10641064
// While `DiscriminantKind` is automatically implemented for every type,
10651065
// the concrete discriminant may not be known yet.
10661066
//
@@ -1100,7 +1100,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
11001100
| ty::Error(_) => false,
11011101
}
11021102
}
1103-
super::ImplSourceParam(..) => {
1103+
super::ImplSource::Param(..) => {
11041104
// This case tell us nothing about the value of an
11051105
// associated type. Consider:
11061106
//
@@ -1128,7 +1128,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
11281128
// in `assemble_candidates_from_param_env`.
11291129
false
11301130
}
1131-
super::ImplSourceAutoImpl(..) | super::ImplSourceBuiltin(..) => {
1131+
super::ImplSource::AutoImpl(..) | super::ImplSource::Builtin(..) => {
11321132
// These traits have no associated types.
11331133
selcx.tcx().sess.delay_span_bug(
11341134
obligation.cause.span,
@@ -1186,20 +1186,20 @@ fn confirm_select_candidate<'cx, 'tcx>(
11861186
impl_source: Selection<'tcx>,
11871187
) -> Progress<'tcx> {
11881188
match impl_source {
1189-
super::ImplSourceUserDefined(data) => confirm_impl_candidate(selcx, obligation, data),
1190-
super::ImplSourceGenerator(data) => confirm_generator_candidate(selcx, obligation, data),
1191-
super::ImplSourceClosure(data) => confirm_closure_candidate(selcx, obligation, data),
1192-
super::ImplSourceFnPointer(data) => confirm_fn_pointer_candidate(selcx, obligation, data),
1193-
super::ImplSourceDiscriminantKind(data) => {
1189+
super::ImplSource::UserDefined(data) => confirm_impl_candidate(selcx, obligation, data),
1190+
super::ImplSource::Generator(data) => confirm_generator_candidate(selcx, obligation, data),
1191+
super::ImplSource::Closure(data) => confirm_closure_candidate(selcx, obligation, data),
1192+
super::ImplSource::FnPointer(data) => confirm_fn_pointer_candidate(selcx, obligation, data),
1193+
super::ImplSource::DiscriminantKind(data) => {
11941194
confirm_discriminant_kind_candidate(selcx, obligation, data)
11951195
}
1196-
super::ImplSourceObject(_) => {
1196+
super::ImplSource::Object(_) => {
11971197
confirm_object_candidate(selcx, obligation, obligation_trait_ref)
11981198
}
1199-
super::ImplSourceAutoImpl(..)
1200-
| super::ImplSourceParam(..)
1201-
| super::ImplSourceBuiltin(..)
1202-
| super::ImplSourceTraitAlias(..) =>
1199+
super::ImplSource::AutoImpl(..)
1200+
| super::ImplSource::Param(..)
1201+
| super::ImplSource::Builtin(..)
1202+
| super::ImplSource::TraitAlias(..) =>
12031203
// we don't create Select candidates with this kind of resolution
12041204
{
12051205
span_bug!(

0 commit comments

Comments
 (0)