Skip to content

Commit b55d8a3

Browse files
Apply nits, make some bounds into supertraits on inherent traits
1 parent f368527 commit b55d8a3

File tree

6 files changed

+57
-56
lines changed

6 files changed

+57
-56
lines changed

compiler/rustc_middle/src/ty/predicate.rs

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ pub struct Predicate<'tcx>(
3030
pub(super) Interned<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>>,
3131
);
3232

33+
impl<'tcx> rustc_type_ir::inherent::Predicate<TyCtxt<'tcx>> for Predicate<'tcx> {}
34+
3335
impl<'tcx> rustc_type_ir::visit::Flags for Predicate<'tcx> {
3436
fn flags(&self) -> TypeFlags {
3537
self.0.flags

compiler/rustc_traits/src/type_op.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_infer::infer::TyCtxtInferExt;
33
use rustc_middle::query::Providers;
44
use rustc_middle::traits::query::NoSolution;
55
use rustc_middle::ty::{Clause, ParamEnvAnd};
6-
use rustc_middle::ty::{FnSig, Lift, PolyFnSig, Ty, TyCtxt, TypeFoldable};
6+
use rustc_middle::ty::{FnSig, PolyFnSig, Ty, TyCtxt, TypeFoldable};
77
use rustc_trait_selection::infer::InferCtxtBuilderExt;
88
use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt;
99
use rustc_trait_selection::traits::query::type_op::ascribe_user_type::{

compiler/rustc_type_ir/src/inherent.rs

+43-7
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,69 @@
1-
use crate::{BoundVar, DebruijnIndex, Interner, UniverseIndex};
1+
use std::fmt::Debug;
2+
use std::hash::Hash;
23

3-
pub trait Ty<I: Interner<Ty = Self>> {
4+
use crate::fold::TypeSuperFoldable;
5+
use crate::visit::{Flags, TypeSuperVisitable};
6+
use crate::{
7+
BoundVar, ConstKind, DebruijnIndex, DebugWithInfcx, Interner, RegionKind, TyKind, UniverseIndex,
8+
};
9+
10+
pub trait Ty<I: Interner<Ty = Self>>:
11+
Copy
12+
+ DebugWithInfcx<I>
13+
+ Hash
14+
+ Eq
15+
+ Into<I::GenericArg>
16+
+ IntoKind<Kind = TyKind<I>>
17+
+ TypeSuperVisitable<I>
18+
+ TypeSuperFoldable<I>
19+
+ Flags
20+
{
421
fn new_anon_bound(interner: I, debruijn: DebruijnIndex, var: BoundVar) -> Self;
522
}
623

7-
pub trait Region<I: Interner<Region = Self>> {
24+
pub trait Region<I: Interner<Region = Self>>:
25+
Copy + DebugWithInfcx<I> + Hash + Eq + Into<I::GenericArg> + IntoKind<Kind = RegionKind<I>> + Flags
26+
{
827
fn new_anon_bound(interner: I, debruijn: DebruijnIndex, var: BoundVar) -> Self;
928

1029
fn new_static(interner: I) -> Self;
1130
}
1231

13-
pub trait Const<I: Interner<Const = Self>> {
32+
pub trait Const<I: Interner<Const = Self>>:
33+
Copy
34+
+ DebugWithInfcx<I>
35+
+ Hash
36+
+ Eq
37+
+ Into<I::GenericArg>
38+
+ IntoKind<Kind = ConstKind<I>>
39+
+ TypeSuperVisitable<I>
40+
+ TypeSuperFoldable<I>
41+
+ Flags
42+
{
1443
fn new_anon_bound(interner: I, debruijn: DebruijnIndex, var: BoundVar, ty: I::Ty) -> Self;
1544

1645
fn ty(self) -> I::Ty;
1746
}
1847

19-
pub trait GenericsOf<I: Interner> {
48+
pub trait GenericsOf<I: Interner<GenericsOf = Self>> {
2049
fn count(&self) -> usize;
2150
}
2251

23-
pub trait GenericArgs<I: Interner> {
52+
pub trait GenericArgs<I: Interner<GenericArgs = Self>>:
53+
Copy + DebugWithInfcx<I> + Hash + Eq + IntoIterator<Item = I::GenericArg>
54+
{
2455
fn type_at(self, i: usize) -> I::Ty;
2556

2657
fn identity_for_item(interner: I, def_id: I::DefId) -> I::GenericArgs;
2758
}
2859

60+
pub trait Predicate<I: Interner<Predicate = Self>>:
61+
Copy + Debug + Hash + Eq + TypeSuperVisitable<I> + TypeSuperFoldable<I> + Flags
62+
{
63+
}
64+
2965
/// Common capabilities of placeholder kinds
30-
pub trait PlaceholderLike {
66+
pub trait PlaceholderLike: Copy + Debug + Hash + Eq {
3167
fn universe(self) -> UniverseIndex;
3268
fn var(self) -> BoundVar;
3369

compiler/rustc_type_ir/src/interner.rs

+9-46
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,17 @@ use smallvec::SmallVec;
22
use std::fmt::Debug;
33
use std::hash::Hash;
44

5-
use crate::fold::TypeSuperFoldable;
65
use crate::inherent::*;
76
use crate::ir_print::IrPrint;
87
use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable};
9-
use crate::{CanonicalVarInfo, ConstKind, DebugWithInfcx, RegionKind, TraitRef, TyKind};
8+
use crate::{CanonicalVarInfo, DebugWithInfcx, TraitRef};
109

1110
pub trait Interner: Sized + Copy + IrPrint<TraitRef<Self>> {
1211
type DefId: Copy + Debug + Hash + Eq;
1312
type DefiningOpaqueTypes: Copy + Debug + Hash + Default + Eq + TypeVisitable<Self>;
1413
type AdtDef: Copy + Debug + Hash + Eq;
1514

16-
type GenericArgs: Copy
17-
+ DebugWithInfcx<Self>
18-
+ Hash
19-
+ Eq
20-
+ IntoIterator<Item = Self::GenericArg>
21-
+ GenericArgs<Self>;
15+
type GenericArgs: GenericArgs<Self>;
2216
type GenericArg: Copy + DebugWithInfcx<Self> + Hash + Eq;
2317
type Term: Copy + Debug + Hash + Eq;
2418

@@ -29,21 +23,12 @@ pub trait Interner: Sized + Copy + IrPrint<TraitRef<Self>> {
2923
type CanonicalVars: Copy + Debug + Hash + Eq + IntoIterator<Item = CanonicalVarInfo<Self>>;
3024

3125
// Kinds of tys
32-
type Ty: Copy
33-
+ DebugWithInfcx<Self>
34-
+ Hash
35-
+ Eq
36-
+ Into<Self::GenericArg>
37-
+ IntoKind<Kind = TyKind<Self>>
38-
+ TypeSuperVisitable<Self>
39-
+ TypeSuperFoldable<Self>
40-
+ Flags
41-
+ Ty<Self>;
26+
type Ty: Ty<Self>;
4227
type Tys: Copy + Debug + Hash + Eq + IntoIterator<Item = Self::Ty>;
4328
type AliasTy: Copy + DebugWithInfcx<Self> + Hash + Eq;
4429
type ParamTy: Copy + Debug + Hash + Eq;
4530
type BoundTy: Copy + Debug + Hash + Eq;
46-
type PlaceholderTy: Copy + Debug + Hash + Eq + PlaceholderLike;
31+
type PlaceholderTy: PlaceholderLike;
4732

4833
// Things stored inside of tys
4934
type ErrorGuaranteed: Copy + Debug + Hash + Eq;
@@ -53,46 +38,24 @@ pub trait Interner: Sized + Copy + IrPrint<TraitRef<Self>> {
5338
type Pat: Copy + Debug + Hash + Eq + DebugWithInfcx<Self>;
5439

5540
// Kinds of consts
56-
type Const: Copy
57-
+ DebugWithInfcx<Self>
58-
+ Hash
59-
+ Eq
60-
+ Into<Self::GenericArg>
61-
+ IntoKind<Kind = ConstKind<Self>>
62-
+ TypeSuperVisitable<Self>
63-
+ TypeSuperFoldable<Self>
64-
+ Flags
65-
+ Const<Self>;
41+
type Const: Const<Self>;
6642
type AliasConst: Copy + DebugWithInfcx<Self> + Hash + Eq;
67-
type PlaceholderConst: Copy + Debug + Hash + Eq + PlaceholderLike;
43+
type PlaceholderConst: PlaceholderLike;
6844
type ParamConst: Copy + Debug + Hash + Eq;
6945
type BoundConst: Copy + Debug + Hash + Eq;
7046
type ValueConst: Copy + Debug + Hash + Eq;
7147
type ExprConst: Copy + DebugWithInfcx<Self> + Hash + Eq;
7248

7349
// Kinds of regions
74-
type Region: Copy
75-
+ DebugWithInfcx<Self>
76-
+ Hash
77-
+ Eq
78-
+ Into<Self::GenericArg>
79-
+ IntoKind<Kind = RegionKind<Self>>
80-
+ Flags
81-
+ Region<Self>;
50+
type Region: Region<Self>;
8251
type EarlyParamRegion: Copy + Debug + Hash + Eq;
8352
type LateParamRegion: Copy + Debug + Hash + Eq;
8453
type BoundRegion: Copy + Debug + Hash + Eq;
8554
type InferRegion: Copy + DebugWithInfcx<Self> + Hash + Eq;
86-
type PlaceholderRegion: Copy + Debug + Hash + Eq + PlaceholderLike;
55+
type PlaceholderRegion: PlaceholderLike;
8756

8857
// Predicates
89-
type Predicate: Copy
90-
+ Debug
91-
+ Hash
92-
+ Eq
93-
+ TypeSuperVisitable<Self>
94-
+ TypeSuperFoldable<Self>
95-
+ Flags;
58+
type Predicate: Predicate<Self>;
9659
type TraitPredicate: Copy + Debug + Hash + Eq;
9760
type RegionOutlivesPredicate: Copy + Debug + Hash + Eq;
9861
type TypeOutlivesPredicate: Copy + Debug + Hash + Eq;

compiler/rustc_type_ir/src/ir_print.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub trait IrPrint<T> {
88
}
99

1010
macro_rules! define_display_via_print {
11-
($($ty:ident,)*) => {
11+
($($ty:ident),+ $(,)?) => {
1212
$(
1313
impl<I: Interner> fmt::Display for $ty<I> {
1414
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {

compiler/rustc_type_ir/src/trait_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct TraitRef<I: Interner> {
3131
pub args: I::GenericArgs,
3232
/// This field exists to prevent the creation of `TraitRef` without
3333
/// calling [`TraitRef::new`].
34-
pub(super) _use_trait_ref_new_instead: (),
34+
_use_trait_ref_new_instead: (),
3535
}
3636

3737
impl<I: Interner> TraitRef<I> {

0 commit comments

Comments
 (0)