Skip to content

Commit 9fa6bb2

Browse files
committed
Make atomic structural impls generic over Interner
1 parent 9783fcc commit 9fa6bb2

File tree

3 files changed

+82
-54
lines changed

3 files changed

+82
-54
lines changed

compiler/rustc_middle/src/macros.rs

+32-8
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,35 @@ macro_rules! TrivialTypeTraversalImpls {
100100
};
101101

102102
($($ty:ty,)+) => {
103-
TrivialTypeTraversalImpls! {
104-
for <'tcx> {
105-
$($ty,)+
103+
$(
104+
impl<I: $crate::ty::Interner> $crate::ty::fold::ir::TypeFoldable<I> for $ty {
105+
fn try_fold_with<F: $crate::ty::fold::ir::FallibleTypeFolder<I>>(
106+
self,
107+
_: &mut F,
108+
) -> ::std::result::Result<Self, F::Error> {
109+
Ok(self)
110+
}
111+
112+
#[inline]
113+
fn fold_with<F: $crate::ty::fold::ir::TypeFolder<I>>(
114+
self,
115+
_: &mut F,
116+
) -> Self {
117+
self
118+
}
106119
}
107-
}
120+
121+
impl<I: $crate::ty::Interner> $crate::ty::visit::ir::TypeVisitable<I> for $ty {
122+
#[inline]
123+
fn visit_with<F: $crate::ty::visit::ir::TypeVisitor<I>>(
124+
&self,
125+
_: &mut F)
126+
-> ::std::ops::ControlFlow<F::BreakTy>
127+
{
128+
::std::ops::ControlFlow::Continue(())
129+
}
130+
}
131+
)+
108132
};
109133
}
110134

@@ -121,10 +145,10 @@ macro_rules! EnumTypeTraversalImpl {
121145
(impl<$($p:tt),*> TypeFoldable<$tcx:tt> for $s:path {
122146
$($variants:tt)*
123147
} $(where $($wc:tt)*)*) => {
124-
impl<$($p),*> $crate::ty::fold::ir::TypeFoldable<$crate::ty::TyCtxt<$tcx>> for $s
148+
impl<$($p),*> $crate::ty::fold::ir::TypeFoldable<$tcx> for $s
125149
$(where $($wc)*)*
126150
{
127-
fn try_fold_with<V: $crate::ty::fold::FallibleTypeFolder<$tcx>>(
151+
fn try_fold_with<V: $crate::ty::fold::ir::FallibleTypeFolder<$tcx>>(
128152
self,
129153
folder: &mut V,
130154
) -> ::std::result::Result<Self, V::Error> {
@@ -136,10 +160,10 @@ macro_rules! EnumTypeTraversalImpl {
136160
(impl<$($p:tt),*> TypeVisitable<$tcx:tt> for $s:path {
137161
$($variants:tt)*
138162
} $(where $($wc:tt)*)*) => {
139-
impl<$($p),*> $crate::ty::visit::ir::TypeVisitable<$crate::ty::TyCtxt<$tcx>> for $s
163+
impl<$($p),*> $crate::ty::visit::ir::TypeVisitable<$tcx> for $s
140164
$(where $($wc)*)*
141165
{
142-
fn visit_with<V: $crate::ty::visit::TypeVisitor<$tcx>>(
166+
fn visit_with<V: $crate::ty::visit::ir::TypeVisitor<$tcx>>(
143167
&self,
144168
visitor: &mut V,
145169
) -> ::std::ops::ControlFlow<V::BreakTy> {

compiler/rustc_middle/src/mir/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,11 @@ pub enum BindingForm<'tcx> {
705705
RefForGuard,
706706
}
707707

708-
TrivialTypeTraversalAndLiftImpls! { BindingForm<'tcx>, }
708+
TrivialTypeTraversalAndLiftImpls! {
709+
for<'tcx> {
710+
BindingForm<'tcx>,
711+
}
712+
}
709713

710714
mod binding_form_impl {
711715
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};

compiler/rustc_middle/src/ty/structural_impls.rs

+45-45
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::mir::{Field, ProjectionKind};
77
use crate::ty::fold::{ir::TypeSuperFoldable, FallibleTypeFolder, TypeFoldable};
88
use crate::ty::print::{with_no_trimmed_paths, FmtPrinter, Printer};
99
use crate::ty::visit::{ir::TypeSuperVisitable, TypeVisitable, TypeVisitor};
10-
use crate::ty::{self, ir, AliasTy, InferConst, Lift, Term, TermKind, Ty, TyCtxt};
10+
use crate::ty::{self, ir, AliasTy, InferConst, Interner, Lift, Term, TermKind, Ty, TyCtxt};
1111
use rustc_data_structures::functor::IdFunctor;
1212
use rustc_hir::def::Namespace;
1313
use rustc_index::vec::{Idx, IndexVec};
@@ -375,28 +375,28 @@ impl<'tcx> ir::TypeVisitable<TyCtxt<'tcx>> for ty::AdtDef<'tcx> {
375375
}
376376
}
377377

378-
impl<'tcx, T: TypeFoldable<'tcx>, U: TypeFoldable<'tcx>> ir::TypeFoldable<TyCtxt<'tcx>> for (T, U) {
379-
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(
378+
impl<I: Interner, T: ir::TypeFoldable<I>, U: ir::TypeFoldable<I>> ir::TypeFoldable<I> for (T, U) {
379+
fn try_fold_with<F: ir::FallibleTypeFolder<I>>(
380380
self,
381381
folder: &mut F,
382382
) -> Result<(T, U), F::Error> {
383383
Ok((self.0.try_fold_with(folder)?, self.1.try_fold_with(folder)?))
384384
}
385385
}
386386

387-
impl<'tcx, T: TypeVisitable<'tcx>, U: TypeVisitable<'tcx>> ir::TypeVisitable<TyCtxt<'tcx>>
387+
impl<I: Interner, T: ir::TypeVisitable<I>, U: ir::TypeVisitable<I>> ir::TypeVisitable<I>
388388
for (T, U)
389389
{
390-
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
390+
fn visit_with<V: ir::TypeVisitor<I>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
391391
self.0.visit_with(visitor)?;
392392
self.1.visit_with(visitor)
393393
}
394394
}
395395

396-
impl<'tcx, A: TypeFoldable<'tcx>, B: TypeFoldable<'tcx>, C: TypeFoldable<'tcx>>
397-
ir::TypeFoldable<TyCtxt<'tcx>> for (A, B, C)
396+
impl<I: Interner, A: ir::TypeFoldable<I>, B: ir::TypeFoldable<I>, C: ir::TypeFoldable<I>>
397+
ir::TypeFoldable<I> for (A, B, C)
398398
{
399-
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(
399+
fn try_fold_with<F: ir::FallibleTypeFolder<I>>(
400400
self,
401401
folder: &mut F,
402402
) -> Result<(A, B, C), F::Error> {
@@ -408,44 +408,44 @@ impl<'tcx, A: TypeFoldable<'tcx>, B: TypeFoldable<'tcx>, C: TypeFoldable<'tcx>>
408408
}
409409
}
410410

411-
impl<'tcx, A: TypeVisitable<'tcx>, B: TypeVisitable<'tcx>, C: TypeVisitable<'tcx>>
412-
ir::TypeVisitable<TyCtxt<'tcx>> for (A, B, C)
411+
impl<I: Interner, A: ir::TypeVisitable<I>, B: ir::TypeVisitable<I>, C: ir::TypeVisitable<I>>
412+
ir::TypeVisitable<I> for (A, B, C)
413413
{
414-
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
414+
fn visit_with<V: ir::TypeVisitor<I>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
415415
self.0.visit_with(visitor)?;
416416
self.1.visit_with(visitor)?;
417417
self.2.visit_with(visitor)
418418
}
419419
}
420420

421421
EnumTypeTraversalImpl! {
422-
impl<'tcx, T> TypeFoldable<'tcx> for Option<T> {
422+
impl<I, T> TypeFoldable<I> for Option<T> {
423423
(Some)(a),
424424
(None),
425-
} where T: TypeFoldable<'tcx>
425+
} where I: Interner, T: ir::TypeFoldable<I>
426426
}
427427
EnumTypeTraversalImpl! {
428-
impl<'tcx, T> TypeVisitable<'tcx> for Option<T> {
428+
impl<I, T> TypeVisitable<I> for Option<T> {
429429
(Some)(a),
430430
(None),
431-
} where T: TypeVisitable<'tcx>
431+
} where I: Interner, T: ir::TypeVisitable<I>
432432
}
433433

434434
EnumTypeTraversalImpl! {
435-
impl<'tcx, T, E> TypeFoldable<'tcx> for Result<T, E> {
435+
impl<I, T, E> TypeFoldable<I> for Result<T, E> {
436436
(Ok)(a),
437437
(Err)(a),
438-
} where T: TypeFoldable<'tcx>, E: TypeFoldable<'tcx>,
438+
} where I: Interner, T: ir::TypeFoldable<I>, E: ir::TypeFoldable<I>,
439439
}
440440
EnumTypeTraversalImpl! {
441-
impl<'tcx, T, E> TypeVisitable<'tcx> for Result<T, E> {
441+
impl<I, T, E> TypeVisitable<I> for Result<T, E> {
442442
(Ok)(a),
443443
(Err)(a),
444-
} where T: TypeVisitable<'tcx>, E: TypeVisitable<'tcx>,
444+
} where I: Interner, T: ir::TypeVisitable<I>, E: ir::TypeVisitable<I>,
445445
}
446446

447-
impl<'tcx, T: TypeFoldable<'tcx>> ir::TypeFoldable<TyCtxt<'tcx>> for Rc<T> {
448-
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(
447+
impl<I: Interner, T: ir::TypeFoldable<I>> ir::TypeFoldable<I> for Rc<T> {
448+
fn try_fold_with<F: ir::FallibleTypeFolder<I>>(
449449
mut self,
450450
folder: &mut F,
451451
) -> Result<Self, F::Error> {
@@ -484,14 +484,14 @@ impl<'tcx, T: TypeFoldable<'tcx>> ir::TypeFoldable<TyCtxt<'tcx>> for Rc<T> {
484484
}
485485
}
486486

487-
impl<'tcx, T: TypeVisitable<'tcx>> ir::TypeVisitable<TyCtxt<'tcx>> for Rc<T> {
488-
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
487+
impl<I: Interner, T: ir::TypeVisitable<I>> ir::TypeVisitable<I> for Rc<T> {
488+
fn visit_with<V: ir::TypeVisitor<I>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
489489
(**self).visit_with(visitor)
490490
}
491491
}
492492

493-
impl<'tcx, T: TypeFoldable<'tcx>> ir::TypeFoldable<TyCtxt<'tcx>> for Arc<T> {
494-
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(
493+
impl<I: Interner, T: ir::TypeFoldable<I>> ir::TypeFoldable<I> for Arc<T> {
494+
fn try_fold_with<F: ir::FallibleTypeFolder<I>>(
495495
mut self,
496496
folder: &mut F,
497497
) -> Result<Self, F::Error> {
@@ -530,50 +530,50 @@ impl<'tcx, T: TypeFoldable<'tcx>> ir::TypeFoldable<TyCtxt<'tcx>> for Arc<T> {
530530
}
531531
}
532532

533-
impl<'tcx, T: TypeVisitable<'tcx>> ir::TypeVisitable<TyCtxt<'tcx>> for Arc<T> {
534-
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
533+
impl<I: Interner, T: ir::TypeVisitable<I>> ir::TypeVisitable<I> for Arc<T> {
534+
fn visit_with<V: ir::TypeVisitor<I>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
535535
(**self).visit_with(visitor)
536536
}
537537
}
538538

539-
impl<'tcx, T: TypeFoldable<'tcx>> ir::TypeFoldable<TyCtxt<'tcx>> for Box<T> {
540-
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
539+
impl<I: Interner, T: ir::TypeFoldable<I>> ir::TypeFoldable<I> for Box<T> {
540+
fn try_fold_with<F: ir::FallibleTypeFolder<I>>(self, folder: &mut F) -> Result<Self, F::Error> {
541541
self.try_map_id(|value| value.try_fold_with(folder))
542542
}
543543
}
544544

545-
impl<'tcx, T: TypeVisitable<'tcx>> ir::TypeVisitable<TyCtxt<'tcx>> for Box<T> {
546-
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
545+
impl<I: Interner, T: ir::TypeVisitable<I>> ir::TypeVisitable<I> for Box<T> {
546+
fn visit_with<V: ir::TypeVisitor<I>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
547547
(**self).visit_with(visitor)
548548
}
549549
}
550550

551-
impl<'tcx, T: TypeFoldable<'tcx>> ir::TypeFoldable<TyCtxt<'tcx>> for Vec<T> {
552-
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
551+
impl<I: Interner, T: ir::TypeFoldable<I>> ir::TypeFoldable<I> for Vec<T> {
552+
fn try_fold_with<F: ir::FallibleTypeFolder<I>>(self, folder: &mut F) -> Result<Self, F::Error> {
553553
self.try_map_id(|t| t.try_fold_with(folder))
554554
}
555555
}
556556

557-
impl<'tcx, T: TypeVisitable<'tcx>> ir::TypeVisitable<TyCtxt<'tcx>> for Vec<T> {
558-
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
557+
impl<I: Interner, T: ir::TypeVisitable<I>> ir::TypeVisitable<I> for Vec<T> {
558+
fn visit_with<V: ir::TypeVisitor<I>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
559559
self.iter().try_for_each(|t| t.visit_with(visitor))
560560
}
561561
}
562562

563-
impl<'tcx, T: TypeVisitable<'tcx>> ir::TypeVisitable<TyCtxt<'tcx>> for &[T] {
564-
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
563+
impl<I: Interner, T: ir::TypeVisitable<I>> ir::TypeVisitable<I> for &[T] {
564+
fn visit_with<V: ir::TypeVisitor<I>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
565565
self.iter().try_for_each(|t| t.visit_with(visitor))
566566
}
567567
}
568568

569-
impl<'tcx, T: TypeFoldable<'tcx>> ir::TypeFoldable<TyCtxt<'tcx>> for Box<[T]> {
570-
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
569+
impl<I: Interner, T: ir::TypeFoldable<I>> ir::TypeFoldable<I> for Box<[T]> {
570+
fn try_fold_with<F: ir::FallibleTypeFolder<I>>(self, folder: &mut F) -> Result<Self, F::Error> {
571571
self.try_map_id(|t| t.try_fold_with(folder))
572572
}
573573
}
574574

575-
impl<'tcx, T: TypeVisitable<'tcx>> ir::TypeVisitable<TyCtxt<'tcx>> for Box<[T]> {
576-
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
575+
impl<I: Interner, T: ir::TypeVisitable<I>> ir::TypeVisitable<I> for Box<[T]> {
576+
fn visit_with<V: ir::TypeVisitor<I>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
577577
self.iter().try_for_each(|t| t.visit_with(visitor))
578578
}
579579
}
@@ -790,14 +790,14 @@ impl<'tcx> ir::TypeFoldable<TyCtxt<'tcx>> for &'tcx ty::List<ty::Predicate<'tcx>
790790
}
791791
}
792792

793-
impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> ir::TypeFoldable<TyCtxt<'tcx>> for IndexVec<I, T> {
794-
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
793+
impl<I: Interner, T: ir::TypeFoldable<I>, Ix: Idx> ir::TypeFoldable<I> for IndexVec<Ix, T> {
794+
fn try_fold_with<F: ir::FallibleTypeFolder<I>>(self, folder: &mut F) -> Result<Self, F::Error> {
795795
self.try_map_id(|x| x.try_fold_with(folder))
796796
}
797797
}
798798

799-
impl<'tcx, T: TypeVisitable<'tcx>, I: Idx> ir::TypeVisitable<TyCtxt<'tcx>> for IndexVec<I, T> {
800-
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
799+
impl<I: Interner, T: ir::TypeVisitable<I>, Ix: Idx> ir::TypeVisitable<I> for IndexVec<Ix, T> {
800+
fn visit_with<V: ir::TypeVisitor<I>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
801801
self.iter().try_for_each(|t| t.visit_with(visitor))
802802
}
803803
}

0 commit comments

Comments
 (0)