1
Fork 0

Improve CTFE validation error message

This commit is contained in:
Rémy Rakic 2021-06-13 22:40:42 +02:00
parent fb3ea63d9b
commit 87ecf84c36
2 changed files with 22 additions and 12 deletions

View file

@ -26,23 +26,27 @@ use super::{
macro_rules! throw_validation_failure {
($where:expr, { $( $what_fmt:expr ),+ } $( expected { $( $expected_fmt:expr ),+ } )?) => {{
let msg = rustc_middle::ty::print::with_no_trimmed_paths(|| {
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();
let where_ = &$where;
if !where_.is_empty() {
msg.push_str(" at ");
write_path(&mut msg, where_);
}
$(
msg.push_str(", but expected ");
write!(&mut msg, $($expected_fmt),+).unwrap();
)?
msg
let where_ = &$where;
let path = if !where_.is_empty() {
let mut path = String::new();
write_path(&mut path, where_);
Some(path)
} else {
None
};
(path, msg)
});
throw_ub!(ValidationFailure(msg))
throw_ub!(ValidationFailure { path, msg })
}};
}