Skip to content

Commit fc5df1d

Browse files
committed
renaming err to err_unsup
1 parent b60a336 commit fc5df1d

File tree

18 files changed

+73
-63
lines changed

18 files changed

+73
-63
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!(UnterminatedCString(ptr.erase_tag())),
247+
None => throw_err_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!(ReadPointerAsBytes)
449+
throw_err_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!(ReadUndefBytes(idx)))
519+
).or_else(|idx| throw_err_unsup!(ReadUndefBytes(idx)))
520520
}
521521

522522
pub fn mark_definedness(

src/librustc/mir/interpret/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ pub fn struct_error<'tcx>(tcx: TyCtxtAt<'tcx>, msg: &str) -> DiagnosticBuilder<'
184184
/// Packages the kind of error we got from the const code interpreter
185185
/// up with a Rust-level backtrace of where the error occured.
186186
/// Thsese should always be constructed by calling `.into()` on
187-
/// a `InterpError`. In `librustc_mir::interpret`, we have the `throw_err!`
188-
/// macro for this.
187+
/// a `InterpError`. In `librustc_mir::interpret`, we have `throw_err_*`
188+
/// macros for this.
189189
#[derive(Debug, Clone)]
190190
pub struct InterpErrorInfo<'tcx> {
191191
pub kind: InterpError<'tcx>,

src/librustc/mir/interpret/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! An interpreter for MIR used in CTFE and by miri
22
33
#[macro_export]
4-
macro_rules! throw_err {
4+
macro_rules! throw_err_unsup {
55
($($tt:tt)*) => {
66
Err($crate::mir::interpret::InterpError::Unsupported(
77
$crate::mir::interpret::UnsupportedOpInfo::$($tt)*
@@ -55,7 +55,7 @@ macro_rules! err_inval {
5555
}
5656

5757
#[macro_export]
58-
macro_rules! err {
58+
macro_rules! err_unsup {
5959
($($tt:tt)*) => {
6060
$crate::mir::interpret::InterpError::Unsupported(
6161
$crate::mir::interpret::UnsupportedOpInfo::$($tt)*

src/librustc/mir/interpret/pointer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl<'tcx, Tag> Pointer<Tag> {
196196
msg: CheckInAllocMsg,
197197
) -> InterpResult<'tcx, ()> {
198198
if self.offset > allocation_size {
199-
throw_err!(PointerOutOfBounds { ptr: self.erase_tag(), msg, allocation_size })
199+
throw_err_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!(ReadPointerAsBytes),
363+
Scalar::Ptr(_) => throw_err_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!(InvalidNullPointerUsage),
377-
Scalar::Raw { .. } => throw_err!(ReadBytesAsPointer),
376+
Scalar::Raw { data: 0, .. } => throw_err_unsup!(InvalidNullPointerUsage),
377+
Scalar::Raw { .. } => throw_err_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!(InvalidBool),
409+
_ => throw_err_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!(InvalidChar(val as u128)),
417+
None => throw_err_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!(ReadUndefBytes(Size::from_bytes(0))),
540+
ScalarMaybeUndef::Undef => throw_err_unsup!(ReadUndefBytes(Size::from_bytes(0))),
541541
}
542542
}
543543

src/librustc_mir/const_eval.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,9 @@ 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!(MachineError(format!("calling non-const function `{}`", instance)))
355+
throw_err_unsup!(
356+
MachineError(format!("calling non-const function `{}`", instance))
357+
)
356358
};
357359
}
358360
}
@@ -412,7 +414,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
412414
_tcx: TyCtxt<'tcx>,
413415
_def_id: DefId,
414416
) -> InterpResult<'tcx, Cow<'tcx, Allocation<Self::PointerTag>>> {
415-
throw_err!(ReadForeignStatic)
417+
throw_err_unsup!(ReadForeignStatic)
416418
}
417419

418420
#[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!(Unimplemented(format!("int to {:?} cast", dest_layout.ty))),
202+
_ => throw_err_unsup!(Unimplemented(format!("int to {:?} cast", dest_layout.ty))),
203203
}
204204
}
205205

src/librustc_mir/interpret/eval_context.rs

Lines changed: 3 additions & 3 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!(DeadLocal),
138+
LocalValue::Dead => throw_err_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!(DeadLocal),
151+
LocalValue::Dead => throw_err_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 => {
@@ -346,7 +346,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
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!(NoMirFor(self.tcx.def_path_str(def_id)))
349+
throw_err_unsup!(NoMirFor(self.tcx.def_path_str(def_id)))
350350
},
351351
_ => Ok(self.tcx.instance_mir(instance)),
352352
}

src/librustc_mir/interpret/intern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +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!(
331+
return throw_err_unsup!(
332332
ValidationFailure("encountered dangling pointer in final constant".into())
333333
)
334334
}

src/librustc_mir/interpret/intrinsics.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ 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!(Intrinsic(format!("{} called on 0", intrinsic_name)));
107+
return throw_err_unsup!(
108+
Intrinsic(format!("{} called on 0", intrinsic_name))
109+
);
108110
}
109111
numeric_intrinsic(intrinsic_name.trim_end_matches("_nonzero"), bits, kind)?
110112
} else {
@@ -190,7 +192,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
190192
if overflowed {
191193
let layout = self.layout_of(substs.type_at(0))?;
192194
let r_val = r.to_scalar()?.to_bits(layout.size)?;
193-
return throw_err!(Intrinsic(
195+
return throw_err_unsup!(Intrinsic(
194196
format!("Overflowing shift by {} in {}", r_val, intrinsic_name),
195197
));
196198
}

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!(ReadPointerAsBytes)
254+
throw_err_unsup!(ReadPointerAsBytes)
255255
}
256256
}

src/librustc_mir/interpret/memory.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<'tcx, Other> FnVal<'tcx, Other> {
6666
match self {
6767
FnVal::Instance(instance) =>
6868
Ok(instance),
69-
FnVal::Other(_) => throw_err!(MachineError(format!(
69+
FnVal::Other(_) => throw_err_unsup!(MachineError(format!(
7070
"Expected instance function pointer, got 'other' pointer"
7171
))),
7272
}
@@ -202,7 +202,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
202202
kind: MemoryKind<M::MemoryKinds>,
203203
) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
204204
if ptr.offset.bytes() != 0 {
205-
return throw_err!(ReallocateNonBasePtr);
205+
return throw_err_unsup!(ReallocateNonBasePtr);
206206
}
207207

208208
// For simplicities' sake, we implement reallocate as "alloc, copy, dealloc".
@@ -243,38 +243,40 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
243243
trace!("deallocating: {}", ptr.alloc_id);
244244

245245
if ptr.offset.bytes() != 0 {
246-
return throw_err!(DeallocateNonBasePtr);
246+
return throw_err_unsup!(DeallocateNonBasePtr);
247247
}
248248

249249
let (alloc_kind, mut alloc) = match self.alloc_map.remove(&ptr.alloc_id) {
250250
Some(alloc) => alloc,
251251
None => {
252252
// Deallocating static memory -- always an error
253253
return match self.tcx.alloc_map.lock().get(ptr.alloc_id) {
254-
Some(GlobalAlloc::Function(..)) => throw_err!(DeallocatedWrongMemoryKind(
254+
Some(GlobalAlloc::Function(..)) => throw_err_unsup!(DeallocatedWrongMemoryKind(
255255
"function".to_string(),
256256
format!("{:?}", kind),
257257
)),
258258
Some(GlobalAlloc::Static(..)) |
259-
Some(GlobalAlloc::Memory(..)) => throw_err!(DeallocatedWrongMemoryKind(
259+
Some(GlobalAlloc::Memory(..)) => throw_err_unsup!(DeallocatedWrongMemoryKind(
260260
"static".to_string(),
261261
format!("{:?}", kind),
262262
)),
263-
None => throw_err!(DoubleFree)
263+
None => throw_err_unsup!(DoubleFree)
264264
}
265265
}
266266
};
267267

268268
if alloc_kind != kind {
269-
return throw_err!(DeallocatedWrongMemoryKind(
269+
return throw_err_unsup!(DeallocatedWrongMemoryKind(
270270
format!("{:?}", alloc_kind),
271271
format!("{:?}", kind),
272272
));
273273
}
274274
if let Some((size, align)) = old_size_and_align {
275275
if size.bytes() != alloc.bytes.len() as u64 || align != alloc.align {
276276
let bytes = Size::from_bytes(alloc.bytes.len() as u64);
277-
return throw_err!(IncorrectAllocationInformation(size, bytes, align, alloc.align));
277+
return throw_err_unsup!(
278+
IncorrectAllocationInformation(size, bytes, align, alloc.align)
279+
);
278280
}
279281
}
280282

@@ -319,7 +321,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
319321
} else {
320322
// The biggest power of two through which `offset` is divisible.
321323
let offset_pow2 = 1 << offset.trailing_zeros();
322-
throw_err!(AlignmentCheckFailed {
324+
throw_err_unsup!(AlignmentCheckFailed {
323325
has: Align::from_bytes(offset_pow2).unwrap(),
324326
required: align,
325327
})
@@ -341,7 +343,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
341343
assert!(size.bytes() == 0);
342344
// Must be non-NULL and aligned.
343345
if bits == 0 {
344-
return throw_err!(InvalidNullPointerUsage);
346+
return throw_err_unsup!(InvalidNullPointerUsage);
345347
}
346348
check_offset_align(bits, align)?;
347349
None
@@ -362,7 +364,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
362364
// got picked we might be aligned even if this check fails.
363365
// We instead have to fall back to converting to an integer and checking
364366
// the "real" alignment.
365-
return throw_err!(AlignmentCheckFailed {
367+
return throw_err_unsup!(AlignmentCheckFailed {
366368
has: alloc_align,
367369
required: align,
368370
});
@@ -413,9 +415,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
413415
Some(GlobalAlloc::Memory(mem)) =>
414416
Cow::Borrowed(mem),
415417
Some(GlobalAlloc::Function(..)) =>
416-
return throw_err!(DerefFunctionPointer),
418+
return throw_err_unsup!(DerefFunctionPointer),
417419
None =>
418-
return throw_err!(DanglingPointerDeref),
420+
return throw_err_unsup!(DanglingPointerDeref),
419421
Some(GlobalAlloc::Static(def_id)) => {
420422
// We got a "lazy" static that has not been computed yet.
421423
if tcx.is_foreign_item(def_id) {
@@ -505,11 +507,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
505507
// to give us a cheap reference.
506508
let alloc = Self::get_static_alloc(memory_extra, tcx, id)?;
507509
if alloc.mutability == Mutability::Immutable {
508-
return throw_err!(ModifiedConstantMemory);
510+
return throw_err_unsup!(ModifiedConstantMemory);
509511
}
510512
match M::STATIC_KIND {
511513
Some(kind) => Ok((MemoryKind::Machine(kind), alloc.into_owned())),
512-
None => throw_err!(ModifiedStatic),
514+
None => throw_err_unsup!(ModifiedStatic),
513515
}
514516
});
515517
// Unpack the error type manually because type inference doesn't
@@ -519,7 +521,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
519521
Ok(a) => {
520522
let a = &mut a.1;
521523
if a.mutability == Mutability::Immutable {
522-
return throw_err!(ModifiedConstantMemory);
524+
return throw_err_unsup!(ModifiedConstantMemory);
523525
}
524526
Ok(a)
525527
}
@@ -548,7 +550,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
548550
if let Ok(_) = self.get_fn_alloc(id) {
549551
return if let AllocCheck::Dereferencable = liveness {
550552
// The caller requested no function pointers.
551-
throw_err!(DerefFunctionPointer)
553+
throw_err_unsup!(DerefFunctionPointer)
552554
} else {
553555
Ok((Size::ZERO, Align::from_bytes(1).unwrap()))
554556
};
@@ -579,7 +581,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
579581
.expect("deallocated pointers should all be recorded in \
580582
`dead_alloc_map`"))
581583
} else {
582-
throw_err!(DanglingPointerDeref)
584+
throw_err_unsup!(DanglingPointerDeref)
583585
},
584586
}
585587
}
@@ -591,7 +593,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
591593
} else {
592594
match self.tcx.alloc_map.lock().get(id) {
593595
Some(GlobalAlloc::Function(instance)) => Ok(FnVal::Instance(instance)),
594-
_ => throw_err!(ExecuteMemory),
596+
_ => throw_err_unsup!(ExecuteMemory),
595597
}
596598
}
597599
}
@@ -602,7 +604,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
602604
) -> InterpResult<'tcx, FnVal<'tcx, M::ExtraFnVal>> {
603605
let ptr = self.force_ptr(ptr)?; // We definitely need a pointer value.
604606
if ptr.offset.bytes() != 0 {
605-
return throw_err!(InvalidFunctionPointer);
607+
return throw_err_unsup!(InvalidFunctionPointer);
606608
}
607609
self.get_fn_alloc(ptr.alloc_id)
608610
}
@@ -837,7 +839,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
837839
if (src.offset <= dest.offset && src.offset + size > dest.offset) ||
838840
(dest.offset <= src.offset && dest.offset + size > src.offset)
839841
{
840-
return throw_err!(Intrinsic(
842+
return throw_err_unsup!(Intrinsic(
841843
"copy_nonoverlapping called on overlapping ranges".to_string(),
842844
));
843845
}

0 commit comments

Comments
 (0)