Skip to content

Commit 90064c3

Browse files
Uplift TypeVisitableExt into rustc_type_ir
1 parent 233b213 commit 90064c3

File tree

12 files changed

+476
-315
lines changed

12 files changed

+476
-315
lines changed

compiler/rustc_middle/src/ty/consts.rs

Lines changed: 12 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,16 @@ impl<'tcx> IntoKind for Ty<'tcx> {
496496
}
497497
}
498498

499+
impl<'tcx> rustc_type_ir::visit::Flags for Ty<'tcx> {
500+
fn flags(&self) -> TypeFlags {
501+
self.0.flags
502+
}
503+
504+
fn outer_exclusive_binder(&self) -> DebruijnIndex {
505+
self.0.outer_exclusive_binder
506+
}
507+
}
508+
499509
impl EarlyParamRegion {
500510
/// Does this early bound region have a name? Early bound regions normally
501511
/// always have names except when using anonymous lifetimes (`'_`).

compiler/rustc_middle/src/ty/predicate.rs

Lines changed: 12 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,16 @@ where
642642
}
643643
}
644644

645+
impl<'tcx, T> rustc_type_ir::BoundVars<TyCtxt<'tcx>> for ty::Binder<'tcx, T> {
646+
fn bound_vars(&self) -> &'tcx List<ty::BoundVariableKind> {
647+
self.bound_vars
648+
}
649+
650+
fn has_no_bound_vars(&self) -> bool {
651+
self.bound_vars.is_empty()
652+
}
653+
}
654+
645655
impl<'tcx, T> Binder<'tcx, T> {
646656
/// Skips the binder and returns the "bound" value. This is a
647657
/// risky thing to do because it's easy to get confused about
@@ -1492,6 +1502,7 @@ impl<'tcx> Ty<'tcx> {
14921502
self.0.0
14931503
}
14941504

1505+
// FIXME(compiler-errors): Think about removing this.
14951506
#[inline(always)]
14961507
pub fn flags(self) -> TypeFlags {
14971508
self.0.0.flags

compiler/rustc_middle/src/ty/util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,7 @@ impl<'tcx> Ty<'tcx> {
13121312
ty
13131313
}
13141314

1315+
// FIXME(compiler-errors): Think about removing this.
13151316
#[inline]
13161317
pub fn outer_exclusive_binder(self) -> ty::DebruijnIndex {
13171318
self.0.outer_exclusive_binder

0 commit comments

Comments
 (0)