Skip to content

Commit 7a5a1f9

Browse files
committed
use -Z flag instead of env var
1 parent bec62c2 commit 7a5a1f9

33 files changed

+83
-63
lines changed

src/librustc/session/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
10361036
"run all passes except translation; no output"),
10371037
treat_err_as_bug: bool = (false, parse_bool, [TRACKED],
10381038
"treat all errors that occur as bugs"),
1039+
macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
1040+
"show macro backtraces even for foreign macros"),
10391041
continue_parse_after_error: bool = (false, parse_bool, [TRACKED],
10401042
"attempt to recover from parse errors (experimental)"),
10411043
incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],

src/librustc/session/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,8 @@ pub fn build_session_with_codemap(sopts: config::Options,
731731

732732
let treat_err_as_bug = sopts.debugging_opts.treat_err_as_bug;
733733

734+
let macro_backtrace = sopts.debugging_opts.macro_backtrace;
735+
734736
let emitter: Box<Emitter> = match (sopts.error_format, emitter_dest) {
735737
(config::ErrorOutputType::HumanReadable(color_config), None) => {
736738
Box::new(EmitterWriter::stderr(color_config, Some(codemap.clone()), false))
@@ -755,6 +757,7 @@ pub fn build_session_with_codemap(sopts: config::Options,
755757
let diagnostic_handler =
756758
errors::Handler::with_emitter(can_print_warnings,
757759
treat_err_as_bug,
760+
macro_backtrace,
758761
emitter);
759762

760763
build_session_(sopts,
@@ -925,7 +928,7 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
925928
Box::new(EmitterWriter::stderr(color_config, None, true))
926929
}
927930
};
928-
let handler = errors::Handler::with_emitter(true, false, emitter);
931+
let handler = errors::Handler::with_emitter(true, false, false, emitter);
929932
handler.emit(&MultiSpan::new(), msg, errors::Level::Fatal);
930933
panic!(errors::FatalError);
931934
}
@@ -940,7 +943,7 @@ pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
940943
Box::new(EmitterWriter::stderr(color_config, None, true))
941944
}
942945
};
943-
let handler = errors::Handler::with_emitter(true, false, emitter);
946+
let handler = errors::Handler::with_emitter(true, false, false, emitter);
944947
handler.emit(&MultiSpan::new(), msg, errors::Level::Warning);
945948
}
946949

src/librustc_driver/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ pub fn run<F>(run_compiler: F) -> isize
141141
errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
142142
None,
143143
true);
144-
let handler = errors::Handler::with_emitter(true, false, Box::new(emitter));
144+
let handler = errors::Handler::with_emitter(true, false, false, Box::new(emitter));
145145
handler.emit(&MultiSpan::new(),
146146
"aborting due to previous error(s)",
147147
errors::Level::Fatal);
@@ -1221,7 +1221,7 @@ pub fn monitor<F: FnOnce() + Send + 'static>(f: F) {
12211221
Box::new(errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
12221222
None,
12231223
false));
1224-
let handler = errors::Handler::with_emitter(true, false, emitter);
1224+
let handler = errors::Handler::with_emitter(true, false, false, emitter);
12251225

12261226
// a .span_bug or .bug call has already printed what
12271227
// it wants to print.

src/librustc_driver/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fn test_env<F>(source_string: &str,
104104
let mut options = config::basic_options();
105105
options.debugging_opts.verbose = true;
106106
options.unstable_features = UnstableFeatures::Allow;
107-
let diagnostic_handler = errors::Handler::with_emitter(true, false, emitter);
107+
let diagnostic_handler = errors::Handler::with_emitter(true, false, false, emitter);
108108

109109
let cstore = Rc::new(CStore::new(::DefaultTransCrate::metadata_loader()));
110110
let sess = session::build_session_(options,

src/librustc_errors/diagnostic_builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use syntax_pos::{MultiSpan, Span};
2323
#[must_use]
2424
#[derive(Clone)]
2525
pub struct DiagnosticBuilder<'a> {
26-
handler: &'a Handler,
26+
pub handler: &'a Handler,
2727
diagnostic: Diagnostic,
2828
}
2929

src/librustc_errors/emitter.rs

+30-21
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use std::rc::Rc;
2323
use term;
2424
use std::collections::HashMap;
2525
use std::cmp::min;
26-
use std::env;
2726

2827
/// Emitter trait for emitting errors.
2928
pub trait Emitter {
@@ -65,8 +64,11 @@ impl Emitter for EmitterWriter {
6564
}
6665
}
6766

68-
self.fix_multispans_in_std_macros(&mut primary_span, &mut children);
67+
if !db.handler.macro_backtrace {
68+
self.fix_multispans_in_std_macros(&mut primary_span, &mut children);
69+
}
6970
self.emit_messages_default(&db.level,
71+
db.handler.macro_backtrace,
7072
&db.styled_message(),
7173
&db.code,
7274
&primary_span,
@@ -787,23 +789,21 @@ impl EmitterWriter {
787789
fn fix_multispans_in_std_macros(&mut self,
788790
span: &mut MultiSpan,
789791
children: &mut Vec<SubDiagnostic>) {
790-
if env::var_os("RUST_MACRO_BACKTRACE").is_none() {
791-
let mut spans_updated = self.fix_multispan_in_std_macros(span);
792-
for child in children.iter_mut() {
793-
spans_updated |= self.fix_multispan_in_std_macros(&mut child.span);
794-
}
795-
if spans_updated {
796-
children.push(SubDiagnostic {
797-
level: Level::Note,
798-
message: vec![
799-
(["this error originates in a macro outside of the current crate",
800-
"(run with RUST_MACRO_BACKTRACE=1 for more info)"].join(" "),
801-
Style::NoStyle),
802-
],
803-
span: MultiSpan::new(),
804-
render_span: None,
805-
});
806-
}
792+
let mut spans_updated = self.fix_multispan_in_std_macros(span);
793+
for child in children.iter_mut() {
794+
spans_updated |= self.fix_multispan_in_std_macros(&mut child.span);
795+
}
796+
if spans_updated {
797+
children.push(SubDiagnostic {
798+
level: Level::Note,
799+
message: vec![
800+
(["this error originates in a macro outside of the current crate",
801+
"(run with -Z macro-backtrace for more info)"].join(" "),
802+
Style::NoStyle),
803+
],
804+
span: MultiSpan::new(),
805+
render_span: None,
806+
});
807807
}
808808
}
809809

@@ -888,6 +888,7 @@ impl EmitterWriter {
888888
msg: &Vec<(String, Style)>,
889889
code: &Option<DiagnosticId>,
890890
level: &Level,
891+
macro_backtrace: bool,
891892
max_line_num_len: usize,
892893
is_secondary: bool)
893894
-> io::Result<()> {
@@ -1085,7 +1086,7 @@ impl EmitterWriter {
10851086
}
10861087
}
10871088

1088-
if env::var_os("RUST_MACRO_BACKTRACE").is_some() {
1089+
if macro_backtrace {
10891090
if let Some(ref primary_span) = msp.primary_span().as_ref() {
10901091
self.render_macro_backtrace_old_school(primary_span, &mut buffer)?;
10911092
}
@@ -1182,6 +1183,7 @@ impl EmitterWriter {
11821183
}
11831184
fn emit_messages_default(&mut self,
11841185
level: &Level,
1186+
macro_backtrace: bool,
11851187
message: &Vec<(String, Style)>,
11861188
code: &Option<DiagnosticId>,
11871189
span: &MultiSpan,
@@ -1190,7 +1192,13 @@ impl EmitterWriter {
11901192
let max_line_num = self.get_max_line_num(span, children);
11911193
let max_line_num_len = max_line_num.to_string().len();
11921194

1193-
match self.emit_message_default(span, message, code, level, max_line_num_len, false) {
1195+
match self.emit_message_default(span,
1196+
message,
1197+
code,
1198+
level,
1199+
macro_backtrace,
1200+
max_line_num_len,
1201+
false) {
11941202
Ok(()) => {
11951203
if !children.is_empty() {
11961204
let mut buffer = StyledBuffer::new();
@@ -1210,6 +1218,7 @@ impl EmitterWriter {
12101218
&child.styled_message(),
12111219
&None,
12121220
&child.level,
1221+
macro_backtrace,
12131222
max_line_num_len,
12141223
true) {
12151224
Err(e) => panic!("failed to emit error: {}", e),

src/librustc_errors/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ pub struct Handler {
237237
emitter: RefCell<Box<Emitter>>,
238238
pub can_emit_warnings: bool,
239239
treat_err_as_bug: bool,
240+
pub macro_backtrace: bool,
240241
continue_after_error: Cell<bool>,
241242
delayed_span_bug: RefCell<Option<Diagnostic>>,
242243
tracked_diagnostics: RefCell<Option<Vec<Diagnostic>>>,
@@ -251,21 +252,24 @@ impl Handler {
251252
pub fn with_tty_emitter(color_config: ColorConfig,
252253
can_emit_warnings: bool,
253254
treat_err_as_bug: bool,
255+
macro_backtrace: bool,
254256
cm: Option<Rc<CodeMapper>>)
255257
-> Handler {
256258
let emitter = Box::new(EmitterWriter::stderr(color_config, cm, false));
257-
Handler::with_emitter(can_emit_warnings, treat_err_as_bug, emitter)
259+
Handler::with_emitter(can_emit_warnings, treat_err_as_bug, macro_backtrace, emitter)
258260
}
259261

260262
pub fn with_emitter(can_emit_warnings: bool,
261263
treat_err_as_bug: bool,
264+
macro_backtrace: bool,
262265
e: Box<Emitter>)
263266
-> Handler {
264267
Handler {
265268
err_count: Cell::new(0),
266269
emitter: RefCell::new(e),
267270
can_emit_warnings,
268271
treat_err_as_bug,
272+
macro_backtrace,
269273
continue_after_error: Cell::new(true),
270274
delayed_span_bug: RefCell::new(None),
271275
tracked_diagnostics: RefCell::new(None),

src/librustc_trans/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ pub struct CodegenContext {
353353

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

359359
pub fn config(&self, kind: ModuleKind) -> &ModuleConfig {

src/librustdoc/core.rs

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ pub fn run_core(search_paths: SearchPaths,
141141
let diagnostic_handler = errors::Handler::with_tty_emitter(ColorConfig::Auto,
142142
true,
143143
false,
144+
false,
144145
Some(codemap.clone()));
145146

146147
let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));

src/librustdoc/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn run(input: &str,
8181

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

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

246246
// Compile the code
247-
let diagnostic_handler = errors::Handler::with_emitter(true, false, box emitter);
247+
let diagnostic_handler = errors::Handler::with_emitter(true, false, false, box emitter);
248248

249249
let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));
250250
let mut sess = session::build_session_(

src/libsyntax/parse/lexer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,7 @@ mod tests {
17261726
Some(cm.clone()),
17271727
false);
17281728
ParseSess {
1729-
span_diagnostic: errors::Handler::with_emitter(true, false, Box::new(emitter)),
1729+
span_diagnostic: errors::Handler::with_emitter(true, false, false, Box::new(emitter)),
17301730
unstable_features: UnstableFeatures::from_environment(),
17311731
config: CrateConfig::new(),
17321732
included_mod_stack: RefCell::new(Vec::new()),

src/libsyntax/parse/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ impl ParseSess {
5858
let handler = Handler::with_tty_emitter(ColorConfig::Auto,
5959
true,
6060
false,
61+
false,
6162
Some(cm.clone()));
6263
ParseSess::with_span_handler(handler, cm)
6364
}

src/libsyntax/test_snippet.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &
6262
let emitter = EmitterWriter::new(Box::new(Shared { data: output.clone() }),
6363
Some(code_map.clone()),
6464
false);
65-
let handler = Handler::with_emitter(true, false, Box::new(emitter));
65+
let handler = Handler::with_emitter(true, false, false, Box::new(emitter));
6666
handler.span_err(msp, "foo");
6767

6868
assert!(expected_output.chars().next() == Some('\n'),

src/test/ui/codemap_tests/bad-format-args.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ error: requires at least a format string argument
44
12 | format!();
55
| ^^^^^^^^^^
66
|
7-
= note: this error originates in a macro outside of the current crate (run with RUST_MACRO_BACKTRACE=1 for more info)
7+
= note: this error originates in a macro outside of the current crate (run with -Z macro-backtrace for more info)
88

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

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

2525
error: aborting due to 3 previous errors
2626

src/test/ui/codemap_tests/issue-28308.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0600]: cannot apply unary operator `!` to type `&'static str`
44
12 | assert!("foo");
55
| ^^^^^^^^^^^^^^^
66
|
7-
= note: this error originates in a macro outside of the current crate (run with RUST_MACRO_BACKTRACE=1 for more info)
7+
= note: this error originates in a macro outside of the current crate (run with -Z macro-backtrace for more info)
88

99
error: aborting due to previous error
1010

src/test/ui/cross-crate-macro-backtrace/main.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: 1 positional argument in format string, but no arguments were given
44
16 | myprintln!("{}"); //~ ERROR in this macro
55
| ^^^^^^^^^^^^^^^^^
66
|
7-
= note: this error originates in a macro outside of the current crate (run with RUST_MACRO_BACKTRACE=1 for more info)
7+
= note: this error originates in a macro outside of the current crate (run with -Z macro-backtrace for more info)
88

99
error: aborting due to previous error
1010

src/test/ui/fmt/format-string-error.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ error: invalid format string: expected `'}'` but string was terminated
55
| ^^^^^^^^^^^^^^
66
|
77
= note: if you intended to print `{`, you can escape it using `{{`
8-
= note: this error originates in a macro outside of the current crate (run with RUST_MACRO_BACKTRACE=1 for more info)
8+
= note: this error originates in a macro outside of the current crate (run with -Z macro-backtrace for more info)
99

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

1919
error: aborting due to 2 previous errors
2020

src/test/ui/lifetimes/borrowck-let-suggestion.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ error[E0597]: borrowed value does not live long enough
99
| - temporary value needs to live until here
1010
|
1111
= note: consider using a `let` binding to increase its lifetime
12-
= note: this error originates in a macro outside of the current crate (run with RUST_MACRO_BACKTRACE=1 for more info)
12+
= note: this error originates in a macro outside of the current crate (run with -Z macro-backtrace for more info)
1313

1414
error: aborting due to previous error
1515

src/test/ui/macro_backtrace/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

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

1515
#[macro_use] extern crate ping;
1616

src/test/ui/macros/format-foreign.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ error: multiple unused formatting arguments
1111
= help: `%.*3$s` should be written as `{:.2$}`
1212
= help: `%s` should be written as `{}`
1313
= note: printf formatting not supported; see the documentation for `std::fmt`
14-
= note: this error originates in a macro outside of the current crate (run with RUST_MACRO_BACKTRACE=1 for more info)
14+
= note: this error originates in a macro outside of the current crate (run with -Z macro-backtrace for more info)
1515

1616
error: argument never used
1717
--> $DIR/format-foreign.rs:13:29

src/test/ui/macros/format-unused-lables.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ error: multiple unused formatting arguments
88
| | unused
99
| unused
1010
|
11-
= note: this error originates in a macro outside of the current crate (run with RUST_MACRO_BACKTRACE=1 for more info)
11+
= note: this error originates in a macro outside of the current crate (run with -Z macro-backtrace for more info)
1212

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

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

5252
error: aborting due to 4 previous errors
5353

0 commit comments

Comments
 (0)