Skip to content

Commit f0de294

Browse files
committed
A handful of cleanups for rustc/mir
1 parent 4cf1176 commit f0de294

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
}
@@ -1551,42 +1546,42 @@ impl<'tcx> TerminatorKind<'tcx> {
15511546
};
15521547
fmt_const_val(&mut s, &c).unwrap();
15531548
s.into()
1554-
}).chain(iter::once(String::from("otherwise").into()))
1549+
}).chain(iter::once("otherwise".into()))
15551550
.collect()
15561551
}
15571552
Call {
15581553
destination: Some(_),
15591554
cleanup: Some(_),
15601555
..
1561-
} => vec!["return".into_cow(), "unwind".into_cow()],
1556+
} => vec!["return".into(), "unwind".into()],
15621557
Call {
15631558
destination: Some(_),
15641559
cleanup: None,
15651560
..
1566-
} => vec!["return".into_cow()],
1561+
} => vec!["return".into()],
15671562
Call {
15681563
destination: None,
15691564
cleanup: Some(_),
15701565
..
1571-
} => vec!["unwind".into_cow()],
1566+
} => vec!["unwind".into()],
15721567
Call {
15731568
destination: None,
15741569
cleanup: None,
15751570
..
15761571
} => vec![],
1577-
Yield { drop: Some(_), .. } => vec!["resume".into_cow(), "drop".into_cow()],
1578-
Yield { drop: None, .. } => vec!["resume".into_cow()],
1572+
Yield { drop: Some(_), .. } => vec!["resume".into(), "drop".into()],
1573+
Yield { drop: None, .. } => vec!["resume".into()],
15791574
DropAndReplace { unwind: None, .. } | Drop { unwind: None, .. } => {
1580-
vec!["return".into_cow()]
1575+
vec!["return".into()]
15811576
}
15821577
DropAndReplace {
15831578
unwind: Some(_), ..
15841579
}
15851580
| Drop {
15861581
unwind: Some(_), ..
1587-
} => vec!["return".into_cow(), "unwind".into_cow()],
1582+
} => vec!["return".into(), "unwind".into()],
15881583
Assert { cleanup: None, .. } => vec!["".into()],
1589-
Assert { .. } => vec!["success".into_cow(), "unwind".into_cow()],
1584+
Assert { .. } => vec!["success".into(), "unwind".into()],
15901585
FalseEdges {
15911586
ref imaginary_targets,
15921587
..

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)