Skip to content

Commit f4e8863

Browse files
Uplift TypeVisitableExt into rustc_type_ir
1 parent bc1b9e0 commit f4e8863

File tree

12 files changed

+476
-315
lines changed

12 files changed

+476
-315
lines changed

compiler/rustc_middle/src/ty/consts.rs

+12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ impl<'tcx> IntoKind for Const<'tcx> {
3535
}
3636
}
3737

38+
impl<'tcx> rustc_type_ir::visit::Flags for Const<'tcx> {
39+
fn flags(&self) -> TypeFlags {
40+
self.0.flags
41+
}
42+
43+
fn outer_exclusive_binder(&self) -> rustc_type_ir::DebruijnIndex {
44+
self.0.outer_exclusive_binder
45+
}
46+
}
47+
3848
impl<'tcx> ConstTy<TyCtxt<'tcx>> for Const<'tcx> {
3949
fn ty(self) -> Ty<'tcx> {
4050
self.ty()
@@ -63,11 +73,13 @@ impl<'tcx> Const<'tcx> {
6373
self.0.kind
6474
}
6575

76+
// FIXME(compiler-errors): Think about removing this.
6677
#[inline]
6778
pub fn flags(self) -> TypeFlags {
6879
self.0.flags
6980
}
7081

82+
// FIXME(compiler-errors): Think about removing this.
7183
#[inline]
7284
pub fn outer_exclusive_binder(self) -> ty::DebruijnIndex {
7385
self.0.outer_exclusive_binder

compiler/rustc_middle/src/ty/context.rs

+7
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
8888
type Term = ty::Term<'tcx>;
8989

9090
type Binder<T> = Binder<'tcx, T>;
91+
type BoundVars = &'tcx List<ty::BoundVariableKind>;
92+
type BoundVar = ty::BoundVariableKind;
9193
type CanonicalVars = CanonicalVarInfos<'tcx>;
9294

9395
type Ty = Ty<'tcx>;
@@ -151,6 +153,11 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
151153
) -> Self::Const {
152154
Const::new_bound(self, debruijn, var, ty)
153155
}
156+
157+
fn expect_error_or_delayed_bug() {
158+
let has_errors = ty::tls::with(|tcx| tcx.dcx().has_errors_or_lint_errors_or_delayed_bugs());
159+
assert!(has_errors.is_some());
160+
}
154161
}
155162

156163
type InternedSet<'tcx, T> = ShardedHashMap<InternedInSet<'tcx, T>, ()>;

compiler/rustc_middle/src/ty/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,16 @@ impl<'tcx> IntoKind for Ty<'tcx> {
503503
}
504504
}
505505

506+
impl<'tcx> rustc_type_ir::visit::Flags for Ty<'tcx> {
507+
fn flags(&self) -> TypeFlags {
508+
self.0.flags
509+
}
510+
511+
fn outer_exclusive_binder(&self) -> DebruijnIndex {
512+
self.0.outer_exclusive_binder
513+
}
514+
}
515+
506516
impl EarlyParamRegion {
507517
/// Does this early bound region have a name? Early bound regions normally
508518
/// always have names except when using anonymous lifetimes (`'_`).

compiler/rustc_middle/src/ty/predicate.rs

+12
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,30 @@ pub struct Predicate<'tcx>(
2929
pub(super) Interned<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>>,
3030
);
3131

32+
impl<'tcx> rustc_type_ir::visit::Flags for Predicate<'tcx> {
33+
fn flags(&self) -> TypeFlags {
34+
self.0.flags
35+
}
36+
37+
fn outer_exclusive_binder(&self) -> ty::DebruijnIndex {
38+
self.0.outer_exclusive_binder
39+
}
40+
}
41+
3242
impl<'tcx> Predicate<'tcx> {
3343
/// Gets the inner `ty::Binder<'tcx, PredicateKind<'tcx>>`.
3444
#[inline]
3545
pub fn kind(self) -> ty::Binder<'tcx, PredicateKind<'tcx>> {
3646
self.0.internee
3747
}
3848

49+
// FIXME(compiler-errors): Think about removing this.
3950
#[inline(always)]
4051
pub fn flags(self) -> TypeFlags {
4152
self.0.flags
4253
}
4354

55+
// FIXME(compiler-errors): Think about removing this.
4456
#[inline(always)]
4557
pub fn outer_exclusive_binder(self) -> DebruijnIndex {
4658
self.0.outer_exclusive_binder

compiler/rustc_middle/src/ty/region.rs

+13
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ impl<'tcx> rustc_type_ir::IntoKind for Region<'tcx> {
2626
}
2727
}
2828

29+
impl<'tcx> rustc_type_ir::visit::Flags for Region<'tcx> {
30+
fn flags(&self) -> TypeFlags {
31+
self.type_flags()
32+
}
33+
34+
fn outer_exclusive_binder(&self) -> ty::DebruijnIndex {
35+
match **self {
36+
ty::ReBound(debruijn, _) => debruijn.shifted_in(1),
37+
_ => ty::INNERMOST,
38+
}
39+
}
40+
}
41+
2942
impl<'tcx> Region<'tcx> {
3043
#[inline]
3144
pub fn new_early_param(

compiler/rustc_middle/src/ty/sty.rs

+11
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,16 @@ where
942942
}
943943
}
944944

945+
impl<'tcx, T> rustc_type_ir::BoundVars<TyCtxt<'tcx>> for ty::Binder<'tcx, T> {
946+
fn bound_vars(&self) -> &'tcx List<ty::BoundVariableKind> {
947+
self.bound_vars
948+
}
949+
950+
fn has_no_bound_vars(&self) -> bool {
951+
self.bound_vars.is_empty()
952+
}
953+
}
954+
945955
impl<'tcx, T> Binder<'tcx, T> {
946956
/// Skips the binder and returns the "bound" value. This is a
947957
/// risky thing to do because it's easy to get confused about
@@ -1808,6 +1818,7 @@ impl<'tcx> Ty<'tcx> {
18081818
self.0.0
18091819
}
18101820

1821+
// FIXME(compiler-errors): Think about removing this.
18111822
#[inline(always)]
18121823
pub fn flags(self) -> TypeFlags {
18131824
self.0.0.flags

compiler/rustc_middle/src/ty/util.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,7 @@ impl<'tcx> Ty<'tcx> {
13201320
ty
13211321
}
13221322

1323+
// FIXME(compiler-errors): Think about removing this.
13231324
#[inline]
13241325
pub fn outer_exclusive_binder(self) -> ty::DebruijnIndex {
13251326
self.0.outer_exclusive_binder

0 commit comments

Comments
 (0)