Do not capture stderr in the compiler. Instead just panic silently for fatal errors
This commit is contained in:
parent
9fd7da904b
commit
9a8d6b8bb5
19 changed files with 90 additions and 97 deletions
|
@ -2837,8 +2837,8 @@ impl<'a> LoweringContext<'a> {
|
||||||
(&None, &Some(..), Closed) => "RangeToInclusive",
|
(&None, &Some(..), Closed) => "RangeToInclusive",
|
||||||
(&Some(..), &Some(..), Closed) => "RangeInclusive",
|
(&Some(..), &Some(..), Closed) => "RangeInclusive",
|
||||||
(_, &None, Closed) =>
|
(_, &None, Closed) =>
|
||||||
panic!(self.diagnostic().span_fatal(
|
self.diagnostic().span_fatal(
|
||||||
e.span, "inclusive range with no end")),
|
e.span, "inclusive range with no end").raise(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let fields =
|
let fields =
|
||||||
|
|
|
@ -1333,7 +1333,7 @@ pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
|
||||||
sp.struct_fatal(&format!("Error loading target specification: {}", e))
|
sp.struct_fatal(&format!("Error loading target specification: {}", e))
|
||||||
.help("Use `--print target-list` for a list of built-in targets")
|
.help("Use `--print target-list` for a list of built-in targets")
|
||||||
.emit();
|
.emit();
|
||||||
panic!(FatalError);
|
FatalError.raise();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1341,8 +1341,8 @@ pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
|
||||||
"16" => (ast::IntTy::I16, ast::UintTy::U16),
|
"16" => (ast::IntTy::I16, ast::UintTy::U16),
|
||||||
"32" => (ast::IntTy::I32, ast::UintTy::U32),
|
"32" => (ast::IntTy::I32, ast::UintTy::U32),
|
||||||
"64" => (ast::IntTy::I64, ast::UintTy::U64),
|
"64" => (ast::IntTy::I64, ast::UintTy::U64),
|
||||||
w => panic!(sp.fatal(&format!("target specification was invalid: \
|
w => sp.fatal(&format!("target specification was invalid: \
|
||||||
unrecognized target-pointer-width {}", w))),
|
unrecognized target-pointer-width {}", w)).raise(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Config {
|
Config {
|
||||||
|
|
|
@ -250,7 +250,7 @@ impl Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
|
pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
|
||||||
panic!(self.diagnostic().span_fatal(sp, msg))
|
self.diagnostic().span_fatal(sp, msg).raise()
|
||||||
}
|
}
|
||||||
pub fn span_fatal_with_code<S: Into<MultiSpan>>(
|
pub fn span_fatal_with_code<S: Into<MultiSpan>>(
|
||||||
&self,
|
&self,
|
||||||
|
@ -258,10 +258,10 @@ impl Session {
|
||||||
msg: &str,
|
msg: &str,
|
||||||
code: DiagnosticId,
|
code: DiagnosticId,
|
||||||
) -> ! {
|
) -> ! {
|
||||||
panic!(self.diagnostic().span_fatal_with_code(sp, msg, code))
|
self.diagnostic().span_fatal_with_code(sp, msg, code).raise()
|
||||||
}
|
}
|
||||||
pub fn fatal(&self, msg: &str) -> ! {
|
pub fn fatal(&self, msg: &str) -> ! {
|
||||||
panic!(self.diagnostic().fatal(msg))
|
self.diagnostic().fatal(msg).raise()
|
||||||
}
|
}
|
||||||
pub fn span_err_or_warn<S: Into<MultiSpan>>(&self, is_warning: bool, sp: S, msg: &str) {
|
pub fn span_err_or_warn<S: Into<MultiSpan>>(&self, is_warning: bool, sp: S, msg: &str) {
|
||||||
if is_warning {
|
if is_warning {
|
||||||
|
@ -919,7 +919,7 @@ pub fn build_session_(sopts: config::Options,
|
||||||
let host = match Target::search(config::host_triple()) {
|
let host = match Target::search(config::host_triple()) {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
panic!(span_diagnostic.fatal(&format!("Error loading host specification: {}", e)));
|
span_diagnostic.fatal(&format!("Error loading host specification: {}", e)).raise();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let target_cfg = config::build_target_config(&sopts, &span_diagnostic);
|
let target_cfg = config::build_target_config(&sopts, &span_diagnostic);
|
||||||
|
@ -945,7 +945,7 @@ pub fn build_session_(sopts: config::Options,
|
||||||
let working_dir = match env::current_dir() {
|
let working_dir = match env::current_dir() {
|
||||||
Ok(dir) => dir,
|
Ok(dir) => dir,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
panic!(p_s.span_diagnostic.fatal(&format!("Current directory is invalid: {}", e)))
|
p_s.span_diagnostic.fatal(&format!("Current directory is invalid: {}", e)).raise()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let working_dir = file_path_mapping.map_prefix(working_dir);
|
let working_dir = file_path_mapping.map_prefix(working_dir);
|
||||||
|
@ -1076,7 +1076,7 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
|
||||||
};
|
};
|
||||||
let handler = errors::Handler::with_emitter(true, false, emitter);
|
let handler = errors::Handler::with_emitter(true, false, emitter);
|
||||||
handler.emit(&MultiSpan::new(), msg, errors::Level::Fatal);
|
handler.emit(&MultiSpan::new(), msg, errors::Level::Fatal);
|
||||||
panic!(errors::FatalError);
|
errors::FatalError.raise();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
|
pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
|
||||||
|
|
|
@ -87,11 +87,11 @@ use std::env;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::io::{self, Read, Write};
|
use std::io::{self, Read, Write};
|
||||||
use std::iter::repeat;
|
use std::iter::repeat;
|
||||||
|
use std::panic;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::{self, Command, Stdio};
|
use std::process::{self, Command, Stdio};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::sync::{Arc, Mutex};
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
|
@ -168,7 +168,7 @@ pub fn run<F>(run_compiler: F) -> isize
|
||||||
handler.emit(&MultiSpan::new(),
|
handler.emit(&MultiSpan::new(),
|
||||||
"aborting due to previous error(s)",
|
"aborting due to previous error(s)",
|
||||||
errors::Level::Fatal);
|
errors::Level::Fatal);
|
||||||
exit_on_err();
|
panic::resume_unwind(Box::new(errors::FatalErrorMarker));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1228,27 +1228,16 @@ pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<Any + Send>>
|
||||||
/// The diagnostic emitter yielded to the procedure should be used for reporting
|
/// The diagnostic emitter yielded to the procedure should be used for reporting
|
||||||
/// errors of the compiler.
|
/// errors of the compiler.
|
||||||
pub fn monitor<F: FnOnce() + Send + 'static>(f: F) {
|
pub fn monitor<F: FnOnce() + Send + 'static>(f: F) {
|
||||||
struct Sink(Arc<Mutex<Vec<u8>>>);
|
|
||||||
impl Write for Sink {
|
|
||||||
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
|
|
||||||
Write::write(&mut *self.0.lock().unwrap(), data)
|
|
||||||
}
|
|
||||||
fn flush(&mut self) -> io::Result<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let data = Arc::new(Mutex::new(Vec::new()));
|
|
||||||
let err = Sink(data.clone());
|
|
||||||
|
|
||||||
let result = in_rustc_thread(move || {
|
let result = in_rustc_thread(move || {
|
||||||
io::set_panic(Some(box err));
|
|
||||||
f()
|
f()
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Err(value) = result {
|
if let Err(value) = result {
|
||||||
// Thread panicked without emitting a fatal diagnostic
|
// Thread panicked without emitting a fatal diagnostic
|
||||||
if !value.is::<errors::FatalError>() {
|
if !value.is::<errors::FatalErrorMarker>() {
|
||||||
|
// Emit a newline
|
||||||
|
eprintln!("");
|
||||||
|
|
||||||
let emitter =
|
let emitter =
|
||||||
Box::new(errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
|
Box::new(errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
|
||||||
None,
|
None,
|
||||||
|
@ -1273,22 +1262,12 @@ pub fn monitor<F: FnOnce() + Send + 'static>(f: F) {
|
||||||
¬e,
|
¬e,
|
||||||
errors::Level::Note);
|
errors::Level::Note);
|
||||||
}
|
}
|
||||||
|
|
||||||
eprintln!("{}", str::from_utf8(&data.lock().unwrap()).unwrap());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exit_on_err();
|
panic::resume_unwind(Box::new(errors::FatalErrorMarker));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exit_on_err() -> ! {
|
|
||||||
// Panic so the process returns a failure code, but don't pollute the
|
|
||||||
// output with some unnecessary panic messages, we've already
|
|
||||||
// printed everything that we needed to.
|
|
||||||
io::set_panic(Some(box io::sink()));
|
|
||||||
panic!();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(stage0)]
|
#[cfg(stage0)]
|
||||||
pub fn diagnostics_registry() -> errors::registry::Registry {
|
pub fn diagnostics_registry() -> errors::registry::Registry {
|
||||||
use errors::registry::Registry;
|
use errors::registry::Registry;
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#![cfg_attr(unix, feature(libc))]
|
#![cfg_attr(unix, feature(libc))]
|
||||||
#![feature(conservative_impl_trait)]
|
#![feature(conservative_impl_trait)]
|
||||||
#![feature(i128_type)]
|
#![feature(i128_type)]
|
||||||
|
#![feature(optin_builtin_traits)]
|
||||||
|
|
||||||
extern crate term;
|
extern crate term;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
@ -44,6 +45,7 @@ use std::rc::Rc;
|
||||||
use std::{error, fmt};
|
use std::{error, fmt};
|
||||||
use std::sync::atomic::AtomicUsize;
|
use std::sync::atomic::AtomicUsize;
|
||||||
use std::sync::atomic::Ordering::SeqCst;
|
use std::sync::atomic::Ordering::SeqCst;
|
||||||
|
use std::panic;
|
||||||
|
|
||||||
mod diagnostic;
|
mod diagnostic;
|
||||||
mod diagnostic_builder;
|
mod diagnostic_builder;
|
||||||
|
@ -201,6 +203,18 @@ impl CodeSuggestion {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub struct FatalError;
|
pub struct FatalError;
|
||||||
|
|
||||||
|
pub struct FatalErrorMarker;
|
||||||
|
|
||||||
|
// Don't implement Send on FatalError. This makes it impossible to panic!(FatalError).
|
||||||
|
// We don't want to invoke the panic handler and print a backtrace for fatal errors.
|
||||||
|
impl !Send for FatalError {}
|
||||||
|
|
||||||
|
impl FatalError {
|
||||||
|
pub fn raise(self) -> ! {
|
||||||
|
panic::resume_unwind(Box::new(FatalErrorMarker))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Display for FatalError {
|
impl fmt::Display for FatalError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
write!(f, "parser fatal error")
|
write!(f, "parser fatal error")
|
||||||
|
@ -539,7 +553,7 @@ impl Handler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
panic!(self.fatal(&s));
|
self.fatal(&s).raise();
|
||||||
}
|
}
|
||||||
pub fn emit(&self, msp: &MultiSpan, msg: &str, lvl: Level) {
|
pub fn emit(&self, msp: &MultiSpan, msg: &str, lvl: Level) {
|
||||||
if lvl == Warning && !self.flags.can_emit_warnings {
|
if lvl == Warning && !self.flags.can_emit_warnings {
|
||||||
|
|
|
@ -155,7 +155,7 @@ fn get_llvm_opt_size(optimize: config::OptLevel) -> llvm::CodeGenOptSize {
|
||||||
|
|
||||||
pub fn create_target_machine(sess: &Session) -> TargetMachineRef {
|
pub fn create_target_machine(sess: &Session) -> TargetMachineRef {
|
||||||
target_machine_factory(sess)().unwrap_or_else(|err| {
|
target_machine_factory(sess)().unwrap_or_else(|err| {
|
||||||
panic!(llvm_err(sess.diagnostic(), err))
|
llvm_err(sess.diagnostic(), err).raise()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -582,7 +582,7 @@ fn generate_lto_work(cgcx: &CodegenContext,
|
||||||
lto::LTOMode::JustThisCrate
|
lto::LTOMode::JustThisCrate
|
||||||
};
|
};
|
||||||
let lto_modules = lto::run(cgcx, modules, mode, &mut timeline)
|
let lto_modules = lto::run(cgcx, modules, mode, &mut timeline)
|
||||||
.unwrap_or_else(|e| panic!(e));
|
.unwrap_or_else(|e| e.raise());
|
||||||
|
|
||||||
lto_modules.into_iter().map(|module| {
|
lto_modules.into_iter().map(|module| {
|
||||||
let cost = module.cost();
|
let cost = module.cost();
|
||||||
|
|
|
@ -786,7 +786,7 @@ impl<'a> ExtCtxt<'a> {
|
||||||
/// substitute; we never hit resolve/type-checking so the dummy
|
/// substitute; we never hit resolve/type-checking so the dummy
|
||||||
/// value doesn't have to match anything)
|
/// value doesn't have to match anything)
|
||||||
pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
|
pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
|
||||||
panic!(self.parse_sess.span_diagnostic.span_fatal(sp, msg));
|
self.parse_sess.span_diagnostic.span_fatal(sp, msg).raise();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Emit `msg` attached to `sp`, without immediately stopping
|
/// Emit `msg` attached to `sp`, without immediately stopping
|
||||||
|
|
|
@ -455,7 +455,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
suggested_limit));
|
suggested_limit));
|
||||||
err.emit();
|
err.emit();
|
||||||
self.cx.trace_macros_diag();
|
self.cx.trace_macros_diag();
|
||||||
panic!(FatalError);
|
FatalError.raise();
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(result)
|
Some(result)
|
||||||
|
|
|
@ -116,9 +116,10 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[tokenstream::T
|
||||||
while self.p.token != token::Eof {
|
while self.p.token != token::Eof {
|
||||||
match panictry!(self.p.parse_item()) {
|
match panictry!(self.p.parse_item()) {
|
||||||
Some(item) => ret.push(item),
|
Some(item) => ret.push(item),
|
||||||
None => panic!(self.p.diagnostic().span_fatal(self.p.span,
|
None => self.p.diagnostic().span_fatal(self.p.span,
|
||||||
&format!("expected item, found `{}`",
|
&format!("expected item, found `{}`",
|
||||||
self.p.this_token_to_string())))
|
self.p.this_token_to_string()))
|
||||||
|
.raise()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(ret)
|
Some(ret)
|
||||||
|
|
|
@ -573,7 +573,7 @@ fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
|
||||||
Some(i) => token::NtItem(i),
|
Some(i) => token::NtItem(i),
|
||||||
None => {
|
None => {
|
||||||
p.fatal("expected an item keyword").emit();
|
p.fatal("expected an item keyword").emit();
|
||||||
panic!(FatalError);
|
FatalError.raise();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"block" => token::NtBlock(panictry!(p.parse_block())),
|
"block" => token::NtBlock(panictry!(p.parse_block())),
|
||||||
|
@ -581,7 +581,7 @@ fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
|
||||||
Some(s) => token::NtStmt(s),
|
Some(s) => token::NtStmt(s),
|
||||||
None => {
|
None => {
|
||||||
p.fatal("expected a statement").emit();
|
p.fatal("expected a statement").emit();
|
||||||
panic!(FatalError);
|
FatalError.raise();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"pat" => token::NtPat(panictry!(p.parse_pat())),
|
"pat" => token::NtPat(panictry!(p.parse_pat())),
|
||||||
|
@ -597,7 +597,7 @@ fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
|
||||||
let token_str = pprust::token_to_string(&p.token);
|
let token_str = pprust::token_to_string(&p.token);
|
||||||
p.fatal(&format!("expected ident, found {}",
|
p.fatal(&format!("expected ident, found {}",
|
||||||
&token_str[..])).emit();
|
&token_str[..])).emit();
|
||||||
panic!(FatalError)
|
FatalError.raise()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"path" => token::NtPath(panictry!(p.parse_path_common(PathStyle::Type, false))),
|
"path" => token::NtPath(panictry!(p.parse_path_common(PathStyle::Type, false))),
|
||||||
|
|
|
@ -222,10 +222,10 @@ pub fn compile(sess: &ParseSess, features: &RefCell<Features>, def: &ast::Item)
|
||||||
Success(m) => m,
|
Success(m) => m,
|
||||||
Failure(sp, tok) => {
|
Failure(sp, tok) => {
|
||||||
let s = parse_failure_msg(tok);
|
let s = parse_failure_msg(tok);
|
||||||
panic!(sess.span_diagnostic.span_fatal(sp.substitute_dummy(def.span), &s));
|
sess.span_diagnostic.span_fatal(sp.substitute_dummy(def.span), &s).raise();
|
||||||
}
|
}
|
||||||
Error(sp, s) => {
|
Error(sp, s) => {
|
||||||
panic!(sess.span_diagnostic.span_fatal(sp.substitute_dummy(def.span), &s));
|
sess.span_diagnostic.span_fatal(sp.substitute_dummy(def.span), &s).raise();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1954,7 +1954,7 @@ impl FeatureChecker {
|
||||||
.span_note(ca_span, "`#![feature(custom_attribute)]` declared here")
|
.span_note(ca_span, "`#![feature(custom_attribute)]` declared here")
|
||||||
.emit();
|
.emit();
|
||||||
|
|
||||||
panic!(FatalError);
|
FatalError.raise();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let (Some(span), None) = (self.copy_closures, self.clone_closures) {
|
if let (Some(span), None) = (self.copy_closures, self.clone_closures) {
|
||||||
|
@ -1963,7 +1963,7 @@ impl FeatureChecker {
|
||||||
.span_note(span, "`#![feature(copy_closures)]` declared here")
|
.span_note(span, "`#![feature(copy_closures)]` declared here")
|
||||||
.emit();
|
.emit();
|
||||||
|
|
||||||
panic!(FatalError);
|
FatalError.raise();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ macro_rules! panictry {
|
||||||
Ok(e) => e,
|
Ok(e) => e,
|
||||||
Err(mut e) => {
|
Err(mut e) => {
|
||||||
e.emit();
|
e.emit();
|
||||||
panic!(FatalError);
|
FatalError.raise()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -265,7 +265,7 @@ fn read_block_comment(rdr: &mut StringReader,
|
||||||
while level > 0 {
|
while level > 0 {
|
||||||
debug!("=== block comment level {}", level);
|
debug!("=== block comment level {}", level);
|
||||||
if rdr.is_eof() {
|
if rdr.is_eof() {
|
||||||
panic!(rdr.fatal("unterminated block comment"));
|
rdr.fatal("unterminated block comment").raise();
|
||||||
}
|
}
|
||||||
if rdr.ch_is('\n') {
|
if rdr.ch_is('\n') {
|
||||||
trim_whitespace_prefix_and_push_line(&mut lines, curr_line, col);
|
trim_whitespace_prefix_and_push_line(&mut lines, curr_line, col);
|
||||||
|
|
|
@ -90,7 +90,7 @@ impl<'a> StringReader<'a> {
|
||||||
Ok(tok) => tok,
|
Ok(tok) => tok,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
self.emit_fatal_errors();
|
self.emit_fatal_errors();
|
||||||
panic!(FatalError);
|
FatalError.raise();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ impl<'a> StringReader<'a> {
|
||||||
let mut sr = StringReader::new_raw(sess, filemap);
|
let mut sr = StringReader::new_raw(sess, filemap);
|
||||||
if sr.advance_token().is_err() {
|
if sr.advance_token().is_err() {
|
||||||
sr.emit_fatal_errors();
|
sr.emit_fatal_errors();
|
||||||
panic!(FatalError);
|
FatalError.raise();
|
||||||
}
|
}
|
||||||
sr
|
sr
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,7 @@ impl<'a> StringReader<'a> {
|
||||||
|
|
||||||
if sr.advance_token().is_err() {
|
if sr.advance_token().is_err() {
|
||||||
sr.emit_fatal_errors();
|
sr.emit_fatal_errors();
|
||||||
panic!(FatalError);
|
FatalError.raise();
|
||||||
}
|
}
|
||||||
sr
|
sr
|
||||||
}
|
}
|
||||||
|
@ -647,7 +647,7 @@ impl<'a> StringReader<'a> {
|
||||||
"unterminated block comment"
|
"unterminated block comment"
|
||||||
};
|
};
|
||||||
let last_bpos = self.pos;
|
let last_bpos = self.pos;
|
||||||
panic!(self.fatal_span_(start_bpos, last_bpos, msg));
|
self.fatal_span_(start_bpos, last_bpos, msg).raise();
|
||||||
}
|
}
|
||||||
let n = self.ch.unwrap();
|
let n = self.ch.unwrap();
|
||||||
match n {
|
match n {
|
||||||
|
@ -808,9 +808,9 @@ impl<'a> StringReader<'a> {
|
||||||
for _ in 0..n_digits {
|
for _ in 0..n_digits {
|
||||||
if self.is_eof() {
|
if self.is_eof() {
|
||||||
let last_bpos = self.pos;
|
let last_bpos = self.pos;
|
||||||
panic!(self.fatal_span_(start_bpos,
|
self.fatal_span_(start_bpos,
|
||||||
last_bpos,
|
last_bpos,
|
||||||
"unterminated numeric character escape"));
|
"unterminated numeric character escape").raise();
|
||||||
}
|
}
|
||||||
if self.ch_is(delim) {
|
if self.ch_is(delim) {
|
||||||
let last_bpos = self.pos;
|
let last_bpos = self.pos;
|
||||||
|
@ -1025,9 +1025,9 @@ impl<'a> StringReader<'a> {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
panic!(self.fatal_span_(start_bpos,
|
self.fatal_span_(start_bpos,
|
||||||
self.pos,
|
self.pos,
|
||||||
"unterminated unicode escape (found EOF)"));
|
"unterminated unicode escape (found EOF)").raise();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.bump();
|
self.bump();
|
||||||
|
@ -1283,9 +1283,9 @@ impl<'a> StringReader<'a> {
|
||||||
// lifetimes shouldn't end with a single quote
|
// lifetimes shouldn't end with a single quote
|
||||||
// if we find one, then this is an invalid character literal
|
// if we find one, then this is an invalid character literal
|
||||||
if self.ch_is('\'') {
|
if self.ch_is('\'') {
|
||||||
panic!(self.fatal_span_verbose(
|
self.fatal_span_verbose(start_with_quote, self.next_pos,
|
||||||
start_with_quote, self.next_pos,
|
String::from("character literal may only contain one codepoint"))
|
||||||
String::from("character literal may only contain one codepoint")));
|
.raise();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1332,9 +1332,8 @@ impl<'a> StringReader<'a> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
panic!(self.fatal_span_verbose(
|
self.fatal_span_verbose(start_with_quote, pos,
|
||||||
start_with_quote, pos,
|
String::from("character literal may only contain one codepoint")).raise();
|
||||||
String::from("character literal may only contain one codepoint")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let id = if valid {
|
let id = if valid {
|
||||||
|
@ -1364,9 +1363,9 @@ impl<'a> StringReader<'a> {
|
||||||
while !self.ch_is('"') {
|
while !self.ch_is('"') {
|
||||||
if self.is_eof() {
|
if self.is_eof() {
|
||||||
let last_bpos = self.pos;
|
let last_bpos = self.pos;
|
||||||
panic!(self.fatal_span_(start_bpos,
|
self.fatal_span_(start_bpos,
|
||||||
last_bpos,
|
last_bpos,
|
||||||
"unterminated double quote string"));
|
"unterminated double quote string").raise();
|
||||||
}
|
}
|
||||||
|
|
||||||
let ch_start = self.pos;
|
let ch_start = self.pos;
|
||||||
|
@ -1399,15 +1398,15 @@ impl<'a> StringReader<'a> {
|
||||||
|
|
||||||
if self.is_eof() {
|
if self.is_eof() {
|
||||||
let last_bpos = self.pos;
|
let last_bpos = self.pos;
|
||||||
panic!(self.fatal_span_(start_bpos, last_bpos, "unterminated raw string"));
|
self.fatal_span_(start_bpos, last_bpos, "unterminated raw string").raise();
|
||||||
} else if !self.ch_is('"') {
|
} else if !self.ch_is('"') {
|
||||||
let last_bpos = self.pos;
|
let last_bpos = self.pos;
|
||||||
let curr_char = self.ch.unwrap();
|
let curr_char = self.ch.unwrap();
|
||||||
panic!(self.fatal_span_char(start_bpos,
|
self.fatal_span_char(start_bpos,
|
||||||
last_bpos,
|
last_bpos,
|
||||||
"found invalid character; only `#` is allowed \
|
"found invalid character; only `#` is allowed \
|
||||||
in raw string delimitation",
|
in raw string delimitation",
|
||||||
curr_char));
|
curr_char).raise();
|
||||||
}
|
}
|
||||||
self.bump();
|
self.bump();
|
||||||
let content_start_bpos = self.pos;
|
let content_start_bpos = self.pos;
|
||||||
|
@ -1416,7 +1415,7 @@ impl<'a> StringReader<'a> {
|
||||||
'outer: loop {
|
'outer: loop {
|
||||||
if self.is_eof() {
|
if self.is_eof() {
|
||||||
let last_bpos = self.pos;
|
let last_bpos = self.pos;
|
||||||
panic!(self.fatal_span_(start_bpos, last_bpos, "unterminated raw string"));
|
self.fatal_span_(start_bpos, last_bpos, "unterminated raw string").raise();
|
||||||
}
|
}
|
||||||
// if self.ch_is('"') {
|
// if self.ch_is('"') {
|
||||||
// content_end_bpos = self.pos;
|
// content_end_bpos = self.pos;
|
||||||
|
@ -1573,9 +1572,9 @@ impl<'a> StringReader<'a> {
|
||||||
// character before position `start` are an
|
// character before position `start` are an
|
||||||
// ascii single quote and ascii 'b'.
|
// ascii single quote and ascii 'b'.
|
||||||
let pos = self.pos;
|
let pos = self.pos;
|
||||||
panic!(self.fatal_span_verbose(start - BytePos(2),
|
self.fatal_span_verbose(start - BytePos(2),
|
||||||
pos,
|
pos,
|
||||||
"unterminated byte constant".to_string()));
|
"unterminated byte constant".to_string()).raise();
|
||||||
}
|
}
|
||||||
|
|
||||||
let id = if valid {
|
let id = if valid {
|
||||||
|
@ -1599,7 +1598,7 @@ impl<'a> StringReader<'a> {
|
||||||
while !self.ch_is('"') {
|
while !self.ch_is('"') {
|
||||||
if self.is_eof() {
|
if self.is_eof() {
|
||||||
let pos = self.pos;
|
let pos = self.pos;
|
||||||
panic!(self.fatal_span_(start, pos, "unterminated double quote byte string"));
|
self.fatal_span_(start, pos, "unterminated double quote byte string").raise();
|
||||||
}
|
}
|
||||||
|
|
||||||
let ch_start = self.pos;
|
let ch_start = self.pos;
|
||||||
|
@ -1631,15 +1630,15 @@ impl<'a> StringReader<'a> {
|
||||||
|
|
||||||
if self.is_eof() {
|
if self.is_eof() {
|
||||||
let pos = self.pos;
|
let pos = self.pos;
|
||||||
panic!(self.fatal_span_(start_bpos, pos, "unterminated raw string"));
|
self.fatal_span_(start_bpos, pos, "unterminated raw string").raise();
|
||||||
} else if !self.ch_is('"') {
|
} else if !self.ch_is('"') {
|
||||||
let pos = self.pos;
|
let pos = self.pos;
|
||||||
let ch = self.ch.unwrap();
|
let ch = self.ch.unwrap();
|
||||||
panic!(self.fatal_span_char(start_bpos,
|
self.fatal_span_char(start_bpos,
|
||||||
pos,
|
pos,
|
||||||
"found invalid character; only `#` is allowed in raw \
|
"found invalid character; only `#` is allowed in raw \
|
||||||
string delimitation",
|
string delimitation",
|
||||||
ch));
|
ch).raise();
|
||||||
}
|
}
|
||||||
self.bump();
|
self.bump();
|
||||||
let content_start_bpos = self.pos;
|
let content_start_bpos = self.pos;
|
||||||
|
@ -1648,7 +1647,7 @@ impl<'a> StringReader<'a> {
|
||||||
match self.ch {
|
match self.ch {
|
||||||
None => {
|
None => {
|
||||||
let pos = self.pos;
|
let pos = self.pos;
|
||||||
panic!(self.fatal_span_(start_bpos, pos, "unterminated raw string"))
|
self.fatal_span_(start_bpos, pos, "unterminated raw string").raise()
|
||||||
}
|
}
|
||||||
Some('"') => {
|
Some('"') => {
|
||||||
content_end_bpos = self.pos;
|
content_end_bpos = self.pos;
|
||||||
|
|
|
@ -212,8 +212,8 @@ fn file_to_filemap(sess: &ParseSess, path: &Path, spanopt: Option<Span>)
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let msg = format!("couldn't read {:?}: {}", path.display(), e);
|
let msg = format!("couldn't read {:?}: {}", path.display(), e);
|
||||||
match spanopt {
|
match spanopt {
|
||||||
Some(sp) => panic!(sess.span_diagnostic.span_fatal(sp, &msg)),
|
Some(sp) => sess.span_diagnostic.span_fatal(sp, &msg).raise(),
|
||||||
None => panic!(sess.span_diagnostic.fatal(&msg))
|
None => sess.span_diagnostic.fatal(&msg).raise()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
|
||||||
match i.node {
|
match i.node {
|
||||||
ast::ItemKind::Fn(_, ast::Unsafety::Unsafe, _, _, _, _) => {
|
ast::ItemKind::Fn(_, ast::Unsafety::Unsafe, _, _, _, _) => {
|
||||||
let diag = self.cx.span_diagnostic;
|
let diag = self.cx.span_diagnostic;
|
||||||
panic!(diag.span_fatal(i.span, "unsafe functions cannot be used for tests"));
|
diag.span_fatal(i.span, "unsafe functions cannot be used for tests").raise();
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
debug!("this is a test function");
|
debug!("this is a test function");
|
||||||
|
|
|
@ -92,7 +92,7 @@ impl MultiItemModifier for ProcMacroDerive {
|
||||||
}
|
}
|
||||||
|
|
||||||
err.emit();
|
err.emit();
|
||||||
panic!(FatalError);
|
FatalError.raise();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -103,13 +103,13 @@ impl MultiItemModifier for ProcMacroDerive {
|
||||||
// fail if there have been errors emitted
|
// fail if there have been errors emitted
|
||||||
Ok(_) if ecx.parse_sess.span_diagnostic.err_count() > error_count_before => {
|
Ok(_) if ecx.parse_sess.span_diagnostic.err_count() > error_count_before => {
|
||||||
ecx.struct_span_fatal(span, msg).emit();
|
ecx.struct_span_fatal(span, msg).emit();
|
||||||
panic!(FatalError);
|
FatalError.raise();
|
||||||
}
|
}
|
||||||
Ok(new_items) => new_items.into_iter().map(Annotatable::Item).collect(),
|
Ok(new_items) => new_items.into_iter().map(Annotatable::Item).collect(),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// FIXME: handle this better
|
// FIXME: handle this better
|
||||||
ecx.struct_span_fatal(span, msg).emit();
|
ecx.struct_span_fatal(span, msg).emit();
|
||||||
panic!(FatalError);
|
FatalError.raise();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -51,7 +51,7 @@ impl base::AttrProcMacro for AttrProcMacro {
|
||||||
}
|
}
|
||||||
|
|
||||||
err.emit();
|
err.emit();
|
||||||
panic!(FatalError);
|
FatalError.raise();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ impl base::ProcMacro for BangProcMacro {
|
||||||
}
|
}
|
||||||
|
|
||||||
err.emit();
|
err.emit();
|
||||||
panic!(FatalError);
|
FatalError.raise();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue