Skip to content

Commit 9b8fcc5

Browse files
committed
Make no-op traversables generic over the interner
1 parent d1cc6e5 commit 9b8fcc5

File tree

8 files changed

+22
-21
lines changed

8 files changed

+22
-21
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4693,6 +4693,7 @@ dependencies = [
46934693
"rustc_serialize",
46944694
"rustc_span",
46954695
"rustc_target",
4696+
"rustc_type_ir",
46964697
"smallvec",
46974698
"tracing",
46984699
]
@@ -5340,6 +5341,7 @@ dependencies = [
53405341
"rustc_macros",
53415342
"rustc_serialize",
53425343
"rustc_span",
5344+
"rustc_type_ir",
53435345
"serde_json",
53445346
"tracing",
53455347
]

compiler/rustc_hir/Cargo.toml

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

compiler/rustc_hir/src/hir.rs

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

31923192
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
3193-
#[derive(Encodable, Decodable, HashStable_Generic)]
3193+
#[derive(Encodable, Decodable, HashStable_Generic, TypeFoldable, TypeVisitable)]
31943194
pub enum Unsafety {
31953195
Unsafe,
31963196
Normal,

compiler/rustc_middle/src/macros.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,28 @@ macro_rules! CloneLiftImpls {
6767
/// allocated data** (i.e., don't need to be folded).
6868
#[macro_export]
6969
macro_rules! TrivialTypeTraversalImpls {
70-
(for <$tcx:lifetime> { $($ty:ty,)+ }) => {
70+
($(for { $($generic:tt)+ } { $interner:ty } { $ty:ty })+) => {
7171
$(
72-
impl<$tcx> $crate::ty::fold::TypeFoldable<$crate::ty::TyCtxt<$tcx>> for $ty {
73-
fn try_fold_with<F: $crate::ty::fold::FallibleTypeFolder<$crate::ty::TyCtxt<$tcx>>>(
72+
impl<$($generic)+> $crate::ty::fold::TypeFoldable<$interner> for $ty {
73+
fn try_fold_with<F: $crate::ty::fold::FallibleTypeFolder<$interner>>(
7474
self,
7575
_: &mut F,
7676
) -> ::std::result::Result<Self, F::Error> {
7777
Ok(self)
7878
}
7979

8080
#[inline]
81-
fn fold_with<F: $crate::ty::fold::TypeFolder<$crate::ty::TyCtxt<$tcx>>>(
81+
fn fold_with<F: $crate::ty::fold::TypeFolder<$interner>>(
8282
self,
8383
_: &mut F,
8484
) -> Self {
8585
self
8686
}
8787
}
8888

89-
impl<$tcx> $crate::ty::visit::TypeVisitable<$crate::ty::TyCtxt<$tcx>> for $ty {
89+
impl<$($generic)+> $crate::ty::visit::TypeVisitable<$interner> for $ty {
9090
#[inline]
91-
fn visit_with<F: $crate::ty::visit::TypeVisitor<$crate::ty::TyCtxt<$tcx>>>(
91+
fn visit_with<F: $crate::ty::visit::TypeVisitor<$interner>>(
9292
&self,
9393
_: &mut F)
9494
-> ::std::ops::ControlFlow<F::BreakTy>
@@ -99,11 +99,15 @@ macro_rules! TrivialTypeTraversalImpls {
9999
)+
100100
};
101101

102+
(for <$tcx:lifetime> { $($ty:ty,)+ }) => {
103+
TrivialTypeTraversalImpls! {
104+
$(for { $tcx } { $crate::ty::TyCtxt<$tcx> } { $ty })+
105+
}
106+
};
107+
102108
($($ty:ty,)+) => {
103109
TrivialTypeTraversalImpls! {
104-
for<'tcx> {
105-
$($ty,)+
106-
}
110+
$(for { I: $crate::ty::Interner } { I } { $ty })+
107111
}
108112
};
109113
}

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::ty::{self, AliasTy, Lift, Term, TermKind, Ty, TyCtxt};
1212
use rustc_hir::def::Namespace;
1313
use rustc_index::vec::{Idx, IndexVec};
1414
use rustc_span::source_map::Spanned;
15-
use rustc_target::abi::TyAndLayout;
1615

1716
use std::fmt;
1817
use std::ops::ControlFlow;
@@ -223,7 +222,9 @@ CloneLiftImpls! {
223222
::rustc_hir::HirId,
224223
::rustc_hir::MatchSource,
225224
::rustc_hir::Mutability,
225+
::rustc_hir::Unsafety,
226226
::rustc_target::asm::InlineAsmRegOrRegClass,
227+
::rustc_target::spec::abi::Abi,
227228
crate::mir::coverage::ExpressionOperandId,
228229
crate::mir::coverage::CounterValueReference,
229230
crate::mir::coverage::InjectedExpressionId,
@@ -265,8 +266,6 @@ CloneLiftImpls! {
265266
// implementation and traversal implementations (the latter only for
266267
// TyCtxt<'_> interners).
267268
TrivialTypeTraversalAndLiftImpls! {
268-
::rustc_hir::Unsafety,
269-
::rustc_target::spec::abi::Abi,
270269
crate::ty::BoundConstness,
271270
}
272271

@@ -675,9 +674,3 @@ impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for ty::UnevaluatedConst<'tcx> {
675674
self.substs.visit_with(visitor)
676675
}
677676
}
678-
679-
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for TyAndLayout<'tcx, Ty<'tcx>> {
680-
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
681-
visitor.visit_ty(self.ty)
682-
}
683-
}

compiler/rustc_target/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ 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" }

compiler/rustc_target/src/abi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl ToJson for Endian {
2424
/// to that obtained from `layout_of(ty)`, as we need to produce
2525
/// layouts for which Rust types do not exist, such as enum variants
2626
/// or synthetic fields of enums (i.e., discriminants) and fat pointers.
27-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable_Generic)]
27+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable_Generic, TypeVisitable)]
2828
pub struct TyAndLayout<'a, Ty> {
2929
pub ty: Ty,
3030
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)