Skip to content

Commit

Permalink
Adjust throw_validation_failure macro to shorten the use of `with_n…
Browse files Browse the repository at this point in the history
…o_trimmed_paths`
  • Loading branch information
lqd committed Jun 14, 2021
1 parent 19fddc0 commit 5af1c72
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions compiler/rustc_mir/src/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,22 @@ use super::{

macro_rules! throw_validation_failure {
($where:expr, { $( $what_fmt:expr ),+ } $( expected { $( $expected_fmt:expr ),+ } )?) => {{
let (path, msg) = rustc_middle::ty::print::with_no_trimmed_paths(|| {
let mut msg = String::new();
msg.push_str("encountered ");
write!(&mut msg, $($what_fmt),+).unwrap();
$(
msg.push_str(", but expected ");
write!(&mut msg, $($expected_fmt),+).unwrap();
)?

let mut msg = String::new();
msg.push_str("encountered ");
write!(&mut msg, $($what_fmt),+).unwrap();
$(
msg.push_str(", but expected ");
write!(&mut msg, $($expected_fmt),+).unwrap();
)?
let path = rustc_middle::ty::print::with_no_trimmed_paths(|| {
let where_ = &$where;
let path = if !where_.is_empty() {
if !where_.is_empty() {
let mut path = String::new();
write_path(&mut path, where_);
Some(path)
} else {
None
};

(path, msg)
}
});
throw_ub!(ValidationFailure { path, msg })
}};
Expand Down

0 comments on commit 5af1c72

Please sign in to comment.