Skip to content

Commit

Permalink
Auto merge of rust-lang#94021 - tmiasko:inline, r=nagisa
Browse files Browse the repository at this point in the history
Inline a few trivial conversion functions
  • Loading branch information
bors committed Feb 15, 2022
2 parents 09cb29c + ea71420 commit 393fdc1
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_infer/src/infer/type_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ impl<'tcx> ut::UnifyKey for TyVidEqKey<'tcx> {
fn index(&self) -> u32 {
self.vid.as_u32()
}
#[inline]
fn from_index(i: u32) -> Self {
TyVidEqKey::from(ty::TyVid::from_u32(i))
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/infer/unify_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ impl<'tcx> From<ty::RegionVid> for RegionVidKey<'tcx> {

impl<'tcx> UnifyKey for RegionVidKey<'tcx> {
type Value = UnifiedRegion<'tcx>;
#[inline]
fn index(&self) -> u32 {
self.vid.as_u32()
}
#[inline]
fn from_index(i: u32) -> Self {
RegionVidKey::from(ty::RegionVid::from_u32(i))
}
Expand Down Expand Up @@ -118,9 +120,11 @@ pub struct ConstVarValue<'tcx> {

impl<'tcx> UnifyKey for ty::ConstVid<'tcx> {
type Value = ConstVarValue<'tcx>;
#[inline]
fn index(&self) -> u32 {
self.index
}
#[inline]
fn from_index(i: u32) -> Self {
ty::ConstVid { index: i, phantom: PhantomData }
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/ty/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub enum GenericArgKind<'tcx> {
}

impl<'tcx> GenericArgKind<'tcx> {
#[inline]
fn pack(self) -> GenericArg<'tcx> {
let (tag, ptr) = match self {
GenericArgKind::Lifetime(lt) => {
Expand Down Expand Up @@ -94,18 +95,21 @@ impl<'tcx> PartialOrd for GenericArg<'tcx> {
}

impl<'tcx> From<ty::Region<'tcx>> for GenericArg<'tcx> {
#[inline]
fn from(r: ty::Region<'tcx>) -> GenericArg<'tcx> {
GenericArgKind::Lifetime(r).pack()
}
}

impl<'tcx> From<Ty<'tcx>> for GenericArg<'tcx> {
#[inline]
fn from(ty: Ty<'tcx>) -> GenericArg<'tcx> {
GenericArgKind::Type(ty).pack()
}
}

impl<'tcx> From<ty::Const<'tcx>> for GenericArg<'tcx> {
#[inline]
fn from(c: ty::Const<'tcx>) -> GenericArg<'tcx> {
GenericArgKind::Const(c).pack()
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_mir_transform/src/dest_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,11 @@ impl From<Local> for UnifyLocal {

impl UnifyKey for UnifyLocal {
type Value = ();
#[inline]
fn index(&self) -> u32 {
self.0.as_u32()
}
#[inline]
fn from_index(u: u32) -> Self {
Self(Local::from_u32(u))
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_span/src/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,12 @@ impl LocalExpnId {
/// The ID of the theoretical expansion that generates freshly parsed, unexpanded AST.
pub const ROOT: LocalExpnId = LocalExpnId::from_u32(0);

#[inline]
pub fn from_raw(idx: ExpnIndex) -> LocalExpnId {
LocalExpnId::from_u32(idx.as_u32())
}

#[inline]
pub fn as_raw(self) -> ExpnIndex {
ExpnIndex::from_u32(self.as_u32())
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1541,11 +1541,13 @@ impl Default for TargetOptions {
impl Deref for Target {
type Target = TargetOptions;

#[inline]
fn deref(&self) -> &Self::Target {
&self.options
}
}
impl DerefMut for Target {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.options
}
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_type_ir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,11 @@ pub enum InferTy {
/// they carry no values.
impl UnifyKey for TyVid {
type Value = ();
#[inline]
fn index(&self) -> u32 {
self.as_u32()
}
#[inline]
fn from_index(i: u32) -> TyVid {
TyVid::from_u32(i)
}
Expand All @@ -419,6 +421,7 @@ impl UnifyKey for IntVid {
fn index(&self) -> u32 {
self.index
}
#[inline]
fn from_index(i: u32) -> IntVid {
IntVid { index: i }
}
Expand All @@ -431,9 +434,11 @@ impl EqUnifyValue for FloatVarValue {}

impl UnifyKey for FloatVid {
type Value = Option<FloatVarValue>;
#[inline]
fn index(&self) -> u32 {
self.index
}
#[inline]
fn from_index(i: u32) -> FloatVid {
FloatVid { index: i }
}
Expand Down

0 comments on commit 393fdc1

Please sign in to comment.