Skip to content

Commit 7d5ae09

Browse files
committed
Auto merge of #2338 - RalfJung:format, r=RalfJung
tweak format strings
2 parents 36d8f5c + 907a003 commit 7d5ae09

File tree

6 files changed

+37
-50
lines changed

6 files changed

+37
-50
lines changed

src/diagnostics.rs

+13-18
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,20 @@ impl fmt::Display for TerminationInfo {
4040
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4141
use TerminationInfo::*;
4242
match self {
43-
Exit(code) => write!(f, "the evaluated program completed with exit code {}", code),
44-
Abort(msg) => write!(f, "{}", msg),
45-
UnsupportedInIsolation(msg) => write!(f, "{}", msg),
43+
Exit(code) => write!(f, "the evaluated program completed with exit code {code}"),
44+
Abort(msg) => write!(f, "{msg}"),
45+
UnsupportedInIsolation(msg) => write!(f, "{msg}"),
4646
Int2PtrWithStrictProvenance =>
4747
write!(
4848
f,
4949
"integer-to-pointer casts and `ptr::from_exposed_addr` are not supported with `-Zmiri-strict-provenance`"
5050
),
51-
StackedBorrowsUb { msg, .. } => write!(f, "{}", msg),
51+
StackedBorrowsUb { msg, .. } => write!(f, "{msg}"),
5252
Deadlock => write!(f, "the evaluated program deadlocked"),
5353
MultipleSymbolDefinitions { link_name, .. } =>
54-
write!(f, "multiple definitions of symbol `{}`", link_name),
54+
write!(f, "multiple definitions of symbol `{link_name}`"),
5555
SymbolShimClashing { link_name, .. } =>
56-
write!(
57-
f,
58-
"found `{}` symbol definition that clashes with a built-in shim",
59-
link_name
60-
),
56+
write!(f, "found `{link_name}` symbol definition that clashes with a built-in shim",),
6157
}
6258
}
6359
}
@@ -200,11 +196,11 @@ pub fn report_error<'tcx, 'mir>(
200196
}
201197
MultipleSymbolDefinitions { first, first_crate, second, second_crate, .. } =>
202198
vec![
203-
(Some(*first), format!("it's first defined here, in crate `{}`", first_crate)),
204-
(Some(*second), format!("then it's defined here again, in crate `{}`", second_crate)),
199+
(Some(*first), format!("it's first defined here, in crate `{first_crate}`")),
200+
(Some(*second), format!("then it's defined here again, in crate `{second_crate}`")),
205201
],
206202
SymbolShimClashing { link_name, span } =>
207-
vec![(Some(*span), format!("the `{}` symbol is defined here", link_name))],
203+
vec![(Some(*span), format!("the `{link_name}` symbol is defined here"))],
208204
Int2PtrWithStrictProvenance =>
209205
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"))],
210206
_ => vec![],
@@ -227,15 +223,15 @@ pub fn report_error<'tcx, 'mir>(
227223
) =>
228224
"post-monomorphization error",
229225
kind =>
230-
bug!("This error should be impossible in Miri: {:?}", kind),
226+
bug!("This error should be impossible in Miri: {kind:?}"),
231227
};
232228
#[rustfmt::skip]
233229
let helps = match e.kind() {
234230
Unsupported(
235231
UnsupportedOpInfo::ThreadLocalStatic(_) |
236232
UnsupportedOpInfo::ReadExternStatic(_)
237233
) =>
238-
panic!("Error should never be raised by Miri: {:?}", e.kind()),
234+
panic!("Error should never be raised by Miri: {kind:?}", kind = e.kind()),
239235
Unsupported(
240236
UnsupportedOpInfo::Unsupported(_) |
241237
UnsupportedOpInfo::PartialPointerOverwrite(_) |
@@ -295,9 +291,8 @@ pub fn report_error<'tcx, 'mir>(
295291
match e.kind() {
296292
UndefinedBehavior(UndefinedBehaviorInfo::InvalidUninitBytes(Some((alloc_id, access)))) => {
297293
eprintln!(
298-
"Uninitialized read occurred at offsets 0x{:x}..0x{:x} into this allocation:",
299-
access.uninit_offset.bytes(),
300-
access.uninit_offset.bytes() + access.uninit_size.bytes(),
294+
"Uninitialized read occurred at {alloc_id:?}{range:?}, in this allocation:",
295+
range = alloc_range(access.uninit_offset, access.uninit_size),
301296
);
302297
eprintln!("{:?}", ecx.dump_alloc(*alloc_id));
303298
}

src/intptrcast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'mir, 'tcx> GlobalStateInner {
110110
ecx: &MiriEvalContext<'mir, 'tcx>,
111111
addr: u64,
112112
) -> Pointer<Option<Tag>> {
113-
trace!("Transmuting 0x{:x} to a pointer", addr);
113+
trace!("Transmuting {:#x} to a pointer", addr);
114114

115115
let provenance = if ecx.machine.allow_ptr_int_transmute {
116116
// When we allow transmutes, treat them like casts: generating a wildcard pointer.
@@ -126,7 +126,7 @@ impl<'mir, 'tcx> GlobalStateInner {
126126
ecx: &MiriEvalContext<'mir, 'tcx>,
127127
addr: u64,
128128
) -> InterpResult<'tcx, Pointer<Option<Tag>>> {
129-
trace!("Casting 0x{:x} to a pointer", addr);
129+
trace!("Casting {:#x} to a pointer", addr);
130130

131131
let global_state = ecx.machine.intptrcast.borrow();
132132

src/machine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl Provenance for Tag {
155155

156156
fn fmt(ptr: &Pointer<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
157157
let (tag, addr) = ptr.into_parts(); // address is absolute
158-
write!(f, "0x{:x}", addr.bytes())?;
158+
write!(f, "{:#x}", addr.bytes())?;
159159

160160
match tag {
161161
Tag::Concrete { alloc_id, sb } => {

src/shims/intrinsics.rs

+15-23
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
3636
let intrinsic_name = this.tcx.item_name(instance.def_id());
3737
let intrinsic_name = intrinsic_name.as_str();
3838
let ret = match ret {
39-
None => throw_unsup_format!("unimplemented (diverging) intrinsic: {}", intrinsic_name),
39+
None => throw_unsup_format!("unimplemented (diverging) intrinsic: `{intrinsic_name}`"),
4040
Some(p) => p,
4141
};
4242

@@ -86,7 +86,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
8686
// `checked_mul` enforces a too small bound (the correct one would probably be machine_isize_max),
8787
// but no actual allocation can be big enough for the difference to be noticeable.
8888
let byte_count = ty_layout.size.checked_mul(count, this).ok_or_else(|| {
89-
err_ub_format!("overflow computing total size of `{}`", intrinsic_name)
89+
err_ub_format!("overflow computing total size of `{intrinsic_name}`")
9090
})?;
9191
this.write_bytes_ptr(
9292
ptr,
@@ -200,24 +200,20 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
200200
ty::Float(FloatTy::F32) => x.to_scalar()?.to_f32()?.is_finite(),
201201
ty::Float(FloatTy::F64) => x.to_scalar()?.to_f64()?.is_finite(),
202202
_ => bug!(
203-
"`{}` called with non-float input type {:?}",
204-
intrinsic_name,
205-
x.layout.ty
203+
"`{intrinsic_name}` called with non-float input type {ty:?}",
204+
ty = x.layout.ty,
206205
),
207206
})
208207
};
209208
match (float_finite(a)?, float_finite(b)?) {
210209
(false, false) => throw_ub_format!(
211-
"`{}` intrinsic called with non-finite value as both parameters",
212-
intrinsic_name,
210+
"`{intrinsic_name}` intrinsic called with non-finite value as both parameters",
213211
),
214212
(false, _) => throw_ub_format!(
215-
"`{}` intrinsic called with non-finite value as first parameter",
216-
intrinsic_name,
213+
"`{intrinsic_name}` intrinsic called with non-finite value as first parameter",
217214
),
218215
(_, false) => throw_ub_format!(
219-
"`{}` intrinsic called with non-finite value as second parameter",
220-
intrinsic_name,
216+
"`{intrinsic_name}` intrinsic called with non-finite value as second parameter",
221217
),
222218
_ => {}
223219
}
@@ -494,7 +490,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
494490
// See <https://github.com/rust-lang/rust/issues/91237>.
495491
if overflowed {
496492
let r_val = right.to_scalar()?.to_bits(right.layout.size)?;
497-
throw_ub_format!("overflowing shift by {} in `{}` in SIMD lane {}", r_val, intrinsic_name, i);
493+
throw_ub_format!("overflowing shift by {r_val} in `{intrinsic_name}` in SIMD lane {i}");
498494
}
499495
}
500496
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
751747
this.float_to_int_unchecked(op.to_scalar()?.to_f64()?, dest.layout.ty)?.into(),
752748
_ =>
753749
throw_unsup_format!(
754-
"Unsupported SIMD cast from element type {} to {}",
755-
op.layout.ty,
756-
dest.layout.ty
750+
"Unsupported SIMD cast from element type {from_ty} to {to_ty}",
751+
from_ty = op.layout.ty,
752+
to_ty = dest.layout.ty,
757753
),
758754
};
759755
this.write_immediate(val, &dest.into())?;
@@ -1093,7 +1089,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
10931089
throw_machine_stop!(TerminationInfo::Abort("Trace/breakpoint trap".to_string()))
10941090
}
10951091

1096-
name => throw_unsup_format!("unimplemented intrinsic: {}", name),
1092+
name => throw_unsup_format!("unimplemented intrinsic: `{name}`"),
10971093
}
10981094

10991095
trace!("{:?}", this.dump_place(**dest));
@@ -1340,9 +1336,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
13401336
} else {
13411337
// `f` was not representable in this integer type.
13421338
throw_ub_format!(
1343-
"`float_to_int_unchecked` intrinsic called on {} which cannot be represented in target type `{:?}`",
1344-
f,
1345-
dest_ty,
1339+
"`float_to_int_unchecked` intrinsic called on {f} which cannot be represented in target type `{dest_ty:?}`",
13461340
);
13471341
}
13481342
}
@@ -1356,14 +1350,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
13561350
} else {
13571351
// `f` was not representable in this integer type.
13581352
throw_ub_format!(
1359-
"`float_to_int_unchecked` intrinsic called on {} which cannot be represented in target type `{:?}`",
1360-
f,
1361-
dest_ty,
1353+
"`float_to_int_unchecked` intrinsic called on {f} which cannot be represented in target type `{dest_ty:?}`",
13621354
);
13631355
}
13641356
}
13651357
// Nothing else
1366-
_ => bug!("`float_to_int_unchecked` called with non-int output type {:?}", dest_ty),
1358+
_ => bug!("`float_to_int_unchecked` called with non-int output type {dest_ty:?}"),
13671359
})
13681360
}
13691361
}

src/stacked_borrows/diagnostics.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ impl AllocHistory {
140140
stack: &Stack,
141141
) -> InterpError<'tcx> {
142142
let action = format!(
143-
"trying to reborrow {derived_from:?} for {:?} permission at {alloc_id:?}[{:#x}]",
144-
new.perm,
145-
error_offset.bytes(),
143+
"trying to reborrow {derived_from:?} for {new_perm:?} permission at {alloc_id:?}[{offset:#x}]",
144+
new_perm = new.perm,
145+
offset = error_offset.bytes(),
146146
);
147147
err_sb_ub(
148148
format!("{}{}", action, error_cause(stack, derived_from)),
@@ -162,8 +162,8 @@ impl AllocHistory {
162162
stack: &Stack,
163163
) -> InterpError<'tcx> {
164164
let action = format!(
165-
"attempting a {access} using {tag:?} at {alloc_id:?}[{:#x}]",
166-
error_offset.bytes(),
165+
"attempting a {access} using {tag:?} at {alloc_id:?}[{offset:#x}]",
166+
offset = error_offset.bytes(),
167167
);
168168
err_sb_ub(
169169
format!("{}{}", action, error_cause(stack, tag)),

tests/fail/uninit_buffer.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LL | drop(slice1.cmp(slice2));
1717

1818
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1919

20-
Uninitialized read occurred at offsets 0x4..0x10 into this allocation:
20+
Uninitialized read occurred at ALLOC[0x4..0x10], in this allocation:
2121
ALLOC (Rust heap, size: 32, align: 8) {
2222
0x00 │ 41 42 43 44 __ __ __ __ __ __ __ __ __ __ __ __ │ ABCD░░░░░░░░░░░░
2323
0x10 │ 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ │ .░░░░░░░░░░░░░░░

0 commit comments

Comments
 (0)