Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1b40570

Browse files
committedMar 9, 2020
Auto merge of #69846 - Centril:rollup-7j2v0dx, r=Centril
Rollup of 6 pull requests Successful merges: - #69201 (Permit attributes on 'if' expressions) - #69402 (Extend search) - #69519 ( Don't use static crt by default when build proc-macro) - #69685 (unix: Don't override existing SIGSEGV/BUS handlers) - #69762 (Ensure that validity only raises validity errors) - #69779 (librustc_codegen_llvm: Use slices in preference to 0-terminated strings) Failed merges: r? @ghost
2 parents 2cb0b85 + 6cf5a14 commit 1b40570

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1001
-534
lines changed
 

‎src/librustc/mir/interpret/error.rs

+23-4
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ fn print_backtrace(backtrace: &mut Backtrace) {
245245
eprintln!("\n\nAn error occurred in miri:\n{:?}", backtrace);
246246
}
247247

248-
impl From<ErrorHandled> for InterpErrorInfo<'tcx> {
248+
impl From<ErrorHandled> for InterpErrorInfo<'_> {
249249
fn from(err: ErrorHandled) -> Self {
250250
match err {
251251
ErrorHandled::Reported => err_inval!(ReferencedConstant),
@@ -291,7 +291,7 @@ pub enum InvalidProgramInfo<'tcx> {
291291
Layout(layout::LayoutError<'tcx>),
292292
}
293293

294-
impl fmt::Debug for InvalidProgramInfo<'tcx> {
294+
impl fmt::Debug for InvalidProgramInfo<'_> {
295295
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
296296
use InvalidProgramInfo::*;
297297
match self {
@@ -321,6 +321,8 @@ pub enum UndefinedBehaviorInfo {
321321
RemainderByZero,
322322
/// Overflowing inbounds pointer arithmetic.
323323
PointerArithOverflow,
324+
/// Invalid metadata in a wide pointer (using `str` to avoid allocations).
325+
InvalidMeta(&'static str),
324326
}
325327

326328
impl fmt::Debug for UndefinedBehaviorInfo {
@@ -338,6 +340,7 @@ impl fmt::Debug for UndefinedBehaviorInfo {
338340
DivisionByZero => write!(f, "dividing by zero"),
339341
RemainderByZero => write!(f, "calculating the remainder with a divisor of zero"),
340342
PointerArithOverflow => write!(f, "overflowing in-bounds pointer arithmetic"),
343+
InvalidMeta(msg) => write!(f, "invalid metadata in wide pointer: {}", msg),
341344
}
342345
}
343346
}
@@ -354,8 +357,8 @@ pub enum UnsupportedOpInfo<'tcx> {
354357
Unsupported(String),
355358

356359
/// When const-prop encounters a situation it does not support, it raises this error.
357-
/// This must not allocate for performance reasons.
358-
ConstPropUnsupported(&'tcx str),
360+
/// This must not allocate for performance reasons (hence `str`, not `String`).
361+
ConstPropUnsupported(&'static str),
359362

360363
// -- Everything below is not categorized yet --
361364
FunctionAbiMismatch(Abi, Abi),
@@ -612,3 +615,19 @@ impl fmt::Debug for InterpError<'_> {
612615
}
613616
}
614617
}
618+
619+
impl InterpError<'_> {
620+
/// Some errors allocate to be created as they contain free-form strings.
621+
/// And sometimes we want to be sure that did not happen as it is a
622+
/// waste of resources.
623+
pub fn allocates(&self) -> bool {
624+
match self {
625+
InterpError::MachineStop(_)
626+
| InterpError::Unsupported(UnsupportedOpInfo::Unsupported(_))
627+
| InterpError::Unsupported(UnsupportedOpInfo::ValidationFailure(_))
628+
| InterpError::UndefinedBehavior(UndefinedBehaviorInfo::Ub(_))
629+
| InterpError::UndefinedBehavior(UndefinedBehaviorInfo::UbExperimental(_)) => true,
630+
_ => false,
631+
}
632+
}
633+
}

0 commit comments

Comments
 (0)
Please sign in to comment.