Remove duplication using single variant for error
This commit is contained in:
parent
88821ed54d
commit
6ef625fb41
5 changed files with 22 additions and 38 deletions
|
|
@ -13,7 +13,7 @@ use rustc_macros::HashStable;
|
|||
use rustc_target::spec::abi::Abi;
|
||||
use syntax_pos::{Pos, Span};
|
||||
use syntax::symbol::Symbol;
|
||||
|
||||
use hir::GeneratorKind;
|
||||
use std::{fmt, env};
|
||||
|
||||
use rustc_error_codes::*;
|
||||
|
|
@ -264,10 +264,8 @@ pub enum PanicInfo<O> {
|
|||
OverflowNeg,
|
||||
DivisionByZero,
|
||||
RemainderByZero,
|
||||
GeneratorResumedAfterReturn,
|
||||
GeneratorResumedAfterPanic,
|
||||
AsyncResumedAfterReturn,
|
||||
AsyncResumedAfterPanic,
|
||||
ResumedAfterReturn(GeneratorKind),
|
||||
ResumedAfterPanic(GeneratorKind),
|
||||
}
|
||||
|
||||
/// Type for MIR `Assert` terminator error messages.
|
||||
|
|
@ -302,14 +300,16 @@ impl<O> PanicInfo<O> {
|
|||
"attempt to divide by zero",
|
||||
RemainderByZero =>
|
||||
"attempt to calculate the remainder with a divisor of zero",
|
||||
GeneratorResumedAfterReturn =>
|
||||
ResumedAfterReturn(GeneratorKind::Gen) =>
|
||||
"generator resumed after completion",
|
||||
GeneratorResumedAfterPanic =>
|
||||
"generator resumed after panicking",
|
||||
AsyncResumedAfterReturn =>
|
||||
// FIXME: Do we want a separate message for each Async variant (Block, Closure, Fn)?
|
||||
ResumedAfterReturn(GeneratorKind::Async(_)) =>
|
||||
"`async fn` resumed after completion",
|
||||
AsyncResumedAfterPanic =>
|
||||
"`async fn` resumed after panic",
|
||||
ResumedAfterPanic(GeneratorKind::Gen) =>
|
||||
"generator resumed after panicking",
|
||||
// FIXME: Do we want a separate message for each Async variant (Block, Closure, Fn)?
|
||||
ResumedAfterPanic(GeneratorKind::Async(_)) =>
|
||||
"`async fn` resumed after panicking",
|
||||
Panic { .. } | BoundsCheck { .. } =>
|
||||
bug!("Unexpected PanicInfo"),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2981,8 +2981,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
|
|||
index: index.fold_with(folder),
|
||||
},
|
||||
Panic { .. } | Overflow(_) | OverflowNeg | DivisionByZero | RemainderByZero |
|
||||
GeneratorResumedAfterReturn | GeneratorResumedAfterPanic |
|
||||
AsyncResumedAfterReturn | AsyncResumedAfterPanic =>
|
||||
ResumedAfterReturn(_) | ResumedAfterPanic(_) =>
|
||||
msg.clone(),
|
||||
};
|
||||
Assert { cond: cond.fold_with(folder), expected, msg, target, cleanup }
|
||||
|
|
@ -3028,8 +3027,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
|
|||
len.visit_with(visitor) || index.visit_with(visitor),
|
||||
Panic { .. } | Overflow(_) | OverflowNeg |
|
||||
DivisionByZero | RemainderByZero |
|
||||
GeneratorResumedAfterReturn | GeneratorResumedAfterPanic |
|
||||
AsyncResumedAfterReturn | AsyncResumedAfterPanic =>
|
||||
ResumedAfterReturn(_) | ResumedAfterPanic(_) =>
|
||||
false
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -517,8 +517,7 @@ macro_rules! make_mir_visitor {
|
|||
self.visit_operand(index, location);
|
||||
}
|
||||
Panic { .. } | Overflow(_) | OverflowNeg | DivisionByZero | RemainderByZero |
|
||||
GeneratorResumedAfterReturn | GeneratorResumedAfterPanic |
|
||||
AsyncResumedAfterReturn | AsyncResumedAfterPanic => {
|
||||
ResumedAfterReturn(_) | ResumedAfterPanic(_) => {
|
||||
// Nothing to visit
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,10 +142,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
OverflowNeg => err_panic!(OverflowNeg),
|
||||
DivisionByZero => err_panic!(DivisionByZero),
|
||||
RemainderByZero => err_panic!(RemainderByZero),
|
||||
GeneratorResumedAfterReturn => err_panic!(GeneratorResumedAfterReturn),
|
||||
GeneratorResumedAfterPanic => err_panic!(GeneratorResumedAfterPanic),
|
||||
AsyncResumedAfterReturn => err_panic!(AsyncResumedAfterReturn),
|
||||
AsyncResumedAfterPanic => err_panic!(AsyncResumedAfterPanic),
|
||||
ResumedAfterReturn(generator_kind) => err_panic!(ResumedAfterReturn(*generator_kind)),
|
||||
ResumedAfterPanic(generator_kind) => err_panic!(ResumedAfterPanic(*generator_kind)),
|
||||
Panic { .. } => bug!("`Panic` variant cannot occur in MIR"),
|
||||
}
|
||||
.into());
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@
|
|||
//! Otherwise it drops all the values in scope at the last suspension point.
|
||||
|
||||
use rustc::hir;
|
||||
use rustc::hir::{def_id::DefId, GeneratorKind};
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::mir::*;
|
||||
use rustc::mir::visit::{PlaceContext, Visitor, MutVisitor};
|
||||
use rustc::ty::{self, TyCtxt, AdtDef, Ty};
|
||||
|
|
@ -1056,28 +1056,17 @@ fn create_generator_resume_function<'tcx>(
|
|||
let mut cases = create_cases(body, &transform, |point| Some(point.resume));
|
||||
|
||||
use rustc::mir::interpret::PanicInfo::{
|
||||
GeneratorResumedAfterPanic,
|
||||
GeneratorResumedAfterReturn,
|
||||
AsyncResumedAfterReturn,
|
||||
AsyncResumedAfterPanic,
|
||||
ResumedAfterPanic,
|
||||
ResumedAfterReturn,
|
||||
};
|
||||
|
||||
// Jump to the entry point on the unresumed
|
||||
cases.insert(0, (UNRESUMED, BasicBlock::new(0)));
|
||||
|
||||
// Panic when resumed on the returned or poisoned state
|
||||
match body.generator_kind {
|
||||
Some(GeneratorKind::Async(_)) => {
|
||||
cases.insert(1, (RETURNED, insert_panic_block(tcx, body, AsyncResumedAfterReturn)));
|
||||
cases.insert(2, (POISONED, insert_panic_block(tcx, body, AsyncResumedAfterPanic)));
|
||||
},
|
||||
Some(GeneratorKind::Gen) => {
|
||||
cases.insert(1, (RETURNED, insert_panic_block(tcx, body, GeneratorResumedAfterReturn)));
|
||||
cases.insert(2, (POISONED, insert_panic_block(tcx, body, GeneratorResumedAfterPanic)));
|
||||
},
|
||||
None => {
|
||||
// N/A because we would never create a resume function if there was no generator_kind
|
||||
}
|
||||
if let Some(generator_kind) = body.generator_kind {
|
||||
cases.insert(1, (RETURNED, insert_panic_block(tcx, body, ResumedAfterReturn(generator_kind))));
|
||||
cases.insert(2, (POISONED, insert_panic_block(tcx, body, ResumedAfterPanic(generator_kind))));
|
||||
};
|
||||
|
||||
insert_switch(body, cases, &transform, TerminatorKind::Unreachable);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue