From f0de294a9b6d09b9933c1a22419831ac4bc49ca9 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Wed, 3 Oct 2018 15:07:18 +0200 Subject: [PATCH] A handful of cleanups for rustc/mir --- src/librustc/mir/interpret/value.rs | 4 ++-- src/librustc/mir/mod.rs | 31 ++++++++++++----------------- src/librustc/mir/mono.rs | 2 +- src/librustc/mir/tcx.rs | 12 +++++------ 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/librustc/mir/interpret/value.rs b/src/librustc/mir/interpret/value.rs index d695ad88e47aa..c81d55e69b61a 100644 --- a/src/librustc/mir/interpret/value.rs +++ b/src/librustc/mir/interpret/value.rs @@ -171,7 +171,7 @@ impl<'tcx> Scalar { pub fn from_uint(i: impl Into, 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 } } diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index f36d9553d31c9..fe88897a82ccc 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -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, } } } @@ -1551,42 +1546,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, .. diff --git a/src/librustc/mir/mono.rs b/src/librustc/mir/mono.rs index 4d353a36db02a..7520695a7cd90 100644 --- a/src/librustc/mir/mono.rs +++ b/src/librustc/mir/mono.rs @@ -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), diff --git a/src/librustc/mir/tcx.rs b/src/librustc/mir/tcx.rs index 2a25e057a7149..fc7b4862b0ae5 100644 --- a/src/librustc/mir/tcx.rs +++ b/src/librustc/mir/tcx.rs @@ -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 |