Improve CTFE validation error message
This commit is contained in:
parent
fb3ea63d9b
commit
87ecf84c36
2 changed files with 22 additions and 12 deletions
|
@ -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 })
|
||||
}};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue