From 0341b8ac846c2846fc2aa20aaabe161cb5a0bae9 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 11 Jul 2021 14:18:44 +0200 Subject: [PATCH] fmt: set force_multiline_blocks=true --- benches/helpers/miri_helper.rs | 7 +-- rustfmt.toml | 1 + src/bin/miri.rs | 41 +++++++++------ src/diagnostics.rs | 11 ++-- src/helpers.rs | 9 ++-- src/shims/env.rs | 9 ++-- src/shims/foreign_items.rs | 96 +++++++++++++++++----------------- src/shims/intrinsics.rs | 9 ++-- src/shims/posix/fs.rs | 45 +++++++++------- src/stacked_borrows.rs | 9 ++-- src/vector_clock.rs | 18 ++++--- 11 files changed, 141 insertions(+), 114 deletions(-) diff --git a/benches/helpers/miri_helper.rs b/benches/helpers/miri_helper.rs index b26705cb704..2d27616a361 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/rustfmt.toml b/rustfmt.toml index 373caafd106..be5af7379ea 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 d593f24c71a..9dbd5e24aeb 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 887b2ac4b37..4476ce237ff 100644 --- a/src/diagnostics.rs +++ b/src/diagnostics.rs @@ -43,11 +43,12 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 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 a6e66c3dbd3..057684562fd 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -498,10 +498,11 @@ fn set_last_error_from_io_error(&mut self, err_kind: std::io::ErrorKind) -> Inte 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 d99ffb31b5c..59322b91d67 100644 --- a/src/shims/env.rs +++ b/src/shims/env.rs @@ -53,10 +53,11 @@ pub(crate) fn init<'mir>( "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 2de0baf2947..61dca93f0ed 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -223,54 +223,56 @@ fn emulate_foreign_item( // 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 c018dd87381..caef57df8dd 100644 --- a/src/shims/intrinsics.rs +++ b/src/shims/intrinsics.rs @@ -295,10 +295,11 @@ fn call_intrinsic( 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 fbef9f30407..bfc6195b3af 100644 --- a/src/shims/posix/fs.rs +++ b/src/shims/posix/fs.rs @@ -434,10 +434,11 @@ fn file_type_to_d_type( 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 @@ fn linux_readdir64_r( 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 @@ fn macos_readdir_r( 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 0b92817c972..0365e9ca00e 100644 --- a/src/stacked_borrows.rs +++ b/src/stacked_borrows.rs @@ -699,10 +699,11 @@ fn retag(&mut self, kind: RetagKind, place: &PlaceTy<'tcx, Tag>) -> InterpResult 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 a2e235858d8..74180f25b3b 100644 --- a/src/vector_clock.rs +++ b/src/vector_clock.rs @@ -186,16 +186,18 @@ fn partial_cmp(&self, other: &VClock) -> Option { 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, + }, } }