Skip to content

Commit 0c4513e

Browse files
committed
code review fixes
1 parent c17d11f commit 0c4513e

File tree

3 files changed

+43
-40
lines changed

3 files changed

+43
-40
lines changed

src/librustc/mir/interpret/mod.rs

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,14 @@
11
//! An interpreter for MIR used in CTFE and by miri
22
33
#[macro_export]
4-
macro_rules! throw_unsup {
5-
($($tt:tt)*) => { return Err(err_unsup!($($tt)*).into()) };
6-
}
7-
8-
#[macro_export]
9-
macro_rules! throw_inval {
10-
($($tt:tt)*) => { return Err(err_inval!($($tt)*).into()) };
11-
}
12-
13-
#[macro_export]
14-
macro_rules! throw_ub {
4+
macro_rules! err_unsup {
155
($($tt:tt)*) => {
16-
return Err($crate::mir::interpret::InterpError::UndefinedBehaviour(
17-
$crate::mir::interpret::UndefinedBehaviourInfo::$($tt)*
18-
).into())
6+
$crate::mir::interpret::InterpError::Unsupported(
7+
$crate::mir::interpret::UnsupportedOpInfo::$($tt)*
8+
)
199
};
2010
}
2111

22-
#[macro_export]
23-
macro_rules! throw_panic {
24-
($($tt:tt)*) => { return Err(err_panic!($($tt)*).into()) };
25-
}
26-
27-
#[macro_export]
28-
macro_rules! throw_exhaust {
29-
($($tt:tt)*) => { return Err(err_exhaust!($($tt)*).into()) };
30-
}
31-
3212
#[macro_export]
3313
macro_rules! err_inval {
3414
($($tt:tt)*) => {
@@ -39,10 +19,19 @@ macro_rules! err_inval {
3919
}
4020

4121
#[macro_export]
42-
macro_rules! err_unsup {
22+
macro_rules! err_ub {
4323
($($tt:tt)*) => {
44-
$crate::mir::interpret::InterpError::Unsupported(
45-
$crate::mir::interpret::UnsupportedOpInfo::$($tt)*
24+
$crate::mir::interpret::InterpError::UndefinedBehaviour(
25+
$crate::mir::interpret::UndefinedBehaviourInfo::$($tt)*
26+
)
27+
};
28+
}
29+
30+
#[macro_export]
31+
macro_rules! err_panic {
32+
($($tt:tt)*) => {
33+
$crate::mir::interpret::InterpError::Panic(
34+
$crate::mir::interpret::PanicInfo::$($tt)*
4635
)
4736
};
4837
}
@@ -57,14 +46,34 @@ macro_rules! err_exhaust {
5746
}
5847

5948
#[macro_export]
60-
macro_rules! err_panic {
49+
macro_rules! throw_unsup {
50+
($($tt:tt)*) => { return Err(err_unsup!($($tt)*).into()) };
51+
}
52+
53+
#[macro_export]
54+
macro_rules! throw_inval {
55+
($($tt:tt)*) => { return Err(err_inval!($($tt)*).into()) };
56+
}
57+
58+
#[macro_export]
59+
macro_rules! throw_ub {
6160
($($tt:tt)*) => {
62-
$crate::mir::interpret::InterpError::Panic(
63-
$crate::mir::interpret::PanicInfo::$($tt)*
64-
)
61+
return Err($crate::mir::interpret::InterpError::UndefinedBehaviour(
62+
$crate::mir::interpret::UndefinedBehaviourInfo::$($tt)*
63+
).into())
6564
};
6665
}
6766

67+
#[macro_export]
68+
macro_rules! throw_panic {
69+
($($tt:tt)*) => { return Err(err_panic!($($tt)*).into()) };
70+
}
71+
72+
#[macro_export]
73+
macro_rules! throw_exhaust {
74+
($($tt:tt)*) => { return Err(err_exhaust!($($tt)*).into()) };
75+
}
76+
6877
mod error;
6978
mod value;
7079
mod allocation;

src/librustc_mir/interpret/eval_context.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf for InterpCx<'mir, 'tcx, M> {
191191
fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
192192
self.tcx
193193
.layout_of(self.param_env.and(ty))
194-
.map_err(|layout| {
195-
err_inval!(Layout(layout)).into()
196-
})
194+
.map_err(|layout| err_inval!(Layout(layout)).into())
197195
}
198196
}
199197

src/librustc_mir/transform/const_prop.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,19 +259,15 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
259259
use rustc::mir::interpret::InterpError::*;
260260
match diagnostic.error {
261261
Exit(_) => bug!("the CTFE program cannot exit"),
262-
| Unsupported(_) => {},
263-
| UndefinedBehaviour(_) => {},
264-
| InvalidProgram(_) => {},
265-
| ResourceExhaustion(_) => {},
266-
| Panic(_)
267-
=> {
262+
Panic(_) => {
268263
diagnostic.report_as_lint(
269264
self.ecx.tcx,
270265
"this expression will panic at runtime",
271266
lint_root,
272267
None,
273268
);
274269
}
270+
_ => {},
275271
}
276272
None
277273
},

0 commit comments

Comments
 (0)