Skip to content

Commit

Permalink
Prefer no blocks around trivial match arms
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Dec 23, 2019
1 parent c229719 commit 734fa6c
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 33 deletions.
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
use_small_heuristics = "Max"
version = "Two"
match_arm_blocks = false
5 changes: 2 additions & 3 deletions src/bin/cargo-miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,10 @@ fn inside_cargo_rustc() {
}

match command.status() {
Ok(exit) => {
Ok(exit) =>
if !exit.success() {
std::process::exit(exit.code().unwrap_or(42));
}
}
},
Err(ref e) if needs_miri => panic!("error during miri run: {:?}", e),
Err(ref e) => panic!("error during rustc call: {:?}", e),
}
Expand Down
5 changes: 2 additions & 3 deletions src/bin/miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,8 @@ fn main() {
FromHexError::InvalidHexCharacter { .. } => panic!(
"-Zmiri-seed should only contain valid hex digits [0-9a-fA-F]"
),
FromHexError::OddLength => {
panic!("-Zmiri-seed should have an even number of digits")
}
FromHexError::OddLength =>
panic!("-Zmiri-seed should have an even number of digits"),
err => panic!("Unknown error decoding -Zmiri-seed as hex: {:?}", err),
});
if seed_raw.len() > 8 {
Expand Down
15 changes: 6 additions & 9 deletions src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,21 +215,18 @@ pub fn eval_main<'tcx>(tcx: TyCtxt<'tcx>, main_id: DefId, config: MiriConfig) ->
.expect("invalid MachineStop payload");
match info {
TerminationInfo::Exit(code) => return Some(*code),
TerminationInfo::PoppedTrackedPointerTag(item) => {
format!("popped tracked tag for item {:?}", item)
}
TerminationInfo::Abort => {
format!("the evaluated program aborted execution")
}
TerminationInfo::PoppedTrackedPointerTag(item) =>
format!("popped tracked tag for item {:?}", item),
TerminationInfo::Abort =>
format!("the evaluated program aborted execution"),
}
}
err_unsup!(NoMirFor(..)) => format!(
"{}. Did you set `MIRI_SYSROOT` to a Miri-enabled sysroot? You can prepare one with `cargo miri setup`.",
e
),
InterpError::InvalidProgram(_) => {
bug!("This error should be impossible in Miri: {}", e)
}
InterpError::InvalidProgram(_) =>
bug!("This error should be impossible in Miri: {}", e),
_ => e.to_string(),
};
e.print_backtrace();
Expand Down
5 changes: 2 additions & 3 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn visit_value(&mut self, v: MPlaceTy<'tcx, Tag>) -> InterpResult<'tcx> {
trace!("UnsafeCellVisitor: {:?} {:?}", *v, v.layout.ty);
let is_unsafe_cell = match v.layout.ty.kind {
ty::Adt(adt, _) => {
Some(adt.did) == self.ecx.tcx.lang_items().unsafe_cell_type()
}
ty::Adt(adt, _) =>
Some(adt.did) == self.ecx.tcx.lang_items().unsafe_cell_type(),
_ => false,
};
if is_unsafe_cell {
Expand Down
5 changes: 2 additions & 3 deletions src/shims/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let name = this.memory.read_c_str(name_ptr)?;
Ok(match this.machine.env_vars.map.get(name) {
// The offset is used to strip the "{name}=" part of the string.
Some(var_ptr) => {
Scalar::from(var_ptr.offset(Size::from_bytes(name.len() as u64 + 1), this)?)
}
Some(var_ptr) =>
Scalar::from(var_ptr.offset(Size::from_bytes(name.len() as u64 + 1), this)?),
None => Scalar::ptr_null(&*this.tcx),
})
}
Expand Down
10 changes: 4 additions & 6 deletions src/shims/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
throw_machine_stop!(TerminationInfo::Abort);
}
"miri_start_panic" => return this.handle_miri_start_panic(args, unwind),
_ => {
_ =>
if let Some(p) = ret {
p
} else {
throw_unsup_format!("unimplemented (diverging) intrinsic: {}", intrinsic_name);
}
}
},
};

match intrinsic_name {
Expand Down Expand Up @@ -375,9 +374,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.write_scalar(Scalar::from_f64(res), dest)?;
}

"exact_div" => {
this.exact_div(this.read_immediate(args[0])?, this.read_immediate(args[1])?, dest)?
}
"exact_div" =>
this.exact_div(this.read_immediate(args[0])?, this.read_immediate(args[1])?, dest)?,

"forget" => {}

Expand Down
10 changes: 4 additions & 6 deletions src/stacked_borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,8 @@ impl Stacks {
// Thus we call `static_base_ptr` such that the global pointers get the same tag
// as what we use here.
// The base pointer is not unique, so the base permission is `SharedReadWrite`.
MemoryKind::Machine(MiriMemoryKind::Static) => {
(extra.borrow_mut().static_base_ptr(id), Permission::SharedReadWrite)
}
MemoryKind::Machine(MiriMemoryKind::Static) =>
(extra.borrow_mut().static_base_ptr(id), Permission::SharedReadWrite),
// Everything else we handle entirely untagged for now.
// FIXME: experiment with more precise tracking.
_ => (Tag::Untagged, Permission::SharedReadWrite),
Expand Down Expand Up @@ -611,9 +610,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
)),
ty::Ref(_, _, Immutable) => Some((RefKind::Shared, kind == RetagKind::FnEntry)),
// Raw pointers need to be enabled.
ty::RawPtr(tym) if kind == RetagKind::Raw => {
Some((RefKind::Raw { mutable: tym.mutbl == Mutable }, false))
}
ty::RawPtr(tym) if kind == RetagKind::Raw =>
Some((RefKind::Raw { mutable: tym.mutbl == Mutable }, false)),
// Boxes do not get a protector: protectors reflect that references outlive the call
// they were passed in to; that's just not the case for boxes.
ty::Adt(..) if ty.is_box() => Some((RefKind::Unique { two_phase: false }, false)),
Expand Down

0 comments on commit 734fa6c

Please sign in to comment.