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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 5 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 30 additions & 21 deletions
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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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_(

0 commit comments

Comments
 (0)