diff options
| author | Rémy Rakic <remy.rakic+github@gmail.com> | 2021-06-13 22:40:42 +0200 |
|---|---|---|
| committer | Rémy Rakic <remy.rakic+github@gmail.com> | 2021-06-13 22:40:42 +0200 |
| commit | 87ecf84c360331a5917f6e6d29951b98d5a614ed (patch) | |
| tree | 723149fe9aeda02d093c0cb8e245beda4153bc5e /compiler/rustc_mir/src/interpret/validity.rs | |
| parent | fb3ea63d9b4c3e9bb90d4250b870faaffb9c8fd2 (diff) | |
Improve CTFE validation error message
Diffstat (limited to 'compiler/rustc_mir/src/interpret/validity.rs')
| -rw-r--r-- | compiler/rustc_mir/src/interpret/validity.rs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/compiler/rustc_mir/src/interpret/validity.rs b/compiler/rustc_mir/src/interpret/validity.rs index c9ebffe8d1c..7511890090b 100644 --- a/compiler/rustc_mir/src/interpret/validity.rs +++ b/compiler/rustc_mir/src/interpret/validity.rs @@ -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 }) }}; } |
