Skip to content

Commit

Permalink
use -Z flag instead of env var
Browse files Browse the repository at this point in the history
  • Loading branch information
durka committed Nov 19, 2017
1 parent bec62c2 commit 7a5a1f9
Show file tree
Hide file tree
Showing 33 changed files with 83 additions and 63 deletions.
2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Expand Up @@ -1036,6 +1036,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"run all passes except translation; no output"),
treat_err_as_bug: bool = (false, parse_bool, [TRACKED],
"treat all errors that occur as bugs"),
macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
"show macro backtraces even for foreign macros"),
continue_parse_after_error: bool = (false, parse_bool, [TRACKED],
"attempt to recover from parse errors (experimental)"),
incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],
Expand Down
7 changes: 5 additions & 2 deletions src/librustc/session/mod.rs
Expand Up @@ -731,6 +731,8 @@ pub fn build_session_with_codemap(sopts: config::Options,

let treat_err_as_bug = sopts.debugging_opts.treat_err_as_bug;

let macro_backtrace = sopts.debugging_opts.macro_backtrace;

let emitter: Box<Emitter> = match (sopts.error_format, emitter_dest) {
(config::ErrorOutputType::HumanReadable(color_config), None) => {
Box::new(EmitterWriter::stderr(color_config, Some(codemap.clone()), false))
Expand All @@ -755,6 +757,7 @@ pub fn build_session_with_codemap(sopts: config::Options,
let diagnostic_handler =
errors::Handler::with_emitter(can_print_warnings,
treat_err_as_bug,
macro_backtrace,
emitter);

build_session_(sopts,
Expand Down Expand Up @@ -925,7 +928,7 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
Box::new(EmitterWriter::stderr(color_config, None, true))
}
};
let handler = errors::Handler::with_emitter(true, false, emitter);
let handler = errors::Handler::with_emitter(true, false, false, emitter);
handler.emit(&MultiSpan::new(), msg, errors::Level::Fatal);
panic!(errors::FatalError);
}
Expand All @@ -940,7 +943,7 @@ pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
Box::new(EmitterWriter::stderr(color_config, None, true))
}
};
let handler = errors::Handler::with_emitter(true, false, emitter);
let handler = errors::Handler::with_emitter(true, false, false, emitter);
handler.emit(&MultiSpan::new(), msg, errors::Level::Warning);
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_driver/lib.rs
Expand Up @@ -141,7 +141,7 @@ pub fn run<F>(run_compiler: F) -> isize
errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
None,
true);
let handler = errors::Handler::with_emitter(true, false, Box::new(emitter));
let handler = errors::Handler::with_emitter(true, false, false, Box::new(emitter));
handler.emit(&MultiSpan::new(),
"aborting due to previous error(s)",
errors::Level::Fatal);
Expand Down Expand Up @@ -1221,7 +1221,7 @@ pub fn monitor<F: FnOnce() + Send + 'static>(f: F) {
Box::new(errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
None,
false));
let handler = errors::Handler::with_emitter(true, false, emitter);
let handler = errors::Handler::with_emitter(true, false, false, emitter);

// a .span_bug or .bug call has already printed what
// it wants to print.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/test.rs
Expand Up @@ -104,7 +104,7 @@ fn test_env<F>(source_string: &str,
let mut options = config::basic_options();
options.debugging_opts.verbose = true;
options.unstable_features = UnstableFeatures::Allow;
let diagnostic_handler = errors::Handler::with_emitter(true, false, emitter);
let diagnostic_handler = errors::Handler::with_emitter(true, false, false, emitter);

let cstore = Rc::new(CStore::new(::DefaultTransCrate::metadata_loader()));
let sess = session::build_session_(options,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_errors/diagnostic_builder.rs
Expand Up @@ -23,7 +23,7 @@ use syntax_pos::{MultiSpan, Span};
#[must_use]
#[derive(Clone)]
pub struct DiagnosticBuilder<'a> {
handler: &'a Handler,
pub handler: &'a Handler,
diagnostic: Diagnostic,
}

Expand Down
51 changes: 30 additions & 21 deletions src/librustc_errors/emitter.rs
Expand Up @@ -23,7 +23,6 @@ use std::rc::Rc;
use term;
use std::collections::HashMap;
use std::cmp::min;
use std::env;

/// Emitter trait for emitting errors.
pub trait Emitter {
Expand Down Expand Up @@ -65,8 +64,11 @@ impl Emitter for EmitterWriter {
}
}

self.fix_multispans_in_std_macros(&mut primary_span, &mut children);
if !db.handler.macro_backtrace {
self.fix_multispans_in_std_macros(&mut primary_span, &mut children);
}
self.emit_messages_default(&db.level,
db.handler.macro_backtrace,
&db.styled_message(),
&db.code,
&primary_span,
Expand Down Expand Up @@ -787,23 +789,21 @@ impl EmitterWriter {
fn fix_multispans_in_std_macros(&mut self,
span: &mut MultiSpan,
children: &mut Vec<SubDiagnostic>) {
if env::var_os("RUST_MACRO_BACKTRACE").is_none() {
let mut spans_updated = self.fix_multispan_in_std_macros(span);
for child in children.iter_mut() {
spans_updated |= self.fix_multispan_in_std_macros(&mut child.span);
}
if spans_updated {
children.push(SubDiagnostic {
level: Level::Note,
message: vec![
(["this error originates in a macro outside of the current crate",
"(run with RUST_MACRO_BACKTRACE=1 for more info)"].join(" "),
Style::NoStyle),
],
span: MultiSpan::new(),
render_span: None,
});
}
let mut spans_updated = self.fix_multispan_in_std_macros(span);
for child in children.iter_mut() {
spans_updated |= self.fix_multispan_in_std_macros(&mut child.span);
}
if spans_updated {
children.push(SubDiagnostic {
level: Level::Note,
message: vec![
(["this error originates in a macro outside of the current crate",
"(run with -Z macro-backtrace for more info)"].join(" "),
Style::NoStyle),
],
span: MultiSpan::new(),
render_span: None,
});
}
}

Expand Down Expand Up @@ -888,6 +888,7 @@ impl EmitterWriter {
msg: &Vec<(String, Style)>,
code: &Option<DiagnosticId>,
level: &Level,
macro_backtrace: bool,
max_line_num_len: usize,
is_secondary: bool)
-> io::Result<()> {
Expand Down Expand Up @@ -1085,7 +1086,7 @@ impl EmitterWriter {
}
}

if env::var_os("RUST_MACRO_BACKTRACE").is_some() {
if macro_backtrace {
if let Some(ref primary_span) = msp.primary_span().as_ref() {
self.render_macro_backtrace_old_school(primary_span, &mut buffer)?;
}
Expand Down Expand Up @@ -1182,6 +1183,7 @@ impl EmitterWriter {
}
fn emit_messages_default(&mut self,
level: &Level,
macro_backtrace: bool,
message: &Vec<(String, Style)>,
code: &Option<DiagnosticId>,
span: &MultiSpan,
Expand All @@ -1190,7 +1192,13 @@ impl EmitterWriter {
let max_line_num = self.get_max_line_num(span, children);
let max_line_num_len = max_line_num.to_string().len();

match self.emit_message_default(span, message, code, level, max_line_num_len, false) {
match self.emit_message_default(span,
message,
code,
level,
macro_backtrace,
max_line_num_len,
false) {
Ok(()) => {
if !children.is_empty() {
let mut buffer = StyledBuffer::new();
Expand All @@ -1210,6 +1218,7 @@ impl EmitterWriter {
&child.styled_message(),
&None,
&child.level,
macro_backtrace,
max_line_num_len,
true) {
Err(e) => panic!("failed to emit error: {}", e),
Expand Down
6 changes: 5 additions & 1 deletion src/librustc_errors/lib.rs
Expand Up @@ -237,6 +237,7 @@ pub struct Handler {
emitter: RefCell<Box<Emitter>>,
pub can_emit_warnings: bool,
treat_err_as_bug: bool,
pub macro_backtrace: bool,
continue_after_error: Cell<bool>,
delayed_span_bug: RefCell<Option<Diagnostic>>,
tracked_diagnostics: RefCell<Option<Vec<Diagnostic>>>,
Expand All @@ -251,21 +252,24 @@ impl Handler {
pub fn with_tty_emitter(color_config: ColorConfig,
can_emit_warnings: bool,
treat_err_as_bug: bool,
macro_backtrace: bool,
cm: Option<Rc<CodeMapper>>)
-> Handler {
let emitter = Box::new(EmitterWriter::stderr(color_config, cm, false));
Handler::with_emitter(can_emit_warnings, treat_err_as_bug, emitter)
Handler::with_emitter(can_emit_warnings, treat_err_as_bug, macro_backtrace, emitter)
}

pub fn with_emitter(can_emit_warnings: bool,
treat_err_as_bug: bool,
macro_backtrace: bool,
e: Box<Emitter>)
-> Handler {
Handler {
err_count: Cell::new(0),
emitter: RefCell::new(e),
can_emit_warnings,
treat_err_as_bug,
macro_backtrace,
continue_after_error: Cell::new(true),
delayed_span_bug: RefCell::new(None),
tracked_diagnostics: RefCell::new(None),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/back/write.rs
Expand Up @@ -353,7 +353,7 @@ pub struct CodegenContext {

impl CodegenContext {
pub fn create_diag_handler(&self) -> Handler {
Handler::with_emitter(true, false, Box::new(self.diag_emitter.clone()))
Handler::with_emitter(true, false, false, Box::new(self.diag_emitter.clone()))
}

pub fn config(&self, kind: ModuleKind) -> &ModuleConfig {
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/core.rs
Expand Up @@ -141,6 +141,7 @@ pub fn run_core(search_paths: SearchPaths,
let diagnostic_handler = errors::Handler::with_tty_emitter(ColorConfig::Auto,
true,
false,
false,
Some(codemap.clone()));

let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/test.rs
Expand Up @@ -81,7 +81,7 @@ pub fn run(input: &str,

let codemap = Rc::new(CodeMap::new(sessopts.file_path_mapping()));
let handler =
errors::Handler::with_tty_emitter(ColorConfig::Auto, true, false, Some(codemap.clone()));
errors::Handler::with_tty_emitter(ColorConfig::Auto, true, false, false, Some(codemap.clone()));

let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));
let mut sess = session::build_session_(
Expand Down Expand Up @@ -244,7 +244,7 @@ fn run_test(test: &str, cratename: &str, filename: &str, cfgs: Vec<String>, libs
let _bomb = Bomb(data.clone(), old.unwrap_or(box io::stdout()));

// Compile the code
let diagnostic_handler = errors::Handler::with_emitter(true, false, box emitter);
let diagnostic_handler = errors::Handler::with_emitter(true, false, false, box emitter);

let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));
let mut sess = session::build_session_(
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/lexer/mod.rs
Expand Up @@ -1726,7 +1726,7 @@ mod tests {
Some(cm.clone()),
false);
ParseSess {
span_diagnostic: errors::Handler::with_emitter(true, false, Box::new(emitter)),
span_diagnostic: errors::Handler::with_emitter(true, false, false, Box::new(emitter)),
unstable_features: UnstableFeatures::from_environment(),
config: CrateConfig::new(),
included_mod_stack: RefCell::new(Vec::new()),
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/parse/mod.rs
Expand Up @@ -58,6 +58,7 @@ impl ParseSess {
let handler = Handler::with_tty_emitter(ColorConfig::Auto,
true,
false,
false,
Some(cm.clone()));
ParseSess::with_span_handler(handler, cm)
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/test_snippet.rs
Expand Up @@ -62,7 +62,7 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &
let emitter = EmitterWriter::new(Box::new(Shared { data: output.clone() }),
Some(code_map.clone()),
false);
let handler = Handler::with_emitter(true, false, Box::new(emitter));
let handler = Handler::with_emitter(true, false, false, Box::new(emitter));
handler.span_err(msp, "foo");

assert!(expected_output.chars().next() == Some('\n'),
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/codemap_tests/bad-format-args.stderr
Expand Up @@ -4,23 +4,23 @@ error: requires at least a format string argument
12 | format!();
| ^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (run with RUST_MACRO_BACKTRACE=1 for more info)
= note: this error originates in a macro outside of the current crate (run with -Z macro-backtrace for more info)

error: expected token: `,`
--> $DIR/bad-format-args.rs:13:5
|
13 | format!("" 1);
| ^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (run with RUST_MACRO_BACKTRACE=1 for more info)
= note: this error originates in a macro outside of the current crate (run with -Z macro-backtrace for more info)

error: expected token: `,`
--> $DIR/bad-format-args.rs:14:5
|
14 | format!("", 1 1);
| ^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (run with RUST_MACRO_BACKTRACE=1 for more info)
= note: this error originates in a macro outside of the current crate (run with -Z macro-backtrace for more info)

error: aborting due to 3 previous errors

2 changes: 1 addition & 1 deletion src/test/ui/codemap_tests/issue-28308.stderr
Expand Up @@ -4,7 +4,7 @@ error[E0600]: cannot apply unary operator `!` to type `&'static str`
12 | assert!("foo");
| ^^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (run with RUST_MACRO_BACKTRACE=1 for more info)
= note: this error originates in a macro outside of the current crate (run with -Z macro-backtrace for more info)

error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/cross-crate-macro-backtrace/main.stderr
Expand Up @@ -4,7 +4,7 @@ error: 1 positional argument in format string, but no arguments were given
16 | myprintln!("{}"); //~ ERROR in this macro
| ^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (run with RUST_MACRO_BACKTRACE=1 for more info)
= note: this error originates in a macro outside of the current crate (run with -Z macro-backtrace for more info)

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/fmt/format-string-error.stderr
Expand Up @@ -5,7 +5,7 @@ error: invalid format string: expected `'}'` but string was terminated
| ^^^^^^^^^^^^^^
|
= note: if you intended to print `{`, you can escape it using `{{`
= note: this error originates in a macro outside of the current crate (run with RUST_MACRO_BACKTRACE=1 for more info)
= note: this error originates in a macro outside of the current crate (run with -Z macro-backtrace for more info)

error: invalid format string: unmatched `}` found
--> $DIR/format-string-error.rs:14:5
Expand All @@ -14,7 +14,7 @@ error: invalid format string: unmatched `}` found
| ^^^^^^^^^^^^^^
|
= note: if you intended to print `}`, you can escape it using `}}`
= note: this error originates in a macro outside of the current crate (run with RUST_MACRO_BACKTRACE=1 for more info)
= note: this error originates in a macro outside of the current crate (run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors

2 changes: 1 addition & 1 deletion src/test/ui/lifetimes/borrowck-let-suggestion.stderr
Expand Up @@ -9,7 +9,7 @@ error[E0597]: borrowed value does not live long enough
| - temporary value needs to live until here
|
= note: consider using a `let` binding to increase its lifetime
= note: this error originates in a macro outside of the current crate (run with RUST_MACRO_BACKTRACE=1 for more info)
= note: this error originates in a macro outside of the current crate (run with -Z macro-backtrace for more info)

error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/macro_backtrace/main.rs
Expand Up @@ -10,7 +10,7 @@

// Test that the macro backtrace facility works
// aux-build:ping.rs
// rustc-env:RUST_MACRO_BACKTRACE
// compile-flags: -Z macro-backtrace

#[macro_use] extern crate ping;

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/macros/format-foreign.stderr
Expand Up @@ -11,7 +11,7 @@ error: multiple unused formatting arguments
= help: `%.*3$s` should be written as `{:.2$}`
= help: `%s` should be written as `{}`
= note: printf formatting not supported; see the documentation for `std::fmt`
= note: this error originates in a macro outside of the current crate (run with RUST_MACRO_BACKTRACE=1 for more info)
= note: this error originates in a macro outside of the current crate (run with -Z macro-backtrace for more info)

error: argument never used
--> $DIR/format-foreign.rs:13:29
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/macros/format-unused-lables.stderr
Expand Up @@ -8,7 +8,7 @@ error: multiple unused formatting arguments
| | unused
| unused
|
= note: this error originates in a macro outside of the current crate (run with RUST_MACRO_BACKTRACE=1 for more info)
= note: this error originates in a macro outside of the current crate (run with -Z macro-backtrace for more info)

error: multiple unused formatting arguments
--> $DIR/format-unused-lables.rs:14:5
Expand All @@ -23,7 +23,7 @@ error: multiple unused formatting arguments
18 | | );
| |______^
|
= note: this error originates in a macro outside of the current crate (run with RUST_MACRO_BACKTRACE=1 for more info)
= note: this error originates in a macro outside of the current crate (run with -Z macro-backtrace for more info)

error: named argument never used
--> $DIR/format-unused-lables.rs:20:35
Expand All @@ -47,7 +47,7 @@ error: multiple unused formatting arguments
|
= help: `$STUFF` should be written as `{STUFF}`
= note: shell formatting not supported; see the documentation for `std::fmt`
= note: this error originates in a macro outside of the current crate (run with RUST_MACRO_BACKTRACE=1 for more info)
= note: this error originates in a macro outside of the current crate (run with -Z macro-backtrace for more info)

error: aborting due to 4 previous errors

0 comments on commit 7a5a1f9

Please sign in to comment.