Skip to content

Commit 16f607f

Browse files
authored
Rollup merge of #70138 - RalfJung:throw-not-return, r=oli-obk
do not 'return' in 'throw_' macros In #69839 we turned a closure into a `try` block, but it turns out that does not work with our `throw_` macros, which `return` so they skip the `try`. Here we fix that. For some reason that means we also have to remove some `;`. r? @oli-obk
2 parents 569272a + e46b3c2 commit 16f607f

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

src/librustc/mir/interpret/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ macro_rules! err_exhaust {
4646
};
4747
}
4848

49+
// In the `throw_*` macros, avoid `return` to make them work with `try {}`.
4950
#[macro_export]
5051
macro_rules! throw_unsup {
51-
($($tt:tt)*) => { return Err(err_unsup!($($tt)*).into()) };
52+
($($tt:tt)*) => { Err::<!, _>(err_unsup!($($tt)*))? };
5253
}
5354

5455
#[macro_export]
@@ -58,12 +59,12 @@ macro_rules! throw_unsup_format {
5859

5960
#[macro_export]
6061
macro_rules! throw_inval {
61-
($($tt:tt)*) => { return Err(err_inval!($($tt)*).into()) };
62+
($($tt:tt)*) => { Err::<!, _>(err_inval!($($tt)*))? };
6263
}
6364

6465
#[macro_export]
6566
macro_rules! throw_ub {
66-
($($tt:tt)*) => { return Err(err_ub!($($tt)*).into()) };
67+
($($tt:tt)*) => { Err::<!, _>(err_ub!($($tt)*))? };
6768
}
6869

6970
#[macro_export]
@@ -73,13 +74,13 @@ macro_rules! throw_ub_format {
7374

7475
#[macro_export]
7576
macro_rules! throw_exhaust {
76-
($($tt:tt)*) => { return Err(err_exhaust!($($tt)*).into()) };
77+
($($tt:tt)*) => { Err::<!, _>(err_exhaust!($($tt)*))? };
7778
}
7879

7980
#[macro_export]
8081
macro_rules! throw_machine_stop {
8182
($($tt:tt)*) => {
82-
return Err($crate::mir::interpret::InterpError::MachineStop(Box::new($($tt)*)).into())
83+
Err::<!, _>($crate::mir::interpret::InterpError::MachineStop(Box::new($($tt)*)))?
8384
};
8485
}
8586

src/librustc_mir/interpret/machine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
171171

172172
/// Called to evaluate `Abort` MIR terminator.
173173
fn abort(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx, !> {
174-
throw_unsup_format!("aborting execution is not supported");
174+
throw_unsup_format!("aborting execution is not supported")
175175
}
176176

177177
/// Called for all binary operations where the LHS has pointer type.

src/librustc_mir/transform/const_prop.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -192,19 +192,19 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
192192
_ret: Option<(PlaceTy<'tcx>, BasicBlock)>,
193193
_unwind: Option<BasicBlock>,
194194
) -> InterpResult<'tcx> {
195-
throw_unsup!(ConstPropUnsupported("calling intrinsics isn't supported in ConstProp"));
195+
throw_unsup!(ConstPropUnsupported("calling intrinsics isn't supported in ConstProp"))
196196
}
197197

198198
fn assert_panic(
199199
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
200200
_msg: &rustc::mir::AssertMessage<'tcx>,
201201
_unwind: Option<rustc::mir::BasicBlock>,
202202
) -> InterpResult<'tcx> {
203-
bug!("panics terminators are not evaluated in ConstProp");
203+
bug!("panics terminators are not evaluated in ConstProp")
204204
}
205205

206206
fn ptr_to_int(_mem: &Memory<'mir, 'tcx, Self>, _ptr: Pointer) -> InterpResult<'tcx, u64> {
207-
throw_unsup!(ConstPropUnsupported("ptr-to-int casts aren't supported in ConstProp"));
207+
throw_unsup!(ConstPropUnsupported("ptr-to-int casts aren't supported in ConstProp"))
208208
}
209209

210210
fn binary_ptr_op(
@@ -217,7 +217,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
217217
throw_unsup!(ConstPropUnsupported(
218218
"pointer arithmetic or comparisons aren't supported \
219219
in ConstProp"
220-
));
220+
))
221221
}
222222

223223
#[inline(always)]
@@ -240,7 +240,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
240240
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
241241
_dest: PlaceTy<'tcx>,
242242
) -> InterpResult<'tcx> {
243-
throw_unsup!(ConstPropUnsupported("can't const prop `box` keyword"));
243+
throw_unsup!(ConstPropUnsupported("can't const prop `box` keyword"))
244244
}
245245

246246
fn access_local(

0 commit comments

Comments
 (0)