The war on abort_if_errors
This commit is contained in:
parent
b1b6b33c6d
commit
0ac8915875
11 changed files with 72 additions and 73 deletions
|
@ -270,8 +270,8 @@ pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
|
||||||
let say = |s: &str| {
|
let say = |s: &str| {
|
||||||
match (sp, sess) {
|
match (sp, sess) {
|
||||||
(_, None) => panic!("{}", s),
|
(_, None) => panic!("{}", s),
|
||||||
(Some(sp), Some(sess)) => sess.span_err(sp, s),
|
(Some(sp), Some(sess)) => sess.span_fatal(sp, s),
|
||||||
(None, Some(sess)) => sess.err(s),
|
(None, Some(sess)) => sess.fatal(s),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if s.is_empty() {
|
if s.is_empty() {
|
||||||
|
@ -282,10 +282,6 @@ pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
|
||||||
if c == '_' { continue }
|
if c == '_' { continue }
|
||||||
say(&format!("invalid character `{}` in crate name: `{}`", c, s));
|
say(&format!("invalid character `{}` in crate name: `{}`", c, s));
|
||||||
}
|
}
|
||||||
match sess {
|
|
||||||
Some(sess) => sess.abort_if_errors(),
|
|
||||||
None => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A dummy crate store that does not support any non-local crates,
|
/// A dummy crate store that does not support any non-local crates,
|
||||||
|
|
|
@ -239,7 +239,6 @@ pub fn collect_language_items(session: &Session,
|
||||||
collector.collect(krate);
|
collector.collect(krate);
|
||||||
let LanguageItemCollector { mut items, .. } = collector;
|
let LanguageItemCollector { mut items, .. } = collector;
|
||||||
weak_lang_items::check_crate(krate, session, &mut items);
|
weak_lang_items::check_crate(krate, session, &mut items);
|
||||||
session.abort_if_errors();
|
|
||||||
items
|
items
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -176,14 +176,15 @@ impl Session {
|
||||||
pub fn abort_if_errors(&self) {
|
pub fn abort_if_errors(&self) {
|
||||||
self.diagnostic().abort_if_errors();
|
self.diagnostic().abort_if_errors();
|
||||||
}
|
}
|
||||||
pub fn abort_if_new_errors<F>(&self, mut f: F)
|
pub fn abort_if_new_errors<F, T>(&self, f: F) -> T
|
||||||
where F: FnMut()
|
where F: FnOnce() -> T
|
||||||
{
|
{
|
||||||
let count = self.err_count();
|
let count = self.err_count();
|
||||||
f();
|
let result = f();
|
||||||
if self.err_count() > count {
|
if self.err_count() > count {
|
||||||
self.abort_if_errors();
|
self.abort_if_errors();
|
||||||
}
|
}
|
||||||
|
result
|
||||||
}
|
}
|
||||||
pub fn span_warn(&self, sp: Span, msg: &str) {
|
pub fn span_warn(&self, sp: Span, msg: &str) {
|
||||||
self.diagnostic().span_warn(sp, msg)
|
self.diagnostic().span_warn(sp, msg)
|
||||||
|
|
|
@ -69,7 +69,6 @@ pub fn compile_input(sess: Session,
|
||||||
let state = $make_state;
|
let state = $make_state;
|
||||||
(control.$point.callback)(state);
|
(control.$point.callback)(state);
|
||||||
|
|
||||||
$tsess.abort_if_errors();
|
|
||||||
if control.$point.stop == Compilation::Stop {
|
if control.$point.stop == Compilation::Stop {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -481,13 +480,15 @@ pub fn phase_2_configure_and_expand(sess: &Session,
|
||||||
});
|
});
|
||||||
|
|
||||||
time(time_passes, "gated macro checking", || {
|
time(time_passes, "gated macro checking", || {
|
||||||
let features = syntax::feature_gate::check_crate_macros(sess.codemap(),
|
sess.abort_if_new_errors(|| {
|
||||||
&sess.parse_sess.span_diagnostic,
|
let features =
|
||||||
&krate);
|
syntax::feature_gate::check_crate_macros(sess.codemap(),
|
||||||
|
&sess.parse_sess.span_diagnostic,
|
||||||
|
&krate);
|
||||||
|
|
||||||
// these need to be set "early" so that expansion sees `quote` if enabled.
|
// these need to be set "early" so that expansion sees `quote` if enabled.
|
||||||
*sess.features.borrow_mut() = features;
|
*sess.features.borrow_mut() = features;
|
||||||
sess.abort_if_errors();
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -525,7 +526,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
|
||||||
let Registry { syntax_exts, early_lint_passes, late_lint_passes, lint_groups,
|
let Registry { syntax_exts, early_lint_passes, late_lint_passes, lint_groups,
|
||||||
llvm_passes, attributes, .. } = registry;
|
llvm_passes, attributes, .. } = registry;
|
||||||
|
|
||||||
{
|
sess.abort_if_new_errors(|| {
|
||||||
let mut ls = sess.lint_store.borrow_mut();
|
let mut ls = sess.lint_store.borrow_mut();
|
||||||
for pass in early_lint_passes {
|
for pass in early_lint_passes {
|
||||||
ls.register_early_pass(Some(sess), true, pass);
|
ls.register_early_pass(Some(sess), true, pass);
|
||||||
|
@ -540,17 +541,14 @@ pub fn phase_2_configure_and_expand(sess: &Session,
|
||||||
|
|
||||||
*sess.plugin_llvm_passes.borrow_mut() = llvm_passes;
|
*sess.plugin_llvm_passes.borrow_mut() = llvm_passes;
|
||||||
*sess.plugin_attributes.borrow_mut() = attributes.clone();
|
*sess.plugin_attributes.borrow_mut() = attributes.clone();
|
||||||
}
|
});
|
||||||
|
|
||||||
// Lint plugins are registered; now we can process command line flags.
|
// Lint plugins are registered; now we can process command line flags.
|
||||||
if sess.opts.describe_lints {
|
if sess.opts.describe_lints {
|
||||||
super::describe_lints(&*sess.lint_store.borrow(), true);
|
super::describe_lints(&*sess.lint_store.borrow(), true);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
sess.lint_store.borrow_mut().process_command_line(sess);
|
sess.abort_if_new_errors(|| sess.lint_store.borrow_mut().process_command_line(sess));
|
||||||
|
|
||||||
// Abort if there are errors from lint processing or a plugin registrar.
|
|
||||||
sess.abort_if_errors();
|
|
||||||
|
|
||||||
krate = time(time_passes, "expansion", || {
|
krate = time(time_passes, "expansion", || {
|
||||||
// Windows dlls do not have rpaths, so they don't know how to find their
|
// Windows dlls do not have rpaths, so they don't know how to find their
|
||||||
|
@ -594,13 +592,14 @@ pub fn phase_2_configure_and_expand(sess: &Session,
|
||||||
// much as possible (e.g. help the programmer avoid platform
|
// much as possible (e.g. help the programmer avoid platform
|
||||||
// specific differences)
|
// specific differences)
|
||||||
time(time_passes, "complete gated feature checking 1", || {
|
time(time_passes, "complete gated feature checking 1", || {
|
||||||
let features = syntax::feature_gate::check_crate(sess.codemap(),
|
sess.abort_if_new_errors(|| {
|
||||||
&sess.parse_sess.span_diagnostic,
|
let features = syntax::feature_gate::check_crate(sess.codemap(),
|
||||||
&krate,
|
&sess.parse_sess.span_diagnostic,
|
||||||
&attributes,
|
&krate,
|
||||||
sess.opts.unstable_features);
|
&attributes,
|
||||||
*sess.features.borrow_mut() = features;
|
sess.opts.unstable_features);
|
||||||
sess.abort_if_errors();
|
*sess.features.borrow_mut() = features;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// JBC: make CFG processing part of expansion to avoid this problem:
|
// JBC: make CFG processing part of expansion to avoid this problem:
|
||||||
|
@ -639,13 +638,14 @@ pub fn phase_2_configure_and_expand(sess: &Session,
|
||||||
// later, to make sure we've got everything (e.g. configuration
|
// later, to make sure we've got everything (e.g. configuration
|
||||||
// can insert new attributes via `cfg_attr`)
|
// can insert new attributes via `cfg_attr`)
|
||||||
time(time_passes, "complete gated feature checking 2", || {
|
time(time_passes, "complete gated feature checking 2", || {
|
||||||
let features = syntax::feature_gate::check_crate(sess.codemap(),
|
sess.abort_if_new_errors(|| {
|
||||||
&sess.parse_sess.span_diagnostic,
|
let features = syntax::feature_gate::check_crate(sess.codemap(),
|
||||||
&krate,
|
&sess.parse_sess.span_diagnostic,
|
||||||
&attributes,
|
&krate,
|
||||||
sess.opts.unstable_features);
|
&attributes,
|
||||||
*sess.features.borrow_mut() = features;
|
sess.opts.unstable_features);
|
||||||
sess.abort_if_errors();
|
*sess.features.borrow_mut() = features;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
time(time_passes,
|
time(time_passes,
|
||||||
|
@ -711,9 +711,11 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
|
||||||
"external crate/lib resolution",
|
"external crate/lib resolution",
|
||||||
|| LocalCrateReader::new(sess, cstore, &hir_map).read_crates(krate));
|
|| LocalCrateReader::new(sess, cstore, &hir_map).read_crates(krate));
|
||||||
|
|
||||||
let lang_items = time(time_passes,
|
let lang_items = time(time_passes, "language item collection", || {
|
||||||
"language item collection",
|
sess.abort_if_new_errors(|| {
|
||||||
|| middle::lang_items::collect_language_items(&sess, &hir_map));
|
middle::lang_items::collect_language_items(&sess, &hir_map)
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
let resolve::CrateMap {
|
let resolve::CrateMap {
|
||||||
def_map,
|
def_map,
|
||||||
|
|
|
@ -258,15 +258,14 @@ impl<'a> CrateReader<'a> {
|
||||||
metadata: &MetadataBlob) {
|
metadata: &MetadataBlob) {
|
||||||
let crate_rustc_version = decoder::crate_rustc_version(metadata.as_slice());
|
let crate_rustc_version = decoder::crate_rustc_version(metadata.as_slice());
|
||||||
if crate_rustc_version != Some(rustc_version()) {
|
if crate_rustc_version != Some(rustc_version()) {
|
||||||
span_err!(self.sess, span, E0514,
|
span_fatal!(self.sess, span, E0514,
|
||||||
"the crate `{}` has been compiled with {}, which is \
|
"the crate `{}` has been compiled with {}, which is \
|
||||||
incompatible with this version of rustc",
|
incompatible with this version of rustc",
|
||||||
name,
|
name,
|
||||||
crate_rustc_version
|
crate_rustc_version
|
||||||
.as_ref().map(|s|&**s)
|
.as_ref().map(|s|&**s)
|
||||||
.unwrap_or("an old version of rustc")
|
.unwrap_or("an old version of rustc")
|
||||||
);
|
);
|
||||||
self.sess.abort_if_errors();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -511,7 +510,6 @@ impl<'a> CrateReader<'a> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let span = mk_sp(lo, p.last_span.hi);
|
let span = mk_sp(lo, p.last_span.hi);
|
||||||
p.abort_if_errors();
|
|
||||||
|
|
||||||
// Mark the attrs as used
|
// Mark the attrs as used
|
||||||
for attr in &attrs {
|
for attr in &attrs {
|
||||||
|
@ -554,8 +552,7 @@ impl<'a> CrateReader<'a> {
|
||||||
name,
|
name,
|
||||||
config::host_triple(),
|
config::host_triple(),
|
||||||
self.sess.opts.target_triple);
|
self.sess.opts.target_triple);
|
||||||
span_err!(self.sess, span, E0456, "{}", &message[..]);
|
span_fatal!(self.sess, span, E0456, "{}", &message[..]);
|
||||||
self.sess.abort_if_errors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let registrar =
|
let registrar =
|
||||||
|
|
|
@ -18,8 +18,9 @@ use syntax::visit::{self, Visitor, FnKind};
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
|
|
||||||
pub fn check_crate(sess: &Session, krate: &ast::Crate) {
|
pub fn check_crate(sess: &Session, krate: &ast::Crate) {
|
||||||
visit::walk_crate(&mut CheckConstFn{ sess: sess }, krate);
|
sess.abort_if_new_errors(|| {
|
||||||
sess.abort_if_errors();
|
visit::walk_crate(&mut CheckConstFn{ sess: sess }, krate);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CheckConstFn<'a> {
|
struct CheckConstFn<'a> {
|
||||||
|
|
|
@ -4019,10 +4019,8 @@ pub fn create_resolver<'a, 'tcx>(session: &'a Session,
|
||||||
resolver.callback = callback;
|
resolver.callback = callback;
|
||||||
|
|
||||||
build_reduced_graph::build_reduced_graph(&mut resolver, krate);
|
build_reduced_graph::build_reduced_graph(&mut resolver, krate);
|
||||||
session.abort_if_errors();
|
|
||||||
|
|
||||||
resolve_imports::resolve_imports(&mut resolver);
|
resolve_imports::resolve_imports(&mut resolver);
|
||||||
session.abort_if_errors();
|
|
||||||
|
|
||||||
resolver
|
resolver
|
||||||
}
|
}
|
||||||
|
|
|
@ -555,6 +555,9 @@ impl Handler {
|
||||||
pub enum Level {
|
pub enum Level {
|
||||||
Bug,
|
Bug,
|
||||||
Fatal,
|
Fatal,
|
||||||
|
// An error which while not immediately fatal, should stop the compiler
|
||||||
|
// progressing beyond the current phase.
|
||||||
|
PhaseFatal,
|
||||||
Error,
|
Error,
|
||||||
Warning,
|
Warning,
|
||||||
Note,
|
Note,
|
||||||
|
@ -573,7 +576,7 @@ impl fmt::Display for Level {
|
||||||
impl Level {
|
impl Level {
|
||||||
fn color(self) -> term::color::Color {
|
fn color(self) -> term::color::Color {
|
||||||
match self {
|
match self {
|
||||||
Bug | Fatal | Error => term::color::BRIGHT_RED,
|
Bug | Fatal | PhaseFatal | Error => term::color::BRIGHT_RED,
|
||||||
Warning => term::color::BRIGHT_YELLOW,
|
Warning => term::color::BRIGHT_YELLOW,
|
||||||
Note => term::color::BRIGHT_GREEN,
|
Note => term::color::BRIGHT_GREEN,
|
||||||
Help => term::color::BRIGHT_CYAN,
|
Help => term::color::BRIGHT_CYAN,
|
||||||
|
@ -584,7 +587,7 @@ impl Level {
|
||||||
fn to_str(self) -> &'static str {
|
fn to_str(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Bug => "error: internal compiler error",
|
Bug => "error: internal compiler error",
|
||||||
Fatal | Error => "error",
|
Fatal | PhaseFatal | Error => "error",
|
||||||
Warning => "warning",
|
Warning => "warning",
|
||||||
Note => "note",
|
Note => "note",
|
||||||
Help => "help",
|
Help => "help",
|
||||||
|
|
|
@ -1304,9 +1304,14 @@ pub fn expand_crate(mut cx: ExtCtxt,
|
||||||
expander.cx.syntax_env.insert(name, extension);
|
expander.cx.syntax_env.insert(name, extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let err_count = cx.parse_sess.span_diagnostic.err_count();
|
||||||
let mut ret = expander.fold_crate(c);
|
let mut ret = expander.fold_crate(c);
|
||||||
ret.exported_macros = expander.cx.exported_macros.clone();
|
ret.exported_macros = expander.cx.exported_macros.clone();
|
||||||
cx.parse_sess.span_diagnostic.abort_if_errors();
|
|
||||||
|
if cx.parse_sess.span_diagnostic.err_count() > err_count {
|
||||||
|
cx.parse_sess.span_diagnostic.abort_if_errors();
|
||||||
|
}
|
||||||
|
|
||||||
ret
|
ret
|
||||||
};
|
};
|
||||||
return (ret, cx.syntax_env.names);
|
return (ret, cx.syntax_env.names);
|
||||||
|
|
|
@ -98,7 +98,7 @@ pub fn parse_crate_from_source_str(name: String,
|
||||||
cfg,
|
cfg,
|
||||||
name,
|
name,
|
||||||
source);
|
source);
|
||||||
maybe_aborted(panictry!(p.parse_crate_mod()),p)
|
panictry!(p.parse_crate_mod())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_crate_attrs_from_source_str(name: String,
|
pub fn parse_crate_attrs_from_source_str(name: String,
|
||||||
|
@ -110,7 +110,7 @@ pub fn parse_crate_attrs_from_source_str(name: String,
|
||||||
cfg,
|
cfg,
|
||||||
name,
|
name,
|
||||||
source);
|
source);
|
||||||
maybe_aborted(panictry!(p.parse_inner_attributes()), p)
|
panictry!(p.parse_inner_attributes())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_expr_from_source_str(name: String,
|
pub fn parse_expr_from_source_str(name: String,
|
||||||
|
@ -119,7 +119,7 @@ pub fn parse_expr_from_source_str(name: String,
|
||||||
sess: &ParseSess)
|
sess: &ParseSess)
|
||||||
-> P<ast::Expr> {
|
-> P<ast::Expr> {
|
||||||
let mut p = new_parser_from_source_str(sess, cfg, name, source);
|
let mut p = new_parser_from_source_str(sess, cfg, name, source);
|
||||||
maybe_aborted(panictry!(p.parse_expr()), p)
|
panictry!(p.parse_expr())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_item_from_source_str(name: String,
|
pub fn parse_item_from_source_str(name: String,
|
||||||
|
@ -128,7 +128,7 @@ pub fn parse_item_from_source_str(name: String,
|
||||||
sess: &ParseSess)
|
sess: &ParseSess)
|
||||||
-> Option<P<ast::Item>> {
|
-> Option<P<ast::Item>> {
|
||||||
let mut p = new_parser_from_source_str(sess, cfg, name, source);
|
let mut p = new_parser_from_source_str(sess, cfg, name, source);
|
||||||
maybe_aborted(panictry!(p.parse_item()), p)
|
panictry!(p.parse_item())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_meta_from_source_str(name: String,
|
pub fn parse_meta_from_source_str(name: String,
|
||||||
|
@ -137,7 +137,7 @@ pub fn parse_meta_from_source_str(name: String,
|
||||||
sess: &ParseSess)
|
sess: &ParseSess)
|
||||||
-> P<ast::MetaItem> {
|
-> P<ast::MetaItem> {
|
||||||
let mut p = new_parser_from_source_str(sess, cfg, name, source);
|
let mut p = new_parser_from_source_str(sess, cfg, name, source);
|
||||||
maybe_aborted(panictry!(p.parse_meta_item()), p)
|
panictry!(p.parse_meta_item())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_stmt_from_source_str(name: String,
|
pub fn parse_stmt_from_source_str(name: String,
|
||||||
|
@ -151,7 +151,7 @@ pub fn parse_stmt_from_source_str(name: String,
|
||||||
name,
|
name,
|
||||||
source
|
source
|
||||||
);
|
);
|
||||||
maybe_aborted(panictry!(p.parse_stmt()), p)
|
panictry!(p.parse_stmt())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warning: This parses with quote_depth > 0, which is not the default.
|
// Warning: This parses with quote_depth > 0, which is not the default.
|
||||||
|
@ -168,7 +168,7 @@ pub fn parse_tts_from_source_str(name: String,
|
||||||
);
|
);
|
||||||
p.quote_depth += 1;
|
p.quote_depth += 1;
|
||||||
// right now this is re-creating the token trees from ... token trees.
|
// right now this is re-creating the token trees from ... token trees.
|
||||||
maybe_aborted(panictry!(p.parse_all_token_trees()),p)
|
panictry!(p.parse_all_token_trees())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new parser from a source string
|
// Create a new parser from a source string
|
||||||
|
@ -265,16 +265,10 @@ pub fn tts_to_parser<'a>(sess: &'a ParseSess,
|
||||||
p
|
p
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Abort if necessary
|
|
||||||
pub fn maybe_aborted<T>(result: T, p: Parser) -> T {
|
|
||||||
p.abort_if_errors();
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
fn abort_if_errors<'a, T>(result: PResult<'a, T>, p: &Parser) -> T {
|
fn abort_if_errors<'a, T>(result: PResult<'a, T>, p: &Parser) -> T {
|
||||||
match result {
|
match result {
|
||||||
Ok(c) => {
|
Ok(c) => {
|
||||||
p.abort_if_errors();
|
|
||||||
c
|
c
|
||||||
}
|
}
|
||||||
Err(mut e) => {
|
Err(mut e) => {
|
||||||
|
|
|
@ -2357,7 +2357,11 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
// Assuming we have just parsed `.foo` (i.e., a dot and an ident), continue
|
// Assuming we have just parsed `.foo` (i.e., a dot and an ident), continue
|
||||||
// parsing into an expression.
|
// parsing into an expression.
|
||||||
fn parse_dot_suffix(&mut self, ident: Ident, ident_span: Span, self_value: P<Expr>) -> PResult<'a, P<Expr>> {
|
fn parse_dot_suffix(&mut self,
|
||||||
|
ident: Ident,
|
||||||
|
ident_span: Span,
|
||||||
|
self_value: P<Expr>)
|
||||||
|
-> PResult<'a, P<Expr>> {
|
||||||
let (_, tys, bindings) = if self.eat(&token::ModSep) {
|
let (_, tys, bindings) = if self.eat(&token::ModSep) {
|
||||||
try!(self.expect_lt());
|
try!(self.expect_lt());
|
||||||
try!(self.parse_generic_values_after_lt())
|
try!(self.parse_generic_values_after_lt())
|
||||||
|
@ -2463,7 +2467,6 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// TODO special case lifetime
|
|
||||||
// FIXME Could factor this out into non_fatal_unexpected or something.
|
// FIXME Could factor this out into non_fatal_unexpected or something.
|
||||||
let actual = self.this_token_to_string();
|
let actual = self.this_token_to_string();
|
||||||
self.span_err(self.span, &format!("unexpected token: `{}`", actual));
|
self.span_err(self.span, &format!("unexpected token: `{}`", actual));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue