Skip to content

Commit 94508ca

Browse files
authored
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
2 parents a42a4d6 + f0de294 commit 94508ca

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

src/librustc/mir/interpret/value.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl<'tcx> Scalar {
171171
pub fn from_uint(i: impl Into<u128>, size: Size) -> Self {
172172
let i = i.into();
173173
debug_assert_eq!(truncate(i, size), i,
174-
"Unsigned value {} does not fit in {} bits", i, size.bits());
174+
"Unsigned value {} does not fit in {} bits", i, size.bits());
175175
Scalar::Bits { bits: i, size: size.bytes() as u8 }
176176
}
177177

@@ -181,7 +181,7 @@ impl<'tcx> Scalar {
181181
// `into` performed sign extension, we have to truncate
182182
let truncated = truncate(i as u128, size);
183183
debug_assert_eq!(sign_extend(truncated, size) as i128, i,
184-
"Signed value {} does not fit in {} bits", i, size.bits());
184+
"Signed value {} does not fit in {} bits", i, size.bits());
185185
Scalar::Bits { bits: truncated, size: size.bytes() as u8 }
186186
}
187187

src/librustc/mir/mod.rs

+13-18
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//!
1313
//! [rustc guide]: https://rust-lang-nursery.github.io/rustc-guide/mir/index.html
1414
15-
use graphviz::IntoCow;
1615
use hir::def::CtorKind;
1716
use hir::def_id::DefId;
1817
use hir::{self, HirId, InlineAsm};
@@ -327,22 +326,20 @@ impl<'tcx> Mir<'tcx> {
327326
if idx < stmts.len() {
328327
&stmts[idx].source_info
329328
} else {
330-
assert!(idx == stmts.len());
329+
assert_eq!(idx, stmts.len());
331330
&block.terminator().source_info
332331
}
333332
}
334333

335334
/// Check if `sub` is a sub scope of `sup`
336335
pub fn is_sub_scope(&self, mut sub: SourceScope, sup: SourceScope) -> bool {
337-
loop {
338-
if sub == sup {
339-
return true;
340-
}
336+
while sub != sup {
341337
match self.source_scopes[sub].parent_scope {
342338
None => return false,
343339
Some(p) => sub = p,
344340
}
345341
}
342+
true
346343
}
347344

348345
/// Return the return type, it always return first element from `local_decls` array
@@ -526,9 +523,7 @@ impl BorrowKind {
526523
pub fn allows_two_phase_borrow(&self) -> bool {
527524
match *self {
528525
BorrowKind::Shared | BorrowKind::Shallow | BorrowKind::Unique => false,
529-
BorrowKind::Mut {
530-
allow_two_phase_borrow,
531-
} => allow_two_phase_borrow,
526+
BorrowKind::Mut { allow_two_phase_borrow } => allow_two_phase_borrow,
532527
}
533528
}
534529
}
@@ -1574,42 +1569,42 @@ impl<'tcx> TerminatorKind<'tcx> {
15741569
};
15751570
fmt_const_val(&mut s, &c).unwrap();
15761571
s.into()
1577-
}).chain(iter::once(String::from("otherwise").into()))
1572+
}).chain(iter::once("otherwise".into()))
15781573
.collect()
15791574
}
15801575
Call {
15811576
destination: Some(_),
15821577
cleanup: Some(_),
15831578
..
1584-
} => vec!["return".into_cow(), "unwind".into_cow()],
1579+
} => vec!["return".into(), "unwind".into()],
15851580
Call {
15861581
destination: Some(_),
15871582
cleanup: None,
15881583
..
1589-
} => vec!["return".into_cow()],
1584+
} => vec!["return".into()],
15901585
Call {
15911586
destination: None,
15921587
cleanup: Some(_),
15931588
..
1594-
} => vec!["unwind".into_cow()],
1589+
} => vec!["unwind".into()],
15951590
Call {
15961591
destination: None,
15971592
cleanup: None,
15981593
..
15991594
} => vec![],
1600-
Yield { drop: Some(_), .. } => vec!["resume".into_cow(), "drop".into_cow()],
1601-
Yield { drop: None, .. } => vec!["resume".into_cow()],
1595+
Yield { drop: Some(_), .. } => vec!["resume".into(), "drop".into()],
1596+
Yield { drop: None, .. } => vec!["resume".into()],
16021597
DropAndReplace { unwind: None, .. } | Drop { unwind: None, .. } => {
1603-
vec!["return".into_cow()]
1598+
vec!["return".into()]
16041599
}
16051600
DropAndReplace {
16061601
unwind: Some(_), ..
16071602
}
16081603
| Drop {
16091604
unwind: Some(_), ..
1610-
} => vec!["return".into_cow(), "unwind".into_cow()],
1605+
} => vec!["return".into(), "unwind".into()],
16111606
Assert { cleanup: None, .. } => vec!["".into()],
1612-
Assert { .. } => vec!["success".into_cow(), "unwind".into_cow()],
1607+
Assert { .. } => vec!["success".into(), "unwind".into()],
16131608
FalseEdges {
16141609
ref imaginary_targets,
16151610
..

src/librustc/mir/mono.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> CodegenUnitNameBuilder<'a, 'gcx, 'tcx> {
325325
String::new()
326326
};
327327

328-
let crate_disambiguator = format!("{}", tcx.crate_disambiguator(cnum));
328+
let crate_disambiguator = tcx.crate_disambiguator(cnum).to_string();
329329
// Using a shortened disambiguator of about 40 bits
330330
format!("{}.{}{}",
331331
tcx.crate_name(cnum),

src/librustc/mir/tcx.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
8787
assert!(index < adt_def.variants.len());
8888
assert_eq!(adt_def, adt_def1);
8989
PlaceTy::Downcast { adt_def,
90-
substs,
91-
variant_index: index }
90+
substs,
91+
variant_index: index }
9292
}
9393
_ => {
9494
bug!("cannot downcast non-ADT type: `{:?}`", self)
@@ -151,7 +151,7 @@ impl<'tcx> Place<'tcx> {
151151
}
152152
},
153153
_ => None,
154-
}
154+
}
155155
_ => None,
156156
}
157157
}
@@ -255,9 +255,9 @@ impl<'tcx> Operand<'tcx> {
255255

256256
impl<'tcx> BinOp {
257257
pub fn ty<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
258-
lhs_ty: Ty<'tcx>,
259-
rhs_ty: Ty<'tcx>)
260-
-> Ty<'tcx> {
258+
lhs_ty: Ty<'tcx>,
259+
rhs_ty: Ty<'tcx>)
260+
-> Ty<'tcx> {
261261
// FIXME: handle SIMD correctly
262262
match self {
263263
&BinOp::Add | &BinOp::Sub | &BinOp::Mul | &BinOp::Div | &BinOp::Rem |

0 commit comments

Comments
 (0)