Skip to content

Commit b34a7ff

Browse files
committed
address review comments
1 parent 30a6614 commit b34a7ff

34 files changed

+109
-82
lines changed

src/librustc/session/config.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1036,8 +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"),
1039+
external_macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
1040+
"show macro backtraces even for non-local macros"),
10411041
continue_parse_after_error: bool = (false, parse_bool, [TRACKED],
10421042
"attempt to recover from parse errors (experimental)"),
10431043
incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],
@@ -2102,7 +2102,7 @@ mod tests {
21022102
let registry = errors::registry::Registry::new(&[]);
21032103
let (sessopts, _) = build_session_options_and_crate_config(&matches);
21042104
let sess = build_session(sessopts, None, registry);
2105-
assert!(!sess.diagnostic().can_emit_warnings);
2105+
assert!(!sess.diagnostic().flags.can_emit_warnings);
21062106
}
21072107

21082108
{
@@ -2113,7 +2113,7 @@ mod tests {
21132113
let registry = errors::registry::Registry::new(&[]);
21142114
let (sessopts, _) = build_session_options_and_crate_config(&matches);
21152115
let sess = build_session(sessopts, None, registry);
2116-
assert!(sess.diagnostic().can_emit_warnings);
2116+
assert!(sess.diagnostic().flags.can_emit_warnings);
21172117
}
21182118

21192119
{
@@ -2123,7 +2123,7 @@ mod tests {
21232123
let registry = errors::registry::Registry::new(&[]);
21242124
let (sessopts, _) = build_session_options_and_crate_config(&matches);
21252125
let sess = build_session(sessopts, None, registry);
2126-
assert!(sess.diagnostic().can_emit_warnings);
2126+
assert!(sess.diagnostic().flags.can_emit_warnings);
21272127
}
21282128
}
21292129

src/librustc/session/mod.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -727,11 +727,11 @@ pub fn build_session_with_codemap(sopts: config::Options,
727727
.unwrap_or(false);
728728
let cap_lints_allow = sopts.lint_cap.map_or(false, |cap| cap == lint::Allow);
729729

730-
let can_print_warnings = !(warnings_allow || cap_lints_allow);
730+
let can_emit_warnings = !(warnings_allow || cap_lints_allow);
731731

732732
let treat_err_as_bug = sopts.debugging_opts.treat_err_as_bug;
733733

734-
let macro_backtrace = sopts.debugging_opts.macro_backtrace;
734+
let external_macro_backtrace = sopts.debugging_opts.external_macro_backtrace;
735735

736736
let emitter: Box<Emitter> = match (sopts.error_format, emitter_dest) {
737737
(config::ErrorOutputType::HumanReadable(color_config), None) => {
@@ -755,10 +755,14 @@ pub fn build_session_with_codemap(sopts: config::Options,
755755
};
756756

757757
let diagnostic_handler =
758-
errors::Handler::with_emitter(can_print_warnings,
759-
treat_err_as_bug,
760-
macro_backtrace,
761-
emitter);
758+
errors::Handler::with_emitter_and_flags(
759+
emitter,
760+
errors::HandlerFlags {
761+
can_emit_warnings,
762+
treat_err_as_bug,
763+
external_macro_backtrace,
764+
.. Default::default()
765+
});
762766

763767
build_session_(sopts,
764768
local_crate_source_file,
@@ -928,7 +932,7 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
928932
Box::new(EmitterWriter::stderr(color_config, None, true))
929933
}
930934
};
931-
let handler = errors::Handler::with_emitter(true, false, false, emitter);
935+
let handler = errors::Handler::with_emitter(true, false, emitter);
932936
handler.emit(&MultiSpan::new(), msg, errors::Level::Fatal);
933937
panic!(errors::FatalError);
934938
}
@@ -943,7 +947,7 @@ pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
943947
Box::new(EmitterWriter::stderr(color_config, None, true))
944948
}
945949
};
946-
let handler = errors::Handler::with_emitter(true, false, false, emitter);
950+
let handler = errors::Handler::with_emitter(true, false, emitter);
947951
handler.emit(&MultiSpan::new(), msg, errors::Level::Warning);
948952
}
949953

src/librustc_driver/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -141,8 +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, false,
145-
Box::new(emitter));
144+
let handler = errors::Handler::with_emitter(true, false, Box::new(emitter));
146145
handler.emit(&MultiSpan::new(),
147146
"aborting due to previous error(s)",
148147
errors::Level::Fatal);
@@ -1222,7 +1221,7 @@ pub fn monitor<F: FnOnce() + Send + 'static>(f: F) {
12221221
Box::new(errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
12231222
None,
12241223
false));
1225-
let handler = errors::Handler::with_emitter(true, false, false, emitter);
1224+
let handler = errors::Handler::with_emitter(true, false, emitter);
12261225

12271226
// a .span_bug or .bug call has already printed what
12281227
// 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, false, emitter);
107+
let diagnostic_handler = errors::Handler::with_emitter(true, false, emitter);
108108

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

src/librustc_errors/emitter.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ impl Emitter for EmitterWriter {
6464
}
6565
}
6666

67-
if !db.handler.macro_backtrace {
67+
if !db.handler.flags.external_macro_backtrace {
6868
self.fix_multispans_in_std_macros(&mut primary_span, &mut children);
6969
}
7070
self.emit_messages_default(&db.level,
71-
db.handler.macro_backtrace,
71+
db.handler.flags.external_macro_backtrace,
7272
&db.styled_message(),
7373
&db.code,
7474
&primary_span,
@@ -798,7 +798,7 @@ impl EmitterWriter {
798798
level: Level::Note,
799799
message: vec![
800800
(["this error originates in a macro outside of the current crate",
801-
"(run with -Z macro-backtrace for more info)"].join(" "),
801+
"(run with -Z external-macro-backtrace for more info)"].join(" "),
802802
Style::NoStyle),
803803
],
804804
span: MultiSpan::new(),
@@ -888,7 +888,7 @@ impl EmitterWriter {
888888
msg: &Vec<(String, Style)>,
889889
code: &Option<DiagnosticId>,
890890
level: &Level,
891-
macro_backtrace: bool,
891+
external_macro_backtrace: bool,
892892
max_line_num_len: usize,
893893
is_secondary: bool)
894894
-> io::Result<()> {
@@ -1086,7 +1086,7 @@ impl EmitterWriter {
10861086
}
10871087
}
10881088

1089-
if macro_backtrace {
1089+
if external_macro_backtrace {
10901090
if let Some(ref primary_span) = msp.primary_span().as_ref() {
10911091
self.render_macro_backtrace_old_school(primary_span, &mut buffer)?;
10921092
}
@@ -1183,7 +1183,7 @@ impl EmitterWriter {
11831183
}
11841184
fn emit_messages_default(&mut self,
11851185
level: &Level,
1186-
macro_backtrace: bool,
1186+
external_macro_backtrace: bool,
11871187
message: &Vec<(String, Style)>,
11881188
code: &Option<DiagnosticId>,
11891189
span: &MultiSpan,
@@ -1196,7 +1196,7 @@ impl EmitterWriter {
11961196
message,
11971197
code,
11981198
level,
1199-
macro_backtrace,
1199+
external_macro_backtrace,
12001200
max_line_num_len,
12011201
false) {
12021202
Ok(()) => {
@@ -1218,7 +1218,7 @@ impl EmitterWriter {
12181218
&child.styled_message(),
12191219
&None,
12201220
&child.level,
1221-
macro_backtrace,
1221+
external_macro_backtrace,
12221222
max_line_num_len,
12231223
true) {
12241224
Err(e) => panic!("failed to emit error: {}", e),

src/librustc_errors/lib.rs

+44-18
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,10 @@ pub use diagnostic_builder::DiagnosticBuilder;
233233
/// (fatal, bug, unimpl) may cause immediate exit,
234234
/// others log errors for later reporting.
235235
pub struct Handler {
236+
pub flags: HandlerFlags,
237+
236238
err_count: Cell<usize>,
237239
emitter: RefCell<Box<Emitter>>,
238-
pub can_emit_warnings: bool,
239-
treat_err_as_bug: bool,
240-
pub macro_backtrace: bool,
241240
continue_after_error: Cell<bool>,
242241
delayed_span_bug: RefCell<Option<Diagnostic>>,
243242
tracked_diagnostics: RefCell<Option<Vec<Diagnostic>>>,
@@ -248,28 +247,55 @@ pub struct Handler {
248247
emitted_diagnostics: RefCell<FxHashSet<u128>>,
249248
}
250249

250+
#[derive(Default)]
251+
pub struct HandlerFlags {
252+
pub can_emit_warnings: bool,
253+
pub treat_err_as_bug: bool,
254+
pub external_macro_backtrace: bool,
255+
}
256+
251257
impl Handler {
252258
pub fn with_tty_emitter(color_config: ColorConfig,
253259
can_emit_warnings: bool,
254260
treat_err_as_bug: bool,
255-
macro_backtrace: bool,
256261
cm: Option<Rc<CodeMapper>>)
257262
-> Handler {
263+
Handler::with_tty_emitter_and_flags(
264+
color_config,
265+
cm,
266+
HandlerFlags {
267+
can_emit_warnings,
268+
treat_err_as_bug,
269+
.. Default::default()
270+
})
271+
}
272+
273+
pub fn with_tty_emitter_and_flags(color_config: ColorConfig,
274+
cm: Option<Rc<CodeMapper>>,
275+
flags: HandlerFlags)
276+
-> Handler {
258277
let emitter = Box::new(EmitterWriter::stderr(color_config, cm, false));
259-
Handler::with_emitter(can_emit_warnings, treat_err_as_bug, macro_backtrace, emitter)
278+
Handler::with_emitter_and_flags(emitter, flags)
260279
}
261280

262281
pub fn with_emitter(can_emit_warnings: bool,
263282
treat_err_as_bug: bool,
264-
macro_backtrace: bool,
265283
e: Box<Emitter>)
266284
-> Handler {
285+
Handler::with_emitter_and_flags(
286+
e,
287+
HandlerFlags {
288+
can_emit_warnings,
289+
treat_err_as_bug,
290+
.. Default::default()
291+
})
292+
}
293+
294+
pub fn with_emitter_and_flags(e: Box<Emitter>, flags: HandlerFlags) -> Handler {
267295
Handler {
296+
flags,
268297
err_count: Cell::new(0),
269298
emitter: RefCell::new(e),
270-
can_emit_warnings,
271-
treat_err_as_bug,
272-
macro_backtrace,
273299
continue_after_error: Cell::new(true),
274300
delayed_span_bug: RefCell::new(None),
275301
tracked_diagnostics: RefCell::new(None),
@@ -297,7 +323,7 @@ impl Handler {
297323
-> DiagnosticBuilder<'a> {
298324
let mut result = DiagnosticBuilder::new(self, Level::Warning, msg);
299325
result.set_span(sp);
300-
if !self.can_emit_warnings {
326+
if !self.flags.can_emit_warnings {
301327
result.cancel();
302328
}
303329
result
@@ -310,14 +336,14 @@ impl Handler {
310336
let mut result = DiagnosticBuilder::new(self, Level::Warning, msg);
311337
result.set_span(sp);
312338
result.code(code);
313-
if !self.can_emit_warnings {
339+
if !self.flags.can_emit_warnings {
314340
result.cancel();
315341
}
316342
result
317343
}
318344
pub fn struct_warn<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
319345
let mut result = DiagnosticBuilder::new(self, Level::Warning, msg);
320-
if !self.can_emit_warnings {
346+
if !self.flags.can_emit_warnings {
321347
result.cancel();
322348
}
323349
result
@@ -380,7 +406,7 @@ impl Handler {
380406
}
381407

382408
fn panic_if_treat_err_as_bug(&self) {
383-
if self.treat_err_as_bug {
409+
if self.flags.treat_err_as_bug {
384410
panic!("encountered error with `-Z treat_err_as_bug");
385411
}
386412
}
@@ -422,7 +448,7 @@ impl Handler {
422448
panic!(ExplicitBug);
423449
}
424450
pub fn delay_span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
425-
if self.treat_err_as_bug {
451+
if self.flags.treat_err_as_bug {
426452
self.span_bug(sp, msg);
427453
}
428454
let mut diagnostic = Diagnostic::new(Level::Bug, msg);
@@ -447,15 +473,15 @@ impl Handler {
447473
self.span_bug(sp, &format!("unimplemented {}", msg));
448474
}
449475
pub fn fatal(&self, msg: &str) -> FatalError {
450-
if self.treat_err_as_bug {
476+
if self.flags.treat_err_as_bug {
451477
self.bug(msg);
452478
}
453479
let mut db = DiagnosticBuilder::new(self, Fatal, msg);
454480
db.emit();
455481
FatalError
456482
}
457483
pub fn err(&self, msg: &str) {
458-
if self.treat_err_as_bug {
484+
if self.flags.treat_err_as_bug {
459485
self.bug(msg);
460486
}
461487
let mut db = DiagnosticBuilder::new(self, Error, msg);
@@ -508,7 +534,7 @@ impl Handler {
508534
panic!(self.fatal(&s));
509535
}
510536
pub fn emit(&self, msp: &MultiSpan, msg: &str, lvl: Level) {
511-
if lvl == Warning && !self.can_emit_warnings {
537+
if lvl == Warning && !self.flags.can_emit_warnings {
512538
return;
513539
}
514540
let mut db = DiagnosticBuilder::new(self, lvl, msg);
@@ -519,7 +545,7 @@ impl Handler {
519545
}
520546
}
521547
pub fn emit_with_code(&self, msp: &MultiSpan, msg: &str, code: DiagnosticId, lvl: Level) {
522-
if lvl == Warning && !self.can_emit_warnings {
548+
if lvl == Warning && !self.flags.can_emit_warnings {
523549
return;
524550
}
525551
let mut db = DiagnosticBuilder::new_with_code(self, lvl, Some(code), msg);

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, false, Box::new(self.diag_emitter.clone()))
356+
Handler::with_emitter(true, 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,7 +141,6 @@ pub fn run_core(search_paths: SearchPaths,
141141
let diagnostic_handler = errors::Handler::with_tty_emitter(ColorConfig::Auto,
142142
true,
143143
false,
144-
false,
145144
Some(codemap.clone()));
146145

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

src/librustdoc/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn run(input: &str,
8282
let codemap = Rc::new(CodeMap::new(sessopts.file_path_mapping()));
8383
let handler =
8484
errors::Handler::with_tty_emitter(ColorConfig::Auto,
85-
true, false, false,
85+
true, false,
8686
Some(codemap.clone()));
8787

8888
let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));
@@ -246,7 +246,7 @@ fn run_test(test: &str, cratename: &str, filename: &str, cfgs: Vec<String>, libs
246246
let _bomb = Bomb(data.clone(), old.unwrap_or(box io::stdout()));
247247

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

251251
let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));
252252
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, false, Box::new(emitter)),
1729+
span_diagnostic: errors::Handler::with_emitter(true, 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,7 +58,6 @@ impl ParseSess {
5858
let handler = Handler::with_tty_emitter(ColorConfig::Auto,
5959
true,
6060
false,
61-
false,
6261
Some(cm.clone()));
6362
ParseSess::with_span_handler(handler, cm)
6463
}

0 commit comments

Comments
 (0)