diff --git a/benches/helpers/miri_helper.rs b/benches/helpers/miri_helper.rs index b26705cb70..2d27616a36 100644 --- a/benches/helpers/miri_helper.rs +++ b/benches/helpers/miri_helper.rs @@ -40,9 +40,10 @@ fn find_sysroot() -> String { let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN")); match (home, toolchain) { (Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain), - _ => option_env!("RUST_SYSROOT") - .expect("need to specify RUST_SYSROOT env var or use rustup or multirust") - .to_owned(), + _ => + option_env!("RUST_SYSROOT") + .expect("need to specify RUST_SYSROOT env var or use rustup or multirust") + .to_owned(), } } diff --git a/cargo-miri/bin.rs b/cargo-miri/bin.rs index 1a7552c5d9..23546988da 100644 --- a/cargo-miri/bin.rs +++ b/cargo-miri/bin.rs @@ -528,9 +528,10 @@ fn phase_cargo_miri(mut args: env::Args) { Some("run") => MiriCommand::Run, Some("setup") => MiriCommand::Setup, // Invalid command. - _ => show_error(format!( - "`cargo miri` supports the following subcommands: `run`, `test`, and `setup`." - )), + _ => + show_error(format!( + "`cargo miri` supports the following subcommands: `run`, `test`, and `setup`." + )), }; let verbose = has_arg_flag("-v"); @@ -1086,8 +1087,9 @@ fn main() { )); } } - _ => show_error(format!( - "`cargo-miri` called without first argument; please only invoke this binary through `cargo miri`" - )), + _ => + show_error(format!( + "`cargo-miri` called without first argument; please only invoke this binary through `cargo miri`" + )), } } diff --git a/rustfmt.toml b/rustfmt.toml index 373caafd10..be5af7379e 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -2,3 +2,4 @@ version = "Two" use_small_heuristics = "Max" match_arm_blocks = false match_arm_leading_pipes = "Preserve" +force_multiline_blocks = true diff --git a/src/bin/miri.rs b/src/bin/miri.rs index d593f24c71..9dbd5e24ae 100644 --- a/src/bin/miri.rs +++ b/src/bin/miri.rs @@ -203,9 +203,12 @@ fn compile_time_sysroot() -> Option { let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN")); Some(match (home, toolchain) { (Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain), - _ => option_env!("RUST_SYSROOT") - .expect("To build Miri without rustup, set the `RUST_SYSROOT` env var at build time") - .to_owned(), + _ => + option_env!("RUST_SYSROOT") + .expect( + "To build Miri without rustup, set the `RUST_SYSROOT` env var at build time", + ) + .to_owned(), }) } @@ -336,9 +339,10 @@ fn main() { "warn" => miri::IsolatedOp::Reject(miri::RejectOpWith::Warning), "warn-nobacktrace" => miri::IsolatedOp::Reject(miri::RejectOpWith::WarningWithoutBacktrace), - _ => panic!( - "-Zmiri-isolation-error must be `abort`, `hide`, `warn`, or `warn-nobacktrace`" - ), + _ => + panic!( + "-Zmiri-isolation-error must be `abort`, `hide`, `warn`, or `warn-nobacktrace`" + ), }; } "-Zmiri-ignore-leaks" => { @@ -383,10 +387,11 @@ fn main() { let id: u64 = match arg.strip_prefix("-Zmiri-track-pointer-tag=").unwrap().parse() { Ok(id) => id, - Err(err) => panic!( - "-Zmiri-track-pointer-tag requires a valid `u64` argument: {}", - err - ), + Err(err) => + panic!( + "-Zmiri-track-pointer-tag requires a valid `u64` argument: {}", + err + ), }; if let Some(id) = miri::PtrId::new(id) { miri_config.tracked_pointer_tag = Some(id); @@ -422,13 +427,15 @@ fn main() { .parse::() { Ok(rate) if rate >= 0.0 && rate <= 1.0 => rate, - Ok(_) => panic!( - "-Zmiri-compare-exchange-weak-failure-rate must be between `0.0` and `1.0`" - ), - Err(err) => panic!( - "-Zmiri-compare-exchange-weak-failure-rate requires a `f64` between `0.0` and `1.0`: {}", - err - ), + Ok(_) => + panic!( + "-Zmiri-compare-exchange-weak-failure-rate must be between `0.0` and `1.0`" + ), + Err(err) => + panic!( + "-Zmiri-compare-exchange-weak-failure-rate requires a `f64` between `0.0` and `1.0`: {}", + err + ), }; miri_config.cmpxchg_weak_failure_rate = rate; } diff --git a/src/diagnostics.rs b/src/diagnostics.rs index 887b2ac4b3..4476ce237f 100644 --- a/src/diagnostics.rs +++ b/src/diagnostics.rs @@ -43,11 +43,12 @@ impl fmt::Display for TerminationInfo { Deadlock => write!(f, "the evaluated program deadlocked"), MultipleSymbolDefinitions { link_name, .. } => write!(f, "multiple definitions of symbol `{}`", link_name), - SymbolShimClashing { link_name, .. } => write!( - f, - "found `{}` symbol definition that clashes with a built-in shim", - link_name - ), + SymbolShimClashing { link_name, .. } => + write!( + f, + "found `{}` symbol definition that clashes with a built-in shim", + link_name + ), } } } diff --git a/src/helpers.rs b/src/helpers.rs index a6e66c3dbd..057684562f 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -498,10 +498,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx match err_kind { NotFound => "ERROR_FILE_NOT_FOUND", PermissionDenied => "ERROR_ACCESS_DENIED", - _ => throw_unsup_format!( - "io error {:?} cannot be translated into a raw os error", - err_kind - ), + _ => + throw_unsup_format!( + "io error {:?} cannot be translated into a raw os error", + err_kind + ), }, )? } else { diff --git a/src/shims/env.rs b/src/shims/env.rs index d99ffb31b5..59322b91d6 100644 --- a/src/shims/env.rs +++ b/src/shims/env.rs @@ -53,10 +53,11 @@ impl<'tcx> EnvVars<'tcx> { "linux" | "macos" => alloc_env_var_as_c_str(name.as_ref(), value.as_ref(), ecx)?, "windows" => alloc_env_var_as_wide_str(name.as_ref(), value.as_ref(), ecx)?, - unsupported => throw_unsup_format!( - "environment support for target OS `{}` not yet available", - unsupported - ), + unsupported => + throw_unsup_format!( + "environment support for target OS `{}` not yet available", + unsupported + ), }; ecx.machine.env_vars.map.insert(OsString::from(name), var_ptr); } diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index 2de0baf294..61dca93f0e 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -223,54 +223,56 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx // First: functions that diverge. let (dest, ret) = match ret { - None => match &*link_name.as_str() { - "miri_start_panic" => { - // `check_shim` happens inside `handle_miri_start_panic`. - this.handle_miri_start_panic(abi, link_name, args, unwind)?; - return Ok(None); - } - // This matches calls to the foreign item `panic_impl`. - // The implementation is provided by the function with the `#[panic_handler]` attribute. - "panic_impl" => { - // We don't use `check_shim` here because we are just forwarding to the lang - // item. Argument count checking will be performed when the returned `Body` is - // called. - this.check_abi_and_shim_symbol_clash(abi, Abi::Rust, link_name)?; - let panic_impl_id = tcx.lang_items().panic_impl().unwrap(); - let panic_impl_instance = ty::Instance::mono(tcx, panic_impl_id); - return Ok(Some(&*this.load_mir(panic_impl_instance.def, None)?)); - } - #[rustfmt::skip] - | "exit" - | "ExitProcess" - => { - let exp_abi = if link_name.as_str() == "exit" { - Abi::C { unwind: false } - } else { - Abi::System { unwind: false } - }; - let &[ref code] = this.check_shim(abi, exp_abi, link_name, args)?; - // it's really u32 for ExitProcess, but we have to put it into the `Exit` variant anyway - let code = this.read_scalar(code)?.to_i32()?; - throw_machine_stop!(TerminationInfo::Exit(code.into())); - } - "abort" => { - let &[] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; - throw_machine_stop!(TerminationInfo::Abort( - "the program aborted execution".to_owned() - )) - } - _ => { - if let Some(body) = this.lookup_exported_symbol(link_name)? { - return Ok(Some(body)); + None => + match &*link_name.as_str() { + "miri_start_panic" => { + // `check_shim` happens inside `handle_miri_start_panic`. + this.handle_miri_start_panic(abi, link_name, args, unwind)?; + return Ok(None); } - this.handle_unsupported(format!( - "can't call (diverging) foreign function: {}", - link_name - ))?; - return Ok(None); - } - }, + // This matches calls to the foreign item `panic_impl`. + // The implementation is provided by the function with the `#[panic_handler]` attribute. + "panic_impl" => { + // We don't use `check_shim` here because we are just forwarding to the lang + // item. Argument count checking will be performed when the returned `Body` is + // called. + this.check_abi_and_shim_symbol_clash(abi, Abi::Rust, link_name)?; + let panic_impl_id = tcx.lang_items().panic_impl().unwrap(); + let panic_impl_instance = ty::Instance::mono(tcx, panic_impl_id); + return Ok(Some(&*this.load_mir(panic_impl_instance.def, None)?)); + } + #[rustfmt::skip] + | "exit" + | "ExitProcess" + => { + let exp_abi = if link_name.as_str() == "exit" { + Abi::C { unwind: false } + } else { + Abi::System { unwind: false } + }; + let &[ref code] = this.check_shim(abi, exp_abi, link_name, args)?; + // it's really u32 for ExitProcess, but we have to put it into the `Exit` variant anyway + let code = this.read_scalar(code)?.to_i32()?; + throw_machine_stop!(TerminationInfo::Exit(code.into())); + } + "abort" => { + let &[] = + this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + throw_machine_stop!(TerminationInfo::Abort( + "the program aborted execution".to_owned() + )) + } + _ => { + if let Some(body) = this.lookup_exported_symbol(link_name)? { + return Ok(Some(body)); + } + this.handle_unsupported(format!( + "can't call (diverging) foreign function: {}", + link_name + ))?; + return Ok(None); + } + }, Some(p) => p, }; diff --git a/src/shims/intrinsics.rs b/src/shims/intrinsics.rs index c018dd8738..caef57df8d 100644 --- a/src/shims/intrinsics.rs +++ b/src/shims/intrinsics.rs @@ -295,10 +295,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx this.float_to_int_unchecked(val.to_scalar()?.to_f32()?, dest.layout.ty)?, ty::Float(FloatTy::F64) => this.float_to_int_unchecked(val.to_scalar()?.to_f64()?, dest.layout.ty)?, - _ => bug!( - "`float_to_int_unchecked` called with non-float input type {:?}", - val.layout.ty - ), + _ => + bug!( + "`float_to_int_unchecked` called with non-float input type {:?}", + val.layout.ty + ), }; this.write_scalar(res, dest)?; diff --git a/src/shims/posix/fs.rs b/src/shims/posix/fs.rs index fbef9f3040..bfc6195b3a 100644 --- a/src/shims/posix/fs.rs +++ b/src/shims/posix/fs.rs @@ -434,10 +434,11 @@ trait EvalContextExtPrivate<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, ' Err(e) => return match e.raw_os_error() { Some(error) => Ok(error), - None => throw_unsup_format!( - "the error {} couldn't be converted to a return value", - e - ), + None => + throw_unsup_format!( + "the error {} couldn't be converted to a return value", + e + ), }, } } @@ -1203,13 +1204,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx this.write_null(&this.deref_operand(result_op)?.into())?; Ok(0) } - Some(Err(e)) => match e.raw_os_error() { - // return positive error number on error - Some(error) => Ok(error), - None => { - throw_unsup_format!("the error {} couldn't be converted to a return value", e) - } - }, + Some(Err(e)) => + match e.raw_os_error() { + // return positive error number on error + Some(error) => Ok(error), + None => { + throw_unsup_format!( + "the error {} couldn't be converted to a return value", + e + ) + } + }, } } @@ -1294,13 +1299,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx this.write_null(&this.deref_operand(result_op)?.into())?; Ok(0) } - Some(Err(e)) => match e.raw_os_error() { - // return positive error number on error - Some(error) => Ok(error), - None => { - throw_unsup_format!("the error {} couldn't be converted to a return value", e) - } - }, + Some(Err(e)) => + match e.raw_os_error() { + // return positive error number on error + Some(error) => Ok(error), + None => { + throw_unsup_format!( + "the error {} couldn't be converted to a return value", + e + ) + } + }, } } diff --git a/src/stacked_borrows.rs b/src/stacked_borrows.rs index 0b92817c97..0365e9ca00 100644 --- a/src/stacked_borrows.rs +++ b/src/stacked_borrows.rs @@ -699,10 +699,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx fn qualify(ty: ty::Ty<'_>, kind: RetagKind) -> Option<(RefKind, bool)> { match ty.kind() { // References are simple. - ty::Ref(_, _, Mutability::Mut) => Some(( - RefKind::Unique { two_phase: kind == RetagKind::TwoPhase }, - kind == RetagKind::FnEntry, - )), + ty::Ref(_, _, Mutability::Mut) => + Some(( + RefKind::Unique { two_phase: kind == RetagKind::TwoPhase }, + kind == RetagKind::FnEntry, + )), ty::Ref(_, _, Mutability::Not) => Some((RefKind::Shared, kind == RetagKind::FnEntry)), // Raw pointers need to be enabled. diff --git a/src/vector_clock.rs b/src/vector_clock.rs index a2e235858d..74180f25b3 100644 --- a/src/vector_clock.rs +++ b/src/vector_clock.rs @@ -186,16 +186,18 @@ impl PartialOrd for VClock { Ordering::Equal => Some(order), // Right has at least 1 element > than the implicit 0, // so the only valid values are Ordering::Less or None. - Ordering::Less => match order { - Ordering::Less | Ordering::Equal => Some(Ordering::Less), - Ordering::Greater => None, - }, + Ordering::Less => + match order { + Ordering::Less | Ordering::Equal => Some(Ordering::Less), + Ordering::Greater => None, + }, // Left has at least 1 element > than the implicit 0, // so the only valid values are Ordering::Greater or None. - Ordering::Greater => match order { - Ordering::Greater | Ordering::Equal => Some(Ordering::Greater), - Ordering::Less => None, - }, + Ordering::Greater => + match order { + Ordering::Greater | Ordering::Equal => Some(Ordering::Greater), + Ordering::Less => None, + }, } }