提交 6ef625fb 编写于 作者: D David Haig

Remove duplication using single variant for error

上级 88821ed5
......@@ -13,7 +13,7 @@
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 @@ pub fn description(&self) -> &'static str {
"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 @@ fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
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 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
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 @@ fn super_assert_message(&mut self,
self.visit_operand(index, location);
}
Panic { .. } | Overflow(_) | OverflowNeg | DivisionByZero | RemainderByZero |
GeneratorResumedAfterReturn | GeneratorResumedAfterPanic |
AsyncResumedAfterReturn | AsyncResumedAfterPanic => {
ResumedAfterReturn(_) | ResumedAfterPanic(_) => {
// Nothing to visit
}
}
......
......@@ -142,10 +142,8 @@ pub(super) fn eval_terminator(
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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册