Skip to content

Commit 8b53abd

Browse files
committed
interpret: fix unnecessary allocation in validation visitor
1 parent 7a42ca9 commit 8b53abd

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

compiler/rustc_const_eval/src/interpret/validity.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! to be const-safe.
66
77
use std::convert::TryFrom;
8-
use std::fmt::Write;
8+
use std::fmt::{Display, Write};
99
use std::num::NonZeroUsize;
1010

1111
use rustc_ast::Mutability;
@@ -308,7 +308,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
308308
fn read_immediate(
309309
&self,
310310
op: &OpTy<'tcx, M::Provenance>,
311-
expected: &str,
311+
expected: impl Display,
312312
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> {
313313
Ok(try_validation!(
314314
self.ecx.read_immediate(op),
@@ -321,7 +321,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
321321
fn read_scalar(
322322
&self,
323323
op: &OpTy<'tcx, M::Provenance>,
324-
expected: &str,
324+
expected: impl Display,
325325
) -> InterpResult<'tcx, Scalar<M::Provenance>> {
326326
Ok(self.read_immediate(op, expected)?.to_scalar())
327327
}
@@ -370,7 +370,8 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
370370
value: &OpTy<'tcx, M::Provenance>,
371371
kind: &str,
372372
) -> InterpResult<'tcx> {
373-
let place = self.ecx.ref_to_mplace(&self.read_immediate(value, &format!("a {kind}"))?)?;
373+
let place =
374+
self.ecx.ref_to_mplace(&self.read_immediate(value, format_args!("a {kind}"))?)?;
374375
// Handle wide pointers.
375376
// Check metadata early, for better diagnostics
376377
if place.layout.is_unsized() {

0 commit comments

Comments
 (0)