From 907a003f14cb34e8b429f23bfb86a4a33634ea68 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 6 Jul 2022 09:47:48 -0400 Subject: [PATCH] tweak format strings --- src/diagnostics.rs | 31 ++++++++++-------------- src/intptrcast.rs | 4 ++-- src/machine.rs | 2 +- src/shims/intrinsics.rs | 38 ++++++++++++------------------ src/stacked_borrows/diagnostics.rs | 10 ++++---- tests/fail/uninit_buffer.stderr | 2 +- 6 files changed, 37 insertions(+), 50 deletions(-) diff --git a/src/diagnostics.rs b/src/diagnostics.rs index 11b5a21b2af8..289c46a5d2ef 100644 --- a/src/diagnostics.rs +++ b/src/diagnostics.rs @@ -40,24 +40,20 @@ impl fmt::Display for TerminationInfo { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { use TerminationInfo::*; match self { - Exit(code) => write!(f, "the evaluated program completed with exit code {}", code), - Abort(msg) => write!(f, "{}", msg), - UnsupportedInIsolation(msg) => write!(f, "{}", msg), + Exit(code) => write!(f, "the evaluated program completed with exit code {code}"), + Abort(msg) => write!(f, "{msg}"), + UnsupportedInIsolation(msg) => write!(f, "{msg}"), Int2PtrWithStrictProvenance => write!( f, "integer-to-pointer casts and `ptr::from_exposed_addr` are not supported with `-Zmiri-strict-provenance`" ), - StackedBorrowsUb { msg, .. } => write!(f, "{}", msg), + StackedBorrowsUb { msg, .. } => write!(f, "{msg}"), Deadlock => write!(f, "the evaluated program deadlocked"), MultipleSymbolDefinitions { link_name, .. } => - write!(f, "multiple definitions of symbol `{}`", 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 - ), + write!(f, "found `{link_name}` symbol definition that clashes with a built-in shim",), } } } @@ -200,11 +196,11 @@ pub fn report_error<'tcx, 'mir>( } MultipleSymbolDefinitions { first, first_crate, second, second_crate, .. } => vec![ - (Some(*first), format!("it's first defined here, in crate `{}`", first_crate)), - (Some(*second), format!("then it's defined here again, in crate `{}`", second_crate)), + (Some(*first), format!("it's first defined here, in crate `{first_crate}`")), + (Some(*second), format!("then it's defined here again, in crate `{second_crate}`")), ], SymbolShimClashing { link_name, span } => - vec![(Some(*span), format!("the `{}` symbol is defined here", link_name))], + vec![(Some(*span), format!("the `{link_name}` symbol is defined here"))], Int2PtrWithStrictProvenance => vec![(None, format!("use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead"))], _ => vec![], @@ -227,7 +223,7 @@ pub fn report_error<'tcx, 'mir>( ) => "post-monomorphization error", kind => - bug!("This error should be impossible in Miri: {:?}", kind), + bug!("This error should be impossible in Miri: {kind:?}"), }; #[rustfmt::skip] let helps = match e.kind() { @@ -235,7 +231,7 @@ pub fn report_error<'tcx, 'mir>( UnsupportedOpInfo::ThreadLocalStatic(_) | UnsupportedOpInfo::ReadExternStatic(_) ) => - panic!("Error should never be raised by Miri: {:?}", e.kind()), + panic!("Error should never be raised by Miri: {kind:?}", kind = e.kind()), Unsupported( UnsupportedOpInfo::Unsupported(_) | UnsupportedOpInfo::PartialPointerOverwrite(_) | @@ -295,9 +291,8 @@ pub fn report_error<'tcx, 'mir>( match e.kind() { UndefinedBehavior(UndefinedBehaviorInfo::InvalidUninitBytes(Some((alloc_id, access)))) => { eprintln!( - "Uninitialized read occurred at offsets 0x{:x}..0x{:x} into this allocation:", - access.uninit_offset.bytes(), - access.uninit_offset.bytes() + access.uninit_size.bytes(), + "Uninitialized read occurred at {alloc_id:?}{range:?}, in this allocation:", + range = alloc_range(access.uninit_offset, access.uninit_size), ); eprintln!("{:?}", ecx.dump_alloc(*alloc_id)); } diff --git a/src/intptrcast.rs b/src/intptrcast.rs index 5a33ada45044..e569960f68fb 100644 --- a/src/intptrcast.rs +++ b/src/intptrcast.rs @@ -110,7 +110,7 @@ impl<'mir, 'tcx> GlobalStateInner { ecx: &MiriEvalContext<'mir, 'tcx>, addr: u64, ) -> Pointer> { - trace!("Transmuting 0x{:x} to a pointer", addr); + trace!("Transmuting {:#x} to a pointer", addr); let provenance = if ecx.machine.allow_ptr_int_transmute { // When we allow transmutes, treat them like casts: generating a wildcard pointer. @@ -126,7 +126,7 @@ impl<'mir, 'tcx> GlobalStateInner { ecx: &MiriEvalContext<'mir, 'tcx>, addr: u64, ) -> InterpResult<'tcx, Pointer>> { - trace!("Casting 0x{:x} to a pointer", addr); + trace!("Casting {:#x} to a pointer", addr); let global_state = ecx.machine.intptrcast.borrow(); diff --git a/src/machine.rs b/src/machine.rs index 18b9a074c7c3..029c32cad917 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -155,7 +155,7 @@ impl Provenance for Tag { fn fmt(ptr: &Pointer, f: &mut fmt::Formatter<'_>) -> fmt::Result { let (tag, addr) = ptr.into_parts(); // address is absolute - write!(f, "0x{:x}", addr.bytes())?; + write!(f, "{:#x}", addr.bytes())?; match tag { Tag::Concrete { alloc_id, sb } => { diff --git a/src/shims/intrinsics.rs b/src/shims/intrinsics.rs index d8f6292e9df3..652f5c94cb37 100644 --- a/src/shims/intrinsics.rs +++ b/src/shims/intrinsics.rs @@ -36,7 +36,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let intrinsic_name = this.tcx.item_name(instance.def_id()); let intrinsic_name = intrinsic_name.as_str(); let ret = match ret { - None => throw_unsup_format!("unimplemented (diverging) intrinsic: {}", intrinsic_name), + None => throw_unsup_format!("unimplemented (diverging) intrinsic: `{intrinsic_name}`"), Some(p) => p, }; @@ -86,7 +86,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx // `checked_mul` enforces a too small bound (the correct one would probably be machine_isize_max), // but no actual allocation can be big enough for the difference to be noticeable. let byte_count = ty_layout.size.checked_mul(count, this).ok_or_else(|| { - err_ub_format!("overflow computing total size of `{}`", intrinsic_name) + err_ub_format!("overflow computing total size of `{intrinsic_name}`") })?; this.write_bytes_ptr( ptr, @@ -200,24 +200,20 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx ty::Float(FloatTy::F32) => x.to_scalar()?.to_f32()?.is_finite(), ty::Float(FloatTy::F64) => x.to_scalar()?.to_f64()?.is_finite(), _ => bug!( - "`{}` called with non-float input type {:?}", - intrinsic_name, - x.layout.ty + "`{intrinsic_name}` called with non-float input type {ty:?}", + ty = x.layout.ty, ), }) }; match (float_finite(a)?, float_finite(b)?) { (false, false) => throw_ub_format!( - "`{}` intrinsic called with non-finite value as both parameters", - intrinsic_name, + "`{intrinsic_name}` intrinsic called with non-finite value as both parameters", ), (false, _) => throw_ub_format!( - "`{}` intrinsic called with non-finite value as first parameter", - intrinsic_name, + "`{intrinsic_name}` intrinsic called with non-finite value as first parameter", ), (_, false) => throw_ub_format!( - "`{}` intrinsic called with non-finite value as second parameter", - intrinsic_name, + "`{intrinsic_name}` intrinsic called with non-finite value as second parameter", ), _ => {} } @@ -494,7 +490,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx // See . if overflowed { let r_val = right.to_scalar()?.to_bits(right.layout.size)?; - throw_ub_format!("overflowing shift by {} in `{}` in SIMD lane {}", r_val, intrinsic_name, i); + throw_ub_format!("overflowing shift by {r_val} in `{intrinsic_name}` in SIMD lane {i}"); } } if matches!(mir_op, BinOp::Eq | BinOp::Ne | BinOp::Lt | BinOp::Le | BinOp::Gt | BinOp::Ge) { @@ -751,9 +747,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx this.float_to_int_unchecked(op.to_scalar()?.to_f64()?, dest.layout.ty)?.into(), _ => throw_unsup_format!( - "Unsupported SIMD cast from element type {} to {}", - op.layout.ty, - dest.layout.ty + "Unsupported SIMD cast from element type {from_ty} to {to_ty}", + from_ty = op.layout.ty, + to_ty = dest.layout.ty, ), }; this.write_immediate(val, &dest.into())?; @@ -1093,7 +1089,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx throw_machine_stop!(TerminationInfo::Abort("Trace/breakpoint trap".to_string())) } - name => throw_unsup_format!("unimplemented intrinsic: {}", name), + name => throw_unsup_format!("unimplemented intrinsic: `{name}`"), } trace!("{:?}", this.dump_place(**dest)); @@ -1340,9 +1336,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx } else { // `f` was not representable in this integer type. throw_ub_format!( - "`float_to_int_unchecked` intrinsic called on {} which cannot be represented in target type `{:?}`", - f, - dest_ty, + "`float_to_int_unchecked` intrinsic called on {f} which cannot be represented in target type `{dest_ty:?}`", ); } } @@ -1356,14 +1350,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx } else { // `f` was not representable in this integer type. throw_ub_format!( - "`float_to_int_unchecked` intrinsic called on {} which cannot be represented in target type `{:?}`", - f, - dest_ty, + "`float_to_int_unchecked` intrinsic called on {f} which cannot be represented in target type `{dest_ty:?}`", ); } } // Nothing else - _ => bug!("`float_to_int_unchecked` called with non-int output type {:?}", dest_ty), + _ => bug!("`float_to_int_unchecked` called with non-int output type {dest_ty:?}"), }) } } diff --git a/src/stacked_borrows/diagnostics.rs b/src/stacked_borrows/diagnostics.rs index cee643fdf821..d787865c4e2d 100644 --- a/src/stacked_borrows/diagnostics.rs +++ b/src/stacked_borrows/diagnostics.rs @@ -140,9 +140,9 @@ impl AllocHistory { stack: &Stack, ) -> InterpError<'tcx> { let action = format!( - "trying to reborrow {derived_from:?} for {:?} permission at {alloc_id:?}[{:#x}]", - new.perm, - error_offset.bytes(), + "trying to reborrow {derived_from:?} for {new_perm:?} permission at {alloc_id:?}[{offset:#x}]", + new_perm = new.perm, + offset = error_offset.bytes(), ); err_sb_ub( format!("{}{}", action, error_cause(stack, derived_from)), @@ -162,8 +162,8 @@ impl AllocHistory { stack: &Stack, ) -> InterpError<'tcx> { let action = format!( - "attempting a {access} using {tag:?} at {alloc_id:?}[{:#x}]", - error_offset.bytes(), + "attempting a {access} using {tag:?} at {alloc_id:?}[{offset:#x}]", + offset = error_offset.bytes(), ); err_sb_ub( format!("{}{}", action, error_cause(stack, tag)), diff --git a/tests/fail/uninit_buffer.stderr b/tests/fail/uninit_buffer.stderr index e684ca8f0771..e8faf8dd8b97 100644 --- a/tests/fail/uninit_buffer.stderr +++ b/tests/fail/uninit_buffer.stderr @@ -17,7 +17,7 @@ LL | drop(slice1.cmp(slice2)); note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace -Uninitialized read occurred at offsets 0x4..0x10 into this allocation: +Uninitialized read occurred at ALLOC[0x4..0x10], in this allocation: ALLOC (Rust heap, size: 32, align: 8) { 0x00 │ 41 42 43 44 __ __ __ __ __ __ __ __ __ __ __ __ │ ABCD░░░░░░░░░░░░ 0x10 │ 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ │ .░░░░░░░░░░░░░░░