Adjust throw_validation_failure macro to shorten the use of with_no_trimmed_paths

This commit is contained in:
Rémy Rakic 2021-06-14 18:57:53 +02:00
parent 19fddc019f
commit 5af1c72513

View file

@ -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 })
}};