Skip to content

Commit 06b72b0

Browse files
committed
Auto merge of rust-lang#101154 - RalfJung:validation-perf, r=oli-obk
interpret: fix unnecessary allocation in validation visitor Should fix the perf regression introduced by rust-lang#100043. r? `@oli-obk`
2 parents 9208625 + 8b53abd commit 06b72b0

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;
@@ -311,7 +311,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
311311
fn read_immediate(
312312
&self,
313313
op: &OpTy<'tcx, M::Provenance>,
314-
expected: &str,
314+
expected: impl Display,
315315
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> {
316316
Ok(try_validation!(
317317
self.ecx.read_immediate(op),
@@ -323,7 +323,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
323323
fn read_scalar(
324324
&self,
325325
op: &OpTy<'tcx, M::Provenance>,
326-
expected: &str,
326+
expected: impl Display,
327327
) -> InterpResult<'tcx, Scalar<M::Provenance>> {
328328
Ok(self.read_immediate(op, expected)?.to_scalar())
329329
}
@@ -368,7 +368,8 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
368368
value: &OpTy<'tcx, M::Provenance>,
369369
kind: &str,
370370
) -> InterpResult<'tcx> {
371-
let place = self.ecx.ref_to_mplace(&self.read_immediate(value, &format!("a {kind}"))?)?;
371+
let place =
372+
self.ecx.ref_to_mplace(&self.read_immediate(value, format_args!("a {kind}"))?)?;
372373
// Handle wide pointers.
373374
// Check metadata early, for better diagnostics
374375
if place.layout.is_unsized() {

0 commit comments

Comments
 (0)