From fe08d9e2d270d97be5a33a2d505d4a9ea56d258a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 3 Aug 2019 20:35:52 +0200 Subject: [PATCH 1/4] also add macros for free-form error messages --- src/librustc/mir/interpret/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index 65f4c9c47d0a9..1ec95c29a4a6f 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -9,6 +9,11 @@ macro_rules! err_unsup { }; } +#[macro_export] +macro_rules! err_unsup_format { + ($($tt:tt)*) => { err_unsup!(Unsupported(format!($($tt)*))) }; +} + #[macro_export] macro_rules! err_inval { ($($tt:tt)*) => { @@ -27,6 +32,11 @@ macro_rules! err_ub { }; } +#[macro_export] +macro_rules! err_ub_format { + ($($tt:tt)*) => { err_ub!(Ub(format!($($tt)*))) }; +} + #[macro_export] macro_rules! err_panic { ($($tt:tt)*) => { From 89a370db0f6caef02b34cd42a151ef21613a8b44 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 3 Aug 2019 20:36:05 +0200 Subject: [PATCH 2/4] add variant for experimental UB (like Stacked Borrows) --- src/librustc/mir/interpret/error.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index 6a8cd9b46ae4a..5d60108f37c1d 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -342,8 +342,10 @@ impl fmt::Debug for InvalidProgramInfo<'tcx> { #[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] pub enum UndefinedBehaviorInfo { - /// Handle cases which for which we do not have a fixed variant. + /// Free-form case. Only for errors that are never caught! Ub(String), + /// Free-form case for experimental UB. Only for errors that are never caught! + UbExperimental(String), /// Unreachable code was executed. Unreachable, } @@ -352,7 +354,7 @@ impl fmt::Debug for UndefinedBehaviorInfo { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { use UndefinedBehaviorInfo::*; match self { - Ub(ref msg) => + Ub(msg) | UbExperimental(msg) => write!(f, "{}", msg), Unreachable => write!(f, "entered unreachable code"), @@ -362,7 +364,7 @@ impl fmt::Debug for UndefinedBehaviorInfo { #[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] pub enum UnsupportedOpInfo<'tcx> { - /// Handle cases which for which we do not have a fixed variant. + /// Free-form case. Only for errors that are never caught! Unsupported(String), // -- Everything below is not classified yet -- From 18daa766f058217e0b2f53d34e02c8a64b341141 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 4 Aug 2019 11:21:41 +0200 Subject: [PATCH 3/4] move AssumptionNotHeld to UB --- src/librustc/mir/interpret/error.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index 5d60108f37c1d..f1baebd34a40c 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -348,6 +348,8 @@ pub enum UndefinedBehaviorInfo { UbExperimental(String), /// Unreachable code was executed. Unreachable, + /// An `assume` was run on a `false` condition, + AssumptionNotHeld, } impl fmt::Debug for UndefinedBehaviorInfo { @@ -358,6 +360,8 @@ impl fmt::Debug for UndefinedBehaviorInfo { write!(f, "{}", msg), Unreachable => write!(f, "entered unreachable code"), + AssumptionNotHeld => + write!(f, "`assume` argument was false"), } } } @@ -408,7 +412,6 @@ pub enum UnsupportedOpInfo<'tcx> { VtableForArgumentlessMethod, ModifiedConstantMemory, ModifiedStatic, - AssumptionNotHeld, TypeNotPrimitive(Ty<'tcx>), ReallocatedWrongMemoryKind(String, String), DeallocatedWrongMemoryKind(String, String), @@ -507,8 +510,6 @@ impl fmt::Debug for UnsupportedOpInfo<'tcx> { ModifiedStatic => write!(f, "tried to modify a static's initial value from another static's \ initializer"), - AssumptionNotHeld => - write!(f, "`assume` argument was false"), ReallocateNonBasePtr => write!(f, "tried to reallocate with a pointer not to the beginning of an \ existing object"), From b9d4c759f3022c2f7c4334ef7b727044aee03915 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 4 Aug 2019 11:59:14 +0200 Subject: [PATCH 4/4] AssumptionNotHeld is used only once in Miri and never caught... remove from enum --- src/librustc/mir/interpret/error.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index f1baebd34a40c..aa36b55ae376e 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -348,8 +348,6 @@ pub enum UndefinedBehaviorInfo { UbExperimental(String), /// Unreachable code was executed. Unreachable, - /// An `assume` was run on a `false` condition, - AssumptionNotHeld, } impl fmt::Debug for UndefinedBehaviorInfo { @@ -360,8 +358,6 @@ impl fmt::Debug for UndefinedBehaviorInfo { write!(f, "{}", msg), Unreachable => write!(f, "entered unreachable code"), - AssumptionNotHeld => - write!(f, "`assume` argument was false"), } } }