Skip to content

Commit 606533e

Browse files
Feedback
- Take more things by self, not &self - Clone more things - Rework namespacing so we can use `ty::` in the canonicalizer
1 parent f66e1c2 commit 606533e

File tree

11 files changed

+204
-228
lines changed

11 files changed

+204
-228
lines changed

compiler/rustc_middle/src/ty/consts.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ pub struct Const<'tcx>(pub(super) Interned<'tcx, WithCachedTypeInfo<ConstData<'t
3131
impl<'tcx> IntoKind for Const<'tcx> {
3232
type Kind = ConstKind<'tcx>;
3333

34-
fn kind(&self) -> ConstKind<'tcx> {
35-
(*self).kind().clone()
34+
fn kind(self) -> ConstKind<'tcx> {
35+
self.kind().clone()
3636
}
3737
}
3838

3939
impl<'tcx> ConstTy<TyCtxt<'tcx>> for Const<'tcx> {
40-
fn ty(&self) -> Ty<'tcx> {
41-
(*self).ty()
40+
fn ty(self) -> Ty<'tcx> {
41+
self.ty()
4242
}
4343
}
4444

compiler/rustc_middle/src/ty/context.rs

+10-21
Original file line numberDiff line numberDiff line change
@@ -131,40 +131,29 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
131131
(ty, mutbl)
132132
}
133133

134-
fn mk_canonical_var_infos(
135-
&self,
136-
infos: &[rustc_type_ir::CanonicalVarInfo<Self>],
137-
) -> Self::CanonicalVars {
138-
(*self).mk_canonical_var_infos(infos)
134+
fn mk_canonical_var_infos(self, infos: &[ty::CanonicalVarInfo<Self>]) -> Self::CanonicalVars {
135+
self.mk_canonical_var_infos(infos)
139136
}
140137

141-
fn mk_bound_ty(
142-
&self,
143-
debruijn: rustc_type_ir::DebruijnIndex,
144-
var: rustc_type_ir::BoundVar,
145-
) -> Self::Ty {
146-
Ty::new_bound(*self, debruijn, ty::BoundTy { var, kind: ty::BoundTyKind::Anon })
138+
fn mk_bound_ty(self, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self::Ty {
139+
Ty::new_bound(self, debruijn, ty::BoundTy { var, kind: ty::BoundTyKind::Anon })
147140
}
148141

149-
fn mk_bound_region(
150-
&self,
151-
debruijn: rustc_type_ir::DebruijnIndex,
152-
var: rustc_type_ir::BoundVar,
153-
) -> Self::Region {
142+
fn mk_bound_region(self, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self::Region {
154143
Region::new_bound(
155-
*self,
144+
self,
156145
debruijn,
157146
ty::BoundRegion { var, kind: ty::BoundRegionKind::BrAnon },
158147
)
159148
}
160149

161150
fn mk_bound_const(
162-
&self,
163-
debruijn: rustc_type_ir::DebruijnIndex,
164-
var: rustc_type_ir::BoundVar,
151+
self,
152+
debruijn: ty::DebruijnIndex,
153+
var: ty::BoundVar,
165154
ty: Self::Ty,
166155
) -> Self::Const {
167-
Const::new_bound(*self, debruijn, var, ty)
156+
Const::new_bound(self, debruijn, var, ty)
168157
}
169158
}
170159

compiler/rustc_middle/src/ty/mod.rs

+17-22
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,10 @@ use std::ops::ControlFlow;
6565
use std::{fmt, str};
6666

6767
pub use crate::ty::diagnostics::*;
68-
pub use rustc_type_ir::AliasKind::*;
6968
pub use rustc_type_ir::ConstKind::{
7069
Bound as BoundCt, Error as ErrorCt, Expr as ExprCt, Infer as InferCt, Param as ParamCt,
7170
Placeholder as PlaceholderCt, Unevaluated, Value,
7271
};
73-
pub use rustc_type_ir::DynKind::*;
74-
pub use rustc_type_ir::InferTy::*;
75-
pub use rustc_type_ir::RegionKind::*;
76-
pub use rustc_type_ir::TyKind::*;
7772
pub use rustc_type_ir::*;
7873

7974
pub use self::binding::BindingMode;
@@ -478,8 +473,8 @@ pub struct Ty<'tcx>(Interned<'tcx, WithCachedTypeInfo<TyKind<'tcx>>>);
478473
impl<'tcx> IntoKind for Ty<'tcx> {
479474
type Kind = TyKind<'tcx>;
480475

481-
fn kind(&self) -> TyKind<'tcx> {
482-
(*self).kind().clone()
476+
fn kind(self) -> TyKind<'tcx> {
477+
self.kind().clone()
483478
}
484479
}
485480

@@ -1515,17 +1510,17 @@ pub struct Placeholder<T> {
15151510

15161511
pub type PlaceholderRegion = Placeholder<BoundRegion>;
15171512

1518-
impl rustc_type_ir::Placeholder for PlaceholderRegion {
1519-
fn universe(&self) -> UniverseIndex {
1513+
impl PlaceholderLike for PlaceholderRegion {
1514+
fn universe(self) -> UniverseIndex {
15201515
self.universe
15211516
}
15221517

1523-
fn var(&self) -> BoundVar {
1518+
fn var(self) -> BoundVar {
15241519
self.bound.var
15251520
}
15261521

1527-
fn with_updated_universe(&self, ui: UniverseIndex) -> Self {
1528-
Placeholder { universe: ui, ..*self }
1522+
fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1523+
Placeholder { universe: ui, ..self }
15291524
}
15301525

15311526
fn new(ui: UniverseIndex, var: BoundVar) -> Self {
@@ -1535,17 +1530,17 @@ impl rustc_type_ir::Placeholder for PlaceholderRegion {
15351530

15361531
pub type PlaceholderType = Placeholder<BoundTy>;
15371532

1538-
impl rustc_type_ir::Placeholder for PlaceholderType {
1539-
fn universe(&self) -> UniverseIndex {
1533+
impl PlaceholderLike for PlaceholderType {
1534+
fn universe(self) -> UniverseIndex {
15401535
self.universe
15411536
}
15421537

1543-
fn var(&self) -> BoundVar {
1538+
fn var(self) -> BoundVar {
15441539
self.bound.var
15451540
}
15461541

1547-
fn with_updated_universe(&self, ui: UniverseIndex) -> Self {
1548-
Placeholder { universe: ui, ..*self }
1542+
fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1543+
Placeholder { universe: ui, ..self }
15491544
}
15501545

15511546
fn new(ui: UniverseIndex, var: BoundVar) -> Self {
@@ -1562,17 +1557,17 @@ pub struct BoundConst<'tcx> {
15621557

15631558
pub type PlaceholderConst = Placeholder<BoundVar>;
15641559

1565-
impl rustc_type_ir::Placeholder for PlaceholderConst {
1566-
fn universe(&self) -> UniverseIndex {
1560+
impl PlaceholderLike for PlaceholderConst {
1561+
fn universe(self) -> UniverseIndex {
15671562
self.universe
15681563
}
15691564

1570-
fn var(&self) -> BoundVar {
1565+
fn var(self) -> BoundVar {
15711566
self.bound
15721567
}
15731568

1574-
fn with_updated_universe(&self, ui: UniverseIndex) -> Self {
1575-
Placeholder { universe: ui, ..*self }
1569+
fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1570+
Placeholder { universe: ui, ..self }
15761571
}
15771572

15781573
fn new(ui: UniverseIndex, var: BoundVar) -> Self {

compiler/rustc_middle/src/ty/sty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1492,8 +1492,8 @@ pub struct Region<'tcx>(pub Interned<'tcx, RegionKind<'tcx>>);
14921492
impl<'tcx> IntoKind for Region<'tcx> {
14931493
type Kind = RegionKind<'tcx>;
14941494

1495-
fn kind(&self) -> RegionKind<'tcx> {
1496-
**self
1495+
fn kind(self) -> RegionKind<'tcx> {
1496+
*self
14971497
}
14981498
}
14991499

0 commit comments

Comments
 (0)