Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
- Take more things by self, not &self
- Clone more things
- Rework namespacing so we can use `ty::` in the canonicalizer
  • Loading branch information
compiler-errors committed Dec 5, 2023
1 parent 97ad9b2 commit aa30616
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 228 deletions.
8 changes: 4 additions & 4 deletions compiler/rustc_middle/src/ty/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ pub struct Const<'tcx>(pub(super) Interned<'tcx, WithCachedTypeInfo<ConstData<'t
impl<'tcx> IntoKind for Const<'tcx> {
type Kind = ConstKind<'tcx>;

fn kind(&self) -> ConstKind<'tcx> {
(*self).kind().clone()
fn kind(self) -> ConstKind<'tcx> {
self.kind().clone()
}
}

impl<'tcx> ConstTy<TyCtxt<'tcx>> for Const<'tcx> {
fn ty(&self) -> Ty<'tcx> {
(*self).ty()
fn ty(self) -> Ty<'tcx> {
self.ty()
}
}

Expand Down
31 changes: 10 additions & 21 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,40 +131,29 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
(ty, mutbl)
}

fn mk_canonical_var_infos(
&self,
infos: &[rustc_type_ir::CanonicalVarInfo<Self>],
) -> Self::CanonicalVars {
(*self).mk_canonical_var_infos(infos)
fn mk_canonical_var_infos(self, infos: &[ty::CanonicalVarInfo<Self>]) -> Self::CanonicalVars {
self.mk_canonical_var_infos(infos)
}

fn mk_bound_ty(
&self,
debruijn: rustc_type_ir::DebruijnIndex,
var: rustc_type_ir::BoundVar,
) -> Self::Ty {
Ty::new_bound(*self, debruijn, ty::BoundTy { var, kind: ty::BoundTyKind::Anon })
fn mk_bound_ty(self, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self::Ty {
Ty::new_bound(self, debruijn, ty::BoundTy { var, kind: ty::BoundTyKind::Anon })
}

fn mk_bound_region(
&self,
debruijn: rustc_type_ir::DebruijnIndex,
var: rustc_type_ir::BoundVar,
) -> Self::Region {
fn mk_bound_region(self, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self::Region {
Region::new_bound(
*self,
self,
debruijn,
ty::BoundRegion { var, kind: ty::BoundRegionKind::BrAnon },
)
}

fn mk_bound_const(
&self,
debruijn: rustc_type_ir::DebruijnIndex,
var: rustc_type_ir::BoundVar,
self,
debruijn: ty::DebruijnIndex,
var: ty::BoundVar,
ty: Self::Ty,
) -> Self::Const {
Const::new_bound(*self, debruijn, var, ty)
Const::new_bound(self, debruijn, var, ty)
}
}

Expand Down
39 changes: 17 additions & 22 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,10 @@ use std::ops::ControlFlow;
use std::{fmt, str};

pub use crate::ty::diagnostics::*;
pub use rustc_type_ir::AliasKind::*;
pub use rustc_type_ir::ConstKind::{
Bound as BoundCt, Error as ErrorCt, Expr as ExprCt, Infer as InferCt, Param as ParamCt,
Placeholder as PlaceholderCt, Unevaluated, Value,
};
pub use rustc_type_ir::DynKind::*;
pub use rustc_type_ir::InferTy::*;
pub use rustc_type_ir::RegionKind::*;
pub use rustc_type_ir::TyKind::*;
pub use rustc_type_ir::*;

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

fn kind(&self) -> TyKind<'tcx> {
(*self).kind().clone()
fn kind(self) -> TyKind<'tcx> {
self.kind().clone()
}
}

Expand Down Expand Up @@ -1515,17 +1510,17 @@ pub struct Placeholder<T> {

pub type PlaceholderRegion = Placeholder<BoundRegion>;

impl rustc_type_ir::Placeholder for PlaceholderRegion {
fn universe(&self) -> UniverseIndex {
impl PlaceholderLike for PlaceholderRegion {
fn universe(self) -> UniverseIndex {
self.universe
}

fn var(&self) -> BoundVar {
fn var(self) -> BoundVar {
self.bound.var
}

fn with_updated_universe(&self, ui: UniverseIndex) -> Self {
Placeholder { universe: ui, ..*self }
fn with_updated_universe(self, ui: UniverseIndex) -> Self {
Placeholder { universe: ui, ..self }
}

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

pub type PlaceholderType = Placeholder<BoundTy>;

impl rustc_type_ir::Placeholder for PlaceholderType {
fn universe(&self) -> UniverseIndex {
impl PlaceholderLike for PlaceholderType {
fn universe(self) -> UniverseIndex {
self.universe
}

fn var(&self) -> BoundVar {
fn var(self) -> BoundVar {
self.bound.var
}

fn with_updated_universe(&self, ui: UniverseIndex) -> Self {
Placeholder { universe: ui, ..*self }
fn with_updated_universe(self, ui: UniverseIndex) -> Self {
Placeholder { universe: ui, ..self }
}

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

pub type PlaceholderConst = Placeholder<BoundVar>;

impl rustc_type_ir::Placeholder for PlaceholderConst {
fn universe(&self) -> UniverseIndex {
impl PlaceholderLike for PlaceholderConst {
fn universe(self) -> UniverseIndex {
self.universe
}

fn var(&self) -> BoundVar {
fn var(self) -> BoundVar {
self.bound
}

fn with_updated_universe(&self, ui: UniverseIndex) -> Self {
Placeholder { universe: ui, ..*self }
fn with_updated_universe(self, ui: UniverseIndex) -> Self {
Placeholder { universe: ui, ..self }
}

fn new(ui: UniverseIndex, var: BoundVar) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1492,8 +1492,8 @@ pub struct Region<'tcx>(pub Interned<'tcx, RegionKind<'tcx>>);
impl<'tcx> IntoKind for Region<'tcx> {
type Kind = RegionKind<'tcx>;

fn kind(&self) -> RegionKind<'tcx> {
**self
fn kind(self) -> RegionKind<'tcx> {
*self
}
}

Expand Down
Loading

0 comments on commit aa30616

Please sign in to comment.