Skip to content

Commit f2c16e3

Browse files
committed
Rename IsFirstInputType to InSelfTy
1 parent 676611e commit f2c16e3

File tree

4 files changed

+17
-29
lines changed

4 files changed

+17
-29
lines changed

compiler/rustc_hir_analysis/src/coherence/orphan.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_middle::{bug, span_bug};
1212
use rustc_span::def_id::{DefId, LocalDefId};
1313
use rustc_span::{Ident, Span};
1414
use rustc_trait_selection::traits::{
15-
self, IsFirstInputType, OrphanCheckErr, OrphanCheckMode, UncoveredTyParams,
15+
self, InSelfTy, OrphanCheckErr, OrphanCheckMode, UncoveredTyParams,
1616
};
1717
use tracing::{debug, instrument};
1818

@@ -414,19 +414,16 @@ fn emit_orphan_check_error<'tcx>(
414414
_ => errors::OnlyCurrentTraits::Arbitrary { span, note: () },
415415
});
416416

417-
for &(mut ty, is_target_ty) in &tys {
418-
let span = if matches!(is_target_ty, IsFirstInputType::Yes) {
419-
// Point at `D<A>` in `impl<A, B> for C<B> in D<A>`
420-
impl_.self_ty.span
421-
} else {
422-
// Point at `C<B>` in `impl<A, B> for C<B> in D<A>`
423-
hir_trait_ref.path.span
417+
for &(mut ty, in_self_ty) in &tys {
418+
// Given `impl<A, B> C<B> for D<A>`,
419+
let span = match in_self_ty {
420+
InSelfTy::Yes => impl_.self_ty.span, // point at `D<A>`.
421+
InSelfTy::No => hir_trait_ref.path.span, // point at `C<B>`.
424422
};
425423

426424
ty = tcx.erase_regions(ty);
427425

428-
let is_foreign =
429-
!trait_ref.def_id.is_local() && matches!(is_target_ty, IsFirstInputType::No);
426+
let is_foreign = !trait_ref.def_id.is_local() && matches!(in_self_ty, InSelfTy::No);
430427

431428
match *ty.kind() {
432429
ty::Slice(_) => {

compiler/rustc_next_trait_solver/src/coherence.rs

+8-17
Original file line numberDiff line numberDiff line change
@@ -96,26 +96,17 @@ pub fn trait_ref_is_local_or_fundamental<I: Interner>(tcx: I, trait_ref: ty::Tra
9696
trait_ref.def_id.is_local() || tcx.trait_is_fundamental(trait_ref.def_id)
9797
}
9898

99-
TrivialTypeTraversalImpls! { IsFirstInputType, }
99+
TrivialTypeTraversalImpls! { InSelfTy }
100100

101101
#[derive(Debug, Copy, Clone)]
102-
pub enum IsFirstInputType {
102+
pub enum InSelfTy {
103103
No,
104104
Yes,
105105
}
106106

107-
impl From<bool> for IsFirstInputType {
108-
fn from(b: bool) -> IsFirstInputType {
109-
match b {
110-
false => IsFirstInputType::No,
111-
true => IsFirstInputType::Yes,
112-
}
113-
}
114-
}
115-
116107
#[derive_where(Debug; I: Interner, T: Debug)]
117108
pub enum OrphanCheckErr<I: Interner, T> {
118-
NonLocalInputType(Vec<(I::Ty, IsFirstInputType)>),
109+
NonLocalInputType(Vec<(I::Ty, InSelfTy)>),
119110
UncoveredTyParams(UncoveredTyParams<I, T>),
120111
}
121112

@@ -258,11 +249,11 @@ where
258249
struct OrphanChecker<'a, Infcx, I: Interner, F> {
259250
infcx: &'a Infcx,
260251
in_crate: InCrate,
261-
in_self_ty: bool,
252+
in_self_ty: InSelfTy,
262253
lazily_normalize_ty: F,
263254
/// Ignore orphan check failures and exclusively search for the first local type.
264255
search_first_local_ty: bool,
265-
non_local_tys: Vec<(I::Ty, IsFirstInputType)>,
256+
non_local_tys: Vec<(I::Ty, InSelfTy)>,
266257
}
267258

268259
impl<'a, Infcx, I, F, E> OrphanChecker<'a, Infcx, I, F>
@@ -275,15 +266,15 @@ where
275266
OrphanChecker {
276267
infcx,
277268
in_crate,
278-
in_self_ty: true,
269+
in_self_ty: InSelfTy::Yes,
279270
lazily_normalize_ty,
280271
search_first_local_ty: false,
281272
non_local_tys: Vec::new(),
282273
}
283274
}
284275

285276
fn found_non_local_ty(&mut self, t: I::Ty) -> ControlFlow<OrphanCheckEarlyExit<I, E>> {
286-
self.non_local_tys.push((t, self.in_self_ty.into()));
277+
self.non_local_tys.push((t, self.in_self_ty));
287278
ControlFlow::Continue(())
288279
}
289280

@@ -449,7 +440,7 @@ where
449440
};
450441
// A bit of a hack, the `OrphanChecker` is only used to visit a `TraitRef`, so
451442
// the first type we visit is always the self type.
452-
self.in_self_ty = false;
443+
self.in_self_ty = InSelfTy::No;
453444
result
454445
}
455446

compiler/rustc_trait_selection/src/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use rustc_span::{DUMMY_SP, Span};
4141
use tracing::{debug, instrument};
4242

4343
pub use self::coherence::{
44-
InCrate, IsFirstInputType, OrphanCheckErr, OrphanCheckMode, OverlapResult, UncoveredTyParams,
44+
InCrate, InSelfTy, OrphanCheckErr, OrphanCheckMode, OverlapResult, UncoveredTyParams,
4545
add_placeholder_note, orphan_check_trait_ref, overlapping_impls,
4646
};
4747
pub use self::dyn_compatibility::{

compiler/rustc_type_ir/src/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/// allocated data** (i.e., don't need to be folded).
33
#[macro_export]
44
macro_rules! TrivialTypeTraversalImpls {
5-
($($ty:ty,)+) => {
5+
($($ty:ty),+ $(,)?) => {
66
$(
77
impl<I: $crate::Interner> $crate::TypeFoldable<I> for $ty {
88
fn try_fold_with<F: $crate::FallibleTypeFolder<I>>(

0 commit comments

Comments
 (0)