Skip to content

Commit 1f5895b

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 cb41509 commit 1f5895b

File tree

11 files changed

+205
-229
lines changed

11 files changed

+205
-229
lines changed

compiler/rustc_middle/src/ty/consts.rs

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

32-
fn kind(&self) -> ConstKind<'tcx> {
33-
(*self).kind().clone()
32+
fn kind(self) -> ConstKind<'tcx> {
33+
self.kind().clone()
3434
}
3535
}
3636

3737
impl<'tcx> ConstTy<TyCtxt<'tcx>> for Const<'tcx> {
38-
fn ty(&self) -> Ty<'tcx> {
39-
(*self).ty()
38+
fn ty(self) -> Ty<'tcx> {
39+
self.ty()
4040
}
4141
}
4242

compiler/rustc_middle/src/ty/context.rs

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

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

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

150-
fn mk_bound_region(
151-
&self,
152-
debruijn: rustc_type_ir::DebruijnIndex,
153-
var: rustc_type_ir::BoundVar,
154-
) -> Self::Region {
143+
fn mk_bound_region(self, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self::Region {
155144
Region::new_bound(
156-
*self,
145+
self,
157146
debruijn,
158147
ty::BoundRegion { var, kind: ty::BoundRegionKind::BrAnon },
159148
)
160149
}
161150

162151
fn mk_bound_const(
163-
&self,
164-
debruijn: rustc_type_ir::DebruijnIndex,
165-
var: rustc_type_ir::BoundVar,
152+
self,
153+
debruijn: ty::DebruijnIndex,
154+
var: ty::BoundVar,
166155
ty: Self::Ty,
167156
) -> Self::Const {
168-
Const::new_bound(*self, debruijn, var, ty)
157+
Const::new_bound(self, debruijn, var, ty)
169158
}
170159
}
171160

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;
@@ -477,8 +472,8 @@ pub struct Ty<'tcx>(Interned<'tcx, WithCachedTypeInfo<TyKind<'tcx>>>);
477472
impl<'tcx> IntoKind for Ty<'tcx> {
478473
type Kind = TyKind<'tcx>;
479474

480-
fn kind(&self) -> TyKind<'tcx> {
481-
(*self).kind().clone()
475+
fn kind(self) -> TyKind<'tcx> {
476+
self.kind().clone()
482477
}
483478
}
484479

@@ -1553,17 +1548,17 @@ pub struct Placeholder<T> {
15531548

15541549
pub type PlaceholderRegion = Placeholder<BoundRegion>;
15551550

1556-
impl rustc_type_ir::Placeholder for PlaceholderRegion {
1557-
fn universe(&self) -> UniverseIndex {
1551+
impl PlaceholderLike for PlaceholderRegion {
1552+
fn universe(self) -> UniverseIndex {
15581553
self.universe
15591554
}
15601555

1561-
fn var(&self) -> BoundVar {
1556+
fn var(self) -> BoundVar {
15621557
self.bound.var
15631558
}
15641559

1565-
fn with_updated_universe(&self, ui: UniverseIndex) -> Self {
1566-
Placeholder { universe: ui, ..*self }
1560+
fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1561+
Placeholder { universe: ui, ..self }
15671562
}
15681563

15691564
fn new(ui: UniverseIndex, var: BoundVar) -> Self {
@@ -1573,17 +1568,17 @@ impl rustc_type_ir::Placeholder for PlaceholderRegion {
15731568

15741569
pub type PlaceholderType = Placeholder<BoundTy>;
15751570

1576-
impl rustc_type_ir::Placeholder for PlaceholderType {
1577-
fn universe(&self) -> UniverseIndex {
1571+
impl PlaceholderLike for PlaceholderType {
1572+
fn universe(self) -> UniverseIndex {
15781573
self.universe
15791574
}
15801575

1581-
fn var(&self) -> BoundVar {
1576+
fn var(self) -> BoundVar {
15821577
self.bound.var
15831578
}
15841579

1585-
fn with_updated_universe(&self, ui: UniverseIndex) -> Self {
1586-
Placeholder { universe: ui, ..*self }
1580+
fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1581+
Placeholder { universe: ui, ..self }
15871582
}
15881583

15891584
fn new(ui: UniverseIndex, var: BoundVar) -> Self {
@@ -1600,17 +1595,17 @@ pub struct BoundConst<'tcx> {
16001595

16011596
pub type PlaceholderConst = Placeholder<BoundVar>;
16021597

1603-
impl rustc_type_ir::Placeholder for PlaceholderConst {
1604-
fn universe(&self) -> UniverseIndex {
1598+
impl PlaceholderLike for PlaceholderConst {
1599+
fn universe(self) -> UniverseIndex {
16051600
self.universe
16061601
}
16071602

1608-
fn var(&self) -> BoundVar {
1603+
fn var(self) -> BoundVar {
16091604
self.bound
16101605
}
16111606

1612-
fn with_updated_universe(&self, ui: UniverseIndex) -> Self {
1613-
Placeholder { universe: ui, ..*self }
1607+
fn with_updated_universe(self, ui: UniverseIndex) -> Self {
1608+
Placeholder { universe: ui, ..self }
16141609
}
16151610

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

compiler/rustc_middle/src/ty/sty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1480,8 +1480,8 @@ pub struct Region<'tcx>(pub Interned<'tcx, RegionKind<'tcx>>);
14801480
impl<'tcx> IntoKind for Region<'tcx> {
14811481
type Kind = RegionKind<'tcx>;
14821482

1483-
fn kind(&self) -> RegionKind<'tcx> {
1484-
**self
1483+
fn kind(self) -> RegionKind<'tcx> {
1484+
*self
14851485
}
14861486
}
14871487

0 commit comments

Comments
 (0)