]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #101154 - RalfJung:validation-perf, r=oli-obk
authorbors <bors@rust-lang.org>
Sat, 3 Sep 2022 09:20:54 +0000 (09:20 +0000)
committerbors <bors@rust-lang.org>
Sat, 3 Sep 2022 09:20:54 +0000 (09:20 +0000)
interpret: fix unnecessary allocation in validation visitor

Should fix the perf regression introduced by https://github.com/rust-lang/rust/pull/100043.

r? `@oli-obk`

compiler/rustc_const_eval/src/interpret/validity.rs

index 0382e2d5805aacb10148c56487e9694aa609a0bc..14aaee6ac3f9ea1168dccb5c502aa6e90dc0c0b0 100644 (file)
@@ -5,7 +5,7 @@
 //! to be const-safe.
 
 use std::convert::TryFrom;
-use std::fmt::Write;
+use std::fmt::{Display, Write};
 use std::num::NonZeroUsize;
 
 use rustc_ast::Mutability;
@@ -311,7 +311,7 @@ fn with_elem<R>(
     fn read_immediate(
         &self,
         op: &OpTy<'tcx, M::Provenance>,
-        expected: &str,
+        expected: impl Display,
     ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> {
         Ok(try_validation!(
             self.ecx.read_immediate(op),
@@ -323,7 +323,7 @@ fn read_immediate(
     fn read_scalar(
         &self,
         op: &OpTy<'tcx, M::Provenance>,
-        expected: &str,
+        expected: impl Display,
     ) -> InterpResult<'tcx, Scalar<M::Provenance>> {
         Ok(self.read_immediate(op, expected)?.to_scalar())
     }
@@ -368,7 +368,8 @@ fn check_safe_pointer(
         value: &OpTy<'tcx, M::Provenance>,
         kind: &str,
     ) -> InterpResult<'tcx> {
-        let place = self.ecx.ref_to_mplace(&self.read_immediate(value, &format!("a {kind}"))?)?;
+        let place =
+            self.ecx.ref_to_mplace(&self.read_immediate(value, format_args!("a {kind}"))?)?;
         // Handle wide pointers.
         // Check metadata early, for better diagnostics
         if place.layout.is_unsized() {