Skip to content

Commit 8a17195

Browse files
committed
Make no-op traversables generic over the interner
1 parent 14b85cb commit 8a17195

File tree

8 files changed

+26
-31
lines changed

8 files changed

+26
-31
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3931,6 +3931,7 @@ dependencies = [
39313931
"rustc_serialize",
39323932
"rustc_span",
39333933
"rustc_target",
3934+
"rustc_type_ir",
39343935
"smallvec",
39353936
"tracing",
39363937
]
@@ -4585,6 +4586,7 @@ dependencies = [
45854586
"rustc_macros",
45864587
"rustc_serialize",
45874588
"rustc_span",
4589+
"rustc_type_ir",
45884590
"serde_json",
45894591
"tracing",
45904592
]

compiler/rustc_hir/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ rustc_macros = { path = "../rustc_macros" }
1515
rustc_serialize = { path = "../rustc_serialize" }
1616
rustc_span = { path = "../rustc_span" }
1717
rustc_target = { path = "../rustc_target" }
18+
rustc_type_ir = { path = "../rustc_type_ir" }
1819
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
1920
tracing = "0.1"
2021
# tidy-alphabetical-end

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3256,7 +3256,7 @@ impl<'hir> Item<'hir> {
32563256
}
32573257

32583258
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
3259-
#[derive(Encodable, Decodable, HashStable_Generic)]
3259+
#[derive(Encodable, Decodable, HashStable_Generic, TypeFoldable, TypeVisitable)]
32603260
pub enum Unsafety {
32613261
Unsafe,
32623262
Normal,

compiler/rustc_middle/src/macros.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,28 @@ macro_rules! TrivialLiftImpls {
5959
/// allocated data** (i.e., don't need to be folded).
6060
#[macro_export]
6161
macro_rules! TrivialTypeTraversalImpls {
62-
($($ty:ty),+ $(,)?) => {
62+
($(for { $($generic:tt)+ } { $interner:ty } { $ty:ty })+) => {
6363
$(
64-
impl<'tcx> $crate::ty::fold::TypeFoldable<$crate::ty::TyCtxt<'tcx>> for $ty {
65-
fn try_fold_with<F: $crate::ty::fold::FallibleTypeFolder<$crate::ty::TyCtxt<'tcx>>>(
64+
impl<$($generic)+> $crate::ty::fold::TypeFoldable<$interner> for $ty {
65+
fn try_fold_with<F: $crate::ty::fold::FallibleTypeFolder<$interner>>(
6666
self,
6767
_: &mut F,
6868
) -> ::std::result::Result<Self, F::Error> {
6969
Ok(self)
7070
}
7171

7272
#[inline]
73-
fn fold_with<F: $crate::ty::fold::TypeFolder<$crate::ty::TyCtxt<'tcx>>>(
73+
fn fold_with<F: $crate::ty::fold::TypeFolder<$interner>>(
7474
self,
7575
_: &mut F,
7676
) -> Self {
7777
self
7878
}
7979
}
8080

81-
impl<'tcx> $crate::ty::visit::TypeVisitable<$crate::ty::TyCtxt<'tcx>> for $ty {
81+
impl<$($generic)+> $crate::ty::visit::TypeVisitable<$interner> for $ty {
8282
#[inline]
83-
fn visit_with<F: $crate::ty::visit::TypeVisitor<$crate::ty::TyCtxt<'tcx>>>(
83+
fn visit_with<F: $crate::ty::visit::TypeVisitor<$interner>>(
8484
&self,
8585
_: &mut F)
8686
-> ::std::ops::ControlFlow<F::BreakTy>
@@ -90,12 +90,16 @@ macro_rules! TrivialTypeTraversalImpls {
9090
}
9191
)+
9292
};
93-
}
9493

95-
#[macro_export]
96-
macro_rules! TrivialTypeTraversalAndLiftImpls {
97-
($($t:tt)*) => {
98-
TrivialTypeTraversalImpls! { $($t)* }
99-
TrivialLiftImpls! { $($t)* }
100-
}
94+
(for <$tcx:lifetime> { $($ty:ty),+ $(,)? }) => {
95+
TrivialTypeTraversalImpls! {
96+
$(for { $tcx } { $crate::ty::TyCtxt<$tcx> } { $ty })+
97+
}
98+
};
99+
100+
($($ty:ty),+ $(,)?) => {
101+
TrivialTypeTraversalImpls! {
102+
$(for { I: $crate::ty::Interner } { I } { $ty })+
103+
}
104+
};
101105
}

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor};
1010
use crate::ty::{self, AliasTy, InferConst, Lift, Term, TermKind, Ty, TyCtxt};
1111
use rustc_hir::def::Namespace;
1212
use rustc_span::source_map::Spanned;
13-
use rustc_target::abi::TyAndLayout;
1413
use rustc_type_ir::{ConstKind, DebugWithInfcx, InferCtxtLike, WithInfcx};
1514

1615
use std::fmt::{self, Debug};
@@ -409,6 +408,8 @@ TrivialLiftImpls! {
409408
u64,
410409
::rustc_hir::def_id::DefId,
411410
::rustc_hir::Mutability,
411+
::rustc_hir::Unsafety,
412+
::rustc_target::spec::abi::Abi,
412413
crate::ty::ClosureKind,
413414
crate::ty::ParamConst,
414415
crate::ty::ParamTy,
@@ -423,14 +424,6 @@ TrivialLiftImpls! {
423424
TrivialTypeTraversalImpls! {
424425
crate::ty::BoundConstness,
425426
}
426-
// For some things about which the type library does not know, or does not
427-
// provide any traversal implementations, we need to provide a traversal
428-
// implementation and a lift implementation (the former only for TyCtxt<'_>
429-
// interners).
430-
TrivialTypeTraversalAndLiftImpls! {
431-
::rustc_hir::Unsafety,
432-
::rustc_target::spec::abi::Abi,
433-
}
434427

435428
///////////////////////////////////////////////////////////////////////////
436429
// Lift implementations
@@ -753,9 +746,3 @@ impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for ty::UnevaluatedConst<'tcx> {
753746
self.args.visit_with(visitor)
754747
}
755748
}
756-
757-
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for TyAndLayout<'tcx, Ty<'tcx>> {
758-
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
759-
visitor.visit_ty(self.ty)
760-
}
761-
}

compiler/rustc_target/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ rustc_index = { path = "../rustc_index" }
1414
rustc_macros = { path = "../rustc_macros" }
1515
rustc_serialize = { path = "../rustc_serialize" }
1616
rustc_span = { path = "../rustc_span" }
17+
rustc_type_ir = { path = "../rustc_type_ir" }
1718
serde_json = "1.0.59"
1819
tracing = "0.1"
1920
# tidy-alphabetical-end

compiler/rustc_target/src/abi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<'a> Layout<'a> {
131131
/// to that obtained from `layout_of(ty)`, as we need to produce
132132
/// layouts for which Rust types do not exist, such as enum variants
133133
/// or synthetic fields of enums (i.e., discriminants) and fat pointers.
134-
#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable_Generic)]
134+
#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable_Generic, TypeVisitable)]
135135
pub struct TyAndLayout<'a, Ty> {
136136
pub ty: Ty,
137137
pub layout: Layout<'a>,

compiler/rustc_target/src/spec/abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::{Span, Symbol};
88
mod tests;
99

1010
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Debug)]
11-
#[derive(HashStable_Generic, Encodable, Decodable)]
11+
#[derive(HashStable_Generic, Encodable, Decodable, TypeFoldable, TypeVisitable)]
1212
pub enum Abi {
1313
// Some of the ABIs come first because every time we add a new ABI, we have to re-bless all the
1414
// hashing tests. These are used in many places, so giving them stable values reduces test

0 commit comments

Comments
 (0)