Skip to content

Commit 9df736b

Browse files
authored
Unrolled build for rust-lang#120498
Rollup merge of rust-lang#120498 - compiler-errors:type-flags, r=lcnr Uplift `TypeVisitableExt` into `rustc_type_ir` This uplifts `TypeVisitableExt` into `rustc_type_ir` so it can be used in an interner-agnostic way. It also moves some `TypeSuperVisitable` bounds onto `Interner` since we don't expect to support libraries that have types which aren't foldable by default. This restores a couple of asserts in the canonicalizer code we uplifted, and also makes it so that we can use type-flags-based helpers in the solver code, which I'm interested in uplifting. r? lcnr
2 parents 81b757c + 7e80867 commit 9df736b

File tree

13 files changed

+469
-341
lines changed

13 files changed

+469
-341
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

+9-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::ty::{
2828
self, AdtDef, AdtDefData, AdtKind, Binder, Clause, Const, ConstData, GenericParamDefKind,
2929
ImplPolarity, List, ParamConst, ParamTy, PolyExistentialPredicate, PolyFnSig, Predicate,
3030
PredicateKind, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyVid,
31-
Visibility,
31+
TypeVisitable, Visibility,
3232
};
3333
use crate::ty::{GenericArg, GenericArgs, GenericArgsRef};
3434
use rustc_ast::{self as ast, attr};
@@ -87,7 +87,9 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
8787
type GenericArg = ty::GenericArg<'tcx>;
8888
type Term = ty::Term<'tcx>;
8989

90-
type Binder<T> = Binder<'tcx, T>;
90+
type Binder<T: TypeVisitable<TyCtxt<'tcx>>> = 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
@@ -504,6 +504,16 @@ impl<'tcx> IntoKind for Ty<'tcx> {
504504
}
505505
}
506506

507+
impl<'tcx> rustc_type_ir::visit::Flags for Ty<'tcx> {
508+
fn flags(&self) -> TypeFlags {
509+
self.0.flags
510+
}
511+
512+
fn outer_exclusive_binder(&self) -> DebruijnIndex {
513+
self.0.outer_exclusive_binder
514+
}
515+
}
516+
507517
impl EarlyParamRegion {
508518
/// Does this early bound region have a name? Early bound regions normally
509519
/// 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)