Skip to content

Commit 35417e7

Browse files
committed
renaming throw_err_* to throw_*
1 parent fc5df1d commit 35417e7

File tree

18 files changed

+112
-126
lines changed

18 files changed

+112
-126
lines changed

src/librustc/mir/interpret/allocation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
244244
Ok(&self.get_bytes(cx, ptr, size_with_null)?[..size])
245245
}
246246
// This includes the case where `offset` is out-of-bounds to begin with.
247-
None => throw_err_unsup!(UnterminatedCString(ptr.erase_tag())),
247+
None => throw_unsup!(UnterminatedCString(ptr.erase_tag())),
248248
}
249249
}
250250

@@ -446,7 +446,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
446446
if self.relocations(cx, ptr, size).is_empty() {
447447
Ok(())
448448
} else {
449-
throw_err_unsup!(ReadPointerAsBytes)
449+
throw_unsup!(ReadPointerAsBytes)
450450
}
451451
}
452452

@@ -516,7 +516,7 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
516516
self.undef_mask.is_range_defined(
517517
ptr.offset,
518518
ptr.offset + size,
519-
).or_else(|idx| throw_err_unsup!(ReadUndefBytes(idx)))
519+
).or_else(|idx| throw_unsup!(ReadUndefBytes(idx)))
520520
}
521521

522522
pub fn mark_definedness(

src/librustc/mir/interpret/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
//! An interpreter for MIR used in CTFE and by miri
22
33
#[macro_export]
4-
macro_rules! throw_err_unsup {
4+
macro_rules! throw_unsup {
55
($($tt:tt)*) => {
6-
Err($crate::mir::interpret::InterpError::Unsupported(
6+
return Err($crate::mir::interpret::InterpError::Unsupported(
77
$crate::mir::interpret::UnsupportedOpInfo::$($tt)*
88
).into())
99
};
1010
}
1111

1212
#[macro_export]
13-
macro_rules! throw_err_inval {
13+
macro_rules! throw_inval {
1414
($($tt:tt)*) => {
15-
Err($crate::mir::interpret::InterpError::InvalidProgram(
15+
return Err($crate::mir::interpret::InterpError::InvalidProgram(
1616
$crate::mir::interpret::InvalidProgramInfo::$($tt)*
1717
).into())
1818
};
1919
}
2020

2121
#[macro_export]
22-
macro_rules! throw_err_ub {
22+
macro_rules! throw_ub {
2323
($($tt:tt)*) => {
24-
Err($crate::mir::interpret::InterpError::UndefinedBehaviour(
24+
return Err($crate::mir::interpret::InterpError::UndefinedBehaviour(
2525
$crate::mir::interpret::UndefinedBehaviourInfo::$($tt)*
2626
).into())
2727
};
2828
}
2929

3030
#[macro_export]
31-
macro_rules! throw_err_panic {
31+
macro_rules! throw_panic {
3232
($($tt:tt)*) => {
33-
Err($crate::mir::interpret::InterpError::Panic(
33+
return Err($crate::mir::interpret::InterpError::Panic(
3434
$crate::mir::interpret::PanicInfo::$($tt)*
3535
).into())
3636
};
3737
}
3838

3939
#[macro_export]
40-
macro_rules! throw_err_exhaust {
40+
macro_rules! throw_exhaust {
4141
($($tt:tt)*) => {
42-
Err($crate::mir::interpret::InterpError::ResourceExhaustion(
42+
return Err($crate::mir::interpret::InterpError::ResourceExhaustion(
4343
$crate::mir::interpret::ResourceExhaustionInfo::$($tt)*
4444
).into())
4545
};

src/librustc/mir/interpret/pointer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ pub trait PointerArithmetic: layout::HasDataLayout {
7474
#[inline]
7575
fn offset<'tcx>(&self, val: u64, i: u64) -> InterpResult<'tcx, u64> {
7676
let (res, over) = self.overflowing_offset(val, i);
77-
if over { throw_err_panic!(Overflow(mir::BinOp::Add)) } else { Ok(res) }
77+
if over { throw_panic!(Overflow(mir::BinOp::Add)) } else { Ok(res) }
7878
}
7979

8080
#[inline]
8181
fn signed_offset<'tcx>(&self, val: u64, i: i64) -> InterpResult<'tcx, u64> {
8282
let (res, over) = self.overflowing_signed_offset(val, i128::from(i));
83-
if over { throw_err_panic!(Overflow(mir::BinOp::Add)) } else { Ok(res) }
83+
if over { throw_panic!(Overflow(mir::BinOp::Add)) } else { Ok(res) }
8484
}
8585
}
8686

@@ -196,7 +196,7 @@ impl<'tcx, Tag> Pointer<Tag> {
196196
msg: CheckInAllocMsg,
197197
) -> InterpResult<'tcx, ()> {
198198
if self.offset > allocation_size {
199-
throw_err_unsup!(PointerOutOfBounds { ptr: self.erase_tag(), msg, allocation_size })
199+
throw_unsup!(PointerOutOfBounds { ptr: self.erase_tag(), msg, allocation_size })
200200
} else {
201201
Ok(())
202202
}

src/librustc/mir/interpret/value.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ impl<'tcx, Tag> Scalar<Tag> {
360360
Scalar::check_data(data, size);
361361
Ok(data)
362362
}
363-
Scalar::Ptr(_) => throw_err_unsup!(ReadPointerAsBytes),
363+
Scalar::Ptr(_) => throw_unsup!(ReadPointerAsBytes),
364364
}
365365
}
366366

@@ -373,8 +373,8 @@ impl<'tcx, Tag> Scalar<Tag> {
373373
#[inline]
374374
pub fn to_ptr(self) -> InterpResult<'tcx, Pointer<Tag>> {
375375
match self {
376-
Scalar::Raw { data: 0, .. } => throw_err_unsup!(InvalidNullPointerUsage),
377-
Scalar::Raw { .. } => throw_err_unsup!(ReadBytesAsPointer),
376+
Scalar::Raw { data: 0, .. } => throw_unsup!(InvalidNullPointerUsage),
377+
Scalar::Raw { .. } => throw_unsup!(ReadBytesAsPointer),
378378
Scalar::Ptr(p) => Ok(p),
379379
}
380380
}
@@ -406,15 +406,15 @@ impl<'tcx, Tag> Scalar<Tag> {
406406
match self {
407407
Scalar::Raw { data: 0, size: 1 } => Ok(false),
408408
Scalar::Raw { data: 1, size: 1 } => Ok(true),
409-
_ => throw_err_unsup!(InvalidBool),
409+
_ => throw_unsup!(InvalidBool),
410410
}
411411
}
412412

413413
pub fn to_char(self) -> InterpResult<'tcx, char> {
414414
let val = self.to_u32()?;
415415
match ::std::char::from_u32(val) {
416416
Some(c) => Ok(c),
417-
None => throw_err_unsup!(InvalidChar(val as u128)),
417+
None => throw_unsup!(InvalidChar(val as u128)),
418418
}
419419
}
420420

@@ -537,7 +537,7 @@ impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
537537
pub fn not_undef(self) -> InterpResult<'static, Scalar<Tag>> {
538538
match self {
539539
ScalarMaybeUndef::Scalar(scalar) => Ok(scalar),
540-
ScalarMaybeUndef::Undef => throw_err_unsup!(ReadUndefBytes(Size::from_bytes(0))),
540+
ScalarMaybeUndef::Undef => throw_unsup!(ReadUndefBytes(Size::from_bytes(0))),
541541
}
542542
}
543543

src/librustc_mir/const_eval.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
352352
ecx.goto_block(ret)?; // fully evaluated and done
353353
Ok(None)
354354
} else {
355-
throw_err_unsup!(
356-
MachineError(format!("calling non-const function `{}`", instance))
357-
)
355+
throw_unsup!(MachineError(format!("calling non-const function `{}`", instance)))
358356
};
359357
}
360358
}
@@ -414,7 +412,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
414412
_tcx: TyCtxt<'tcx>,
415413
_def_id: DefId,
416414
) -> InterpResult<'tcx, Cow<'tcx, Allocation<Self::PointerTag>>> {
417-
throw_err_unsup!(ReadForeignStatic)
415+
throw_unsup!(ReadForeignStatic)
418416
}
419417

420418
#[inline(always)]

src/librustc_mir/interpret/cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
199199
},
200200

201201
// Casts to bool are not permitted by rustc, no need to handle them here.
202-
_ => throw_err_unsup!(Unimplemented(format!("int to {:?} cast", dest_layout.ty))),
202+
_ => throw_unsup!(Unimplemented(format!("int to {:?} cast", dest_layout.ty))),
203203
}
204204
}
205205

src/librustc_mir/interpret/eval_context.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub enum LocalValue<Tag=(), Id=AllocId> {
135135
impl<'tcx, Tag: Copy + 'static> LocalState<'tcx, Tag> {
136136
pub fn access(&self) -> InterpResult<'tcx, Operand<Tag>> {
137137
match self.value {
138-
LocalValue::Dead => throw_err_unsup!(DeadLocal),
138+
LocalValue::Dead => throw_unsup!(DeadLocal),
139139
LocalValue::Uninitialized =>
140140
bug!("The type checker should prevent reading from a never-written local"),
141141
LocalValue::Live(val) => Ok(val),
@@ -148,7 +148,7 @@ impl<'tcx, Tag: Copy + 'static> LocalState<'tcx, Tag> {
148148
&mut self,
149149
) -> InterpResult<'tcx, Result<&mut LocalValue<Tag>, MemPlace<Tag>>> {
150150
match self.value {
151-
LocalValue::Dead => throw_err_unsup!(DeadLocal),
151+
LocalValue::Dead => throw_unsup!(DeadLocal),
152152
LocalValue::Live(Operand::Indirect(mplace)) => Ok(Err(mplace)),
153153
ref mut local @ LocalValue::Live(Operand::Immediate(_)) |
154154
ref mut local @ LocalValue::Uninitialized => {
@@ -305,7 +305,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
305305
&substs,
306306
)),
307307
None => if substs.needs_subst() {
308-
throw_err_inval!(TooGeneric)
308+
throw_inval!(TooGeneric)
309309
} else {
310310
Ok(substs)
311311
},
@@ -339,14 +339,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
339339
&& self.tcx.has_typeck_tables(did)
340340
&& self.tcx.typeck_tables_of(did).tainted_by_errors
341341
{
342-
return throw_err_inval!(TypeckError);
342+
throw_inval!(TypeckError)
343343
}
344344
trace!("load mir {:?}", instance);
345345
match instance {
346346
ty::InstanceDef::Item(def_id) => if self.tcx.is_mir_available(did) {
347347
Ok(self.tcx.optimized_mir(did))
348348
} else {
349-
throw_err_unsup!(NoMirFor(self.tcx.def_path_str(def_id)))
349+
throw_unsup!(NoMirFor(self.tcx.def_path_str(def_id)))
350350
},
351351
_ => Ok(self.tcx.instance_mir(instance)),
352352
}
@@ -359,7 +359,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
359359
match self.stack.last() {
360360
Some(frame) => Ok(self.monomorphize_with_substs(t, frame.instance.substs)?),
361361
None => if t.needs_subst() {
362-
throw_err_inval!(TooGeneric).into()
362+
throw_inval!(TooGeneric)
363363
} else {
364364
Ok(t)
365365
},
@@ -376,7 +376,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
376376
let substituted = t.subst(*self.tcx, substs);
377377

378378
if substituted.needs_subst() {
379-
return throw_err_inval!(TooGeneric);
379+
throw_inval!(TooGeneric)
380380
}
381381

382382
Ok(self.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), substituted))
@@ -575,7 +575,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
575575
info!("ENTERING({}) {}", self.cur_frame(), self.frame().instance);
576576

577577
if self.stack.len() > self.tcx.sess.const_eval_stack_frame_limit {
578-
throw_err_exhaust!(StackFrameLimitReached)
578+
throw_exhaust!(StackFrameLimitReached)
579579
} else {
580580
Ok(())
581581
}
@@ -623,7 +623,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
623623
}
624624
} else {
625625
// Uh, that shouldn't happen... the function did not intend to return
626-
return throw_err_ub!(Unreachable);
626+
throw_ub!(Unreachable)
627627
}
628628
// Jump to new block -- *after* validation so that the spans make more sense.
629629
match frame.return_to_block {

src/librustc_mir/interpret/intern.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,7 @@ pub fn intern_const_alloc_recursive(
328328
}
329329
} else if ecx.memory().dead_alloc_map.contains_key(&alloc_id) {
330330
// dangling pointer
331-
return throw_err_unsup!(
332-
ValidationFailure("encountered dangling pointer in final constant".into())
333-
)
331+
throw_unsup!(ValidationFailure("encountered dangling pointer in final constant".into()))
334332
}
335333
}
336334
Ok(())

src/librustc_mir/interpret/intrinsics.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
104104
};
105105
let out_val = if intrinsic_name.ends_with("_nonzero") {
106106
if bits == 0 {
107-
return throw_err_unsup!(
108-
Intrinsic(format!("{} called on 0", intrinsic_name))
109-
);
107+
throw_unsup!(Intrinsic(format!("{} called on 0", intrinsic_name)))
110108
}
111109
numeric_intrinsic(intrinsic_name.trim_end_matches("_nonzero"), bits, kind)?
112110
} else {
@@ -192,9 +190,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
192190
if overflowed {
193191
let layout = self.layout_of(substs.type_at(0))?;
194192
let r_val = r.to_scalar()?.to_bits(layout.size)?;
195-
return throw_err_unsup!(Intrinsic(
196-
format!("Overflowing shift by {} in {}", r_val, intrinsic_name),
197-
));
193+
throw_unsup!(
194+
Intrinsic(format!("Overflowing shift by {} in {}", r_val, intrinsic_name))
195+
)
198196
}
199197
self.write_scalar(val, dest)?;
200198
}

src/librustc_mir/interpret/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,6 @@ pub trait Machine<'mir, 'tcx>: Sized {
251251
_mem: &Memory<'mir, 'tcx, Self>,
252252
_ptr: Pointer<Self::PointerTag>,
253253
) -> InterpResult<'tcx, u64> {
254-
throw_err_unsup!(ReadPointerAsBytes)
254+
throw_unsup!(ReadPointerAsBytes)
255255
}
256256
}

0 commit comments

Comments
 (0)