mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Rollup merge of #54788 - ljedrz:cleanup_rustc_mir, r=oli-obk
A handful of cleanups for rustc/mir - use the "regular" `into()` instead of `graphviz::IntoCow` in `mod.rs` - `format!("{}", x)` > `x.to_string()` - remove one unnecessary `String` allocation - shorten the logic of one loop - `assert!(x == y)` > `assert_eq!(x, y)` - whitespace & formatting fixes r? @oli-obk
This commit is contained in:
commit
bc2859d5a6
@ -171,7 +171,7 @@ impl<'tcx> Scalar {
|
||||
pub fn from_uint(i: impl Into<u128>, size: Size) -> Self {
|
||||
let i = i.into();
|
||||
debug_assert_eq!(truncate(i, size), i,
|
||||
"Unsigned value {} does not fit in {} bits", i, size.bits());
|
||||
"Unsigned value {} does not fit in {} bits", i, size.bits());
|
||||
Scalar::Bits { bits: i, size: size.bytes() as u8 }
|
||||
}
|
||||
|
||||
@ -181,7 +181,7 @@ impl<'tcx> Scalar {
|
||||
// `into` performed sign extension, we have to truncate
|
||||
let truncated = truncate(i as u128, size);
|
||||
debug_assert_eq!(sign_extend(truncated, size) as i128, i,
|
||||
"Signed value {} does not fit in {} bits", i, size.bits());
|
||||
"Signed value {} does not fit in {} bits", i, size.bits());
|
||||
Scalar::Bits { bits: truncated, size: size.bytes() as u8 }
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,6 @@
|
||||
//!
|
||||
//! [rustc guide]: https://rust-lang-nursery.github.io/rustc-guide/mir/index.html
|
||||
|
||||
use graphviz::IntoCow;
|
||||
use hir::def::CtorKind;
|
||||
use hir::def_id::DefId;
|
||||
use hir::{self, HirId, InlineAsm};
|
||||
@ -327,22 +326,20 @@ impl<'tcx> Mir<'tcx> {
|
||||
if idx < stmts.len() {
|
||||
&stmts[idx].source_info
|
||||
} else {
|
||||
assert!(idx == stmts.len());
|
||||
assert_eq!(idx, stmts.len());
|
||||
&block.terminator().source_info
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if `sub` is a sub scope of `sup`
|
||||
pub fn is_sub_scope(&self, mut sub: SourceScope, sup: SourceScope) -> bool {
|
||||
loop {
|
||||
if sub == sup {
|
||||
return true;
|
||||
}
|
||||
while sub != sup {
|
||||
match self.source_scopes[sub].parent_scope {
|
||||
None => return false,
|
||||
Some(p) => sub = p,
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
/// Return the return type, it always return first element from `local_decls` array
|
||||
@ -526,9 +523,7 @@ impl BorrowKind {
|
||||
pub fn allows_two_phase_borrow(&self) -> bool {
|
||||
match *self {
|
||||
BorrowKind::Shared | BorrowKind::Shallow | BorrowKind::Unique => false,
|
||||
BorrowKind::Mut {
|
||||
allow_two_phase_borrow,
|
||||
} => allow_two_phase_borrow,
|
||||
BorrowKind::Mut { allow_two_phase_borrow } => allow_two_phase_borrow,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1574,42 +1569,42 @@ impl<'tcx> TerminatorKind<'tcx> {
|
||||
};
|
||||
fmt_const_val(&mut s, &c).unwrap();
|
||||
s.into()
|
||||
}).chain(iter::once(String::from("otherwise").into()))
|
||||
}).chain(iter::once("otherwise".into()))
|
||||
.collect()
|
||||
}
|
||||
Call {
|
||||
destination: Some(_),
|
||||
cleanup: Some(_),
|
||||
..
|
||||
} => vec!["return".into_cow(), "unwind".into_cow()],
|
||||
} => vec!["return".into(), "unwind".into()],
|
||||
Call {
|
||||
destination: Some(_),
|
||||
cleanup: None,
|
||||
..
|
||||
} => vec!["return".into_cow()],
|
||||
} => vec!["return".into()],
|
||||
Call {
|
||||
destination: None,
|
||||
cleanup: Some(_),
|
||||
..
|
||||
} => vec!["unwind".into_cow()],
|
||||
} => vec!["unwind".into()],
|
||||
Call {
|
||||
destination: None,
|
||||
cleanup: None,
|
||||
..
|
||||
} => vec![],
|
||||
Yield { drop: Some(_), .. } => vec!["resume".into_cow(), "drop".into_cow()],
|
||||
Yield { drop: None, .. } => vec!["resume".into_cow()],
|
||||
Yield { drop: Some(_), .. } => vec!["resume".into(), "drop".into()],
|
||||
Yield { drop: None, .. } => vec!["resume".into()],
|
||||
DropAndReplace { unwind: None, .. } | Drop { unwind: None, .. } => {
|
||||
vec!["return".into_cow()]
|
||||
vec!["return".into()]
|
||||
}
|
||||
DropAndReplace {
|
||||
unwind: Some(_), ..
|
||||
}
|
||||
| Drop {
|
||||
unwind: Some(_), ..
|
||||
} => vec!["return".into_cow(), "unwind".into_cow()],
|
||||
} => vec!["return".into(), "unwind".into()],
|
||||
Assert { cleanup: None, .. } => vec!["".into()],
|
||||
Assert { .. } => vec!["success".into_cow(), "unwind".into_cow()],
|
||||
Assert { .. } => vec!["success".into(), "unwind".into()],
|
||||
FalseEdges {
|
||||
ref imaginary_targets,
|
||||
..
|
||||
|
@ -325,7 +325,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> CodegenUnitNameBuilder<'a, 'gcx, 'tcx> {
|
||||
String::new()
|
||||
};
|
||||
|
||||
let crate_disambiguator = format!("{}", tcx.crate_disambiguator(cnum));
|
||||
let crate_disambiguator = tcx.crate_disambiguator(cnum).to_string();
|
||||
// Using a shortened disambiguator of about 40 bits
|
||||
format!("{}.{}{}",
|
||||
tcx.crate_name(cnum),
|
||||
|
@ -87,8 +87,8 @@ impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
|
||||
assert!(index < adt_def.variants.len());
|
||||
assert_eq!(adt_def, adt_def1);
|
||||
PlaceTy::Downcast { adt_def,
|
||||
substs,
|
||||
variant_index: index }
|
||||
substs,
|
||||
variant_index: index }
|
||||
}
|
||||
_ => {
|
||||
bug!("cannot downcast non-ADT type: `{:?}`", self)
|
||||
@ -151,7 +151,7 @@ impl<'tcx> Place<'tcx> {
|
||||
}
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@ -255,9 +255,9 @@ impl<'tcx> Operand<'tcx> {
|
||||
|
||||
impl<'tcx> BinOp {
|
||||
pub fn ty<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
lhs_ty: Ty<'tcx>,
|
||||
rhs_ty: Ty<'tcx>)
|
||||
-> Ty<'tcx> {
|
||||
lhs_ty: Ty<'tcx>,
|
||||
rhs_ty: Ty<'tcx>)
|
||||
-> Ty<'tcx> {
|
||||
// FIXME: handle SIMD correctly
|
||||
match self {
|
||||
&BinOp::Add | &BinOp::Sub | &BinOp::Mul | &BinOp::Div | &BinOp::Rem |
|
||||
|
Loading…
Reference in New Issue
Block a user