Skip to content
Permalink
Browse files

avoid more intermediate allocations in validation errors

  • Loading branch information
RalfJung committed Dec 12, 2019
1 parent 3ddc027 commit 14b2436993461c3c703baab29a9d9579bea461fc
Showing with 16 additions and 23 deletions.
  1. +16 −23 src/librustc_mir/interpret/validity.rs
@@ -22,28 +22,23 @@ use super::{

macro_rules! throw_validation_failure {
($what:expr, $where:expr, $details:expr) => {{
let where_ = path_format(&$where);
let where_ = if where_.is_empty() {
String::new()
} else {
format!(" at {}", where_)
};
throw_unsup!(ValidationFailure(format!(
"encountered {}{}, but expected {}",
$what, where_, $details,
)))
let mut msg = format!("encountered {}", $what);
let where_ = &$where;
if !where_.is_empty() {
msg.push_str(" at ");
write_path(&mut msg, where_);
}
write!(&mut msg, ", but expected {}", $details).unwrap();
throw_unsup!(ValidationFailure(msg))
}};
($what:expr, $where:expr) => {{
let where_ = path_format(&$where);
let where_ = if where_.is_empty() {
String::new()
} else {
format!(" at {}", where_)
};
throw_unsup!(ValidationFailure(format!(
"encountered {}{}",
$what, where_,
)))
let mut msg = format!("encountered {}", $what);
let where_ = &$where;
if !where_.is_empty() {
msg.push_str(" at ");
write_path(&mut msg, where_);
}
throw_unsup!(ValidationFailure(msg))
}};
}

@@ -113,10 +108,9 @@ impl<T: Copy + Eq + Hash + std::fmt::Debug, PATH: Default> RefTracking<T, PATH>
}

/// Format a path
fn path_format(path: &Vec<PathElem>) -> String {
fn write_path(out: &mut String, path: &Vec<PathElem>) {
use self::PathElem::*;

let mut out = String::new();
for elem in path.iter() {
match elem {
Field(name) => write!(out, ".{}", name),
@@ -135,7 +129,6 @@ fn path_format(path: &Vec<PathElem>) -> String {
DynDowncast => write!(out, ".<dyn-downcast>"),
}.unwrap()
}
out
}

// Test if a range that wraps at overflow contains `test`

0 comments on commit 14b2436

Please sign in to comment.
You can’t perform that action at this time.