diff options
| author | Alex Burka <alex@alexburka.com> | 2017-11-20 18:03:20 +0000 |
|---|---|---|
| committer | Alex Burka <alex@alexburka.com> | 2017-11-20 18:03:20 +0000 |
| commit | b34a7ffb2524bbe2e8d563a846f6c9f8e2453c1a (patch) | |
| tree | 34577c495feedd5f61208cc3a85c78f458604349 /src/librustc_errors | |
| parent | 30a661409cbdd0fb7ab4386952d9e0ecdd78abfa (diff) | |
| download | rust-b34a7ffb2524bbe2e8d563a846f6c9f8e2453c1a.tar.gz rust-b34a7ffb2524bbe2e8d563a846f6c9f8e2453c1a.zip | |
address review comments
Diffstat (limited to 'src/librustc_errors')
| -rw-r--r-- | src/librustc_errors/emitter.rs | 16 | ||||
| -rw-r--r-- | src/librustc_errors/lib.rs | 62 |
2 files changed, 52 insertions, 26 deletions
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index f3f5b443a43..17ed1734fe2 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -64,11 +64,11 @@ impl Emitter for EmitterWriter { } } - if !db.handler.macro_backtrace { + if !db.handler.flags.external_macro_backtrace { self.fix_multispans_in_std_macros(&mut primary_span, &mut children); } self.emit_messages_default(&db.level, - db.handler.macro_backtrace, + db.handler.flags.external_macro_backtrace, &db.styled_message(), &db.code, &primary_span, @@ -798,7 +798,7 @@ impl EmitterWriter { 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(" "), + "(run with -Z external-macro-backtrace for more info)"].join(" "), Style::NoStyle), ], span: MultiSpan::new(), @@ -888,7 +888,7 @@ impl EmitterWriter { msg: &Vec<(String, Style)>, code: &Option<DiagnosticId>, level: &Level, - macro_backtrace: bool, + external_macro_backtrace: bool, max_line_num_len: usize, is_secondary: bool) -> io::Result<()> { @@ -1086,7 +1086,7 @@ impl EmitterWriter { } } - if macro_backtrace { + if external_macro_backtrace { if let Some(ref primary_span) = msp.primary_span().as_ref() { self.render_macro_backtrace_old_school(primary_span, &mut buffer)?; } @@ -1183,7 +1183,7 @@ impl EmitterWriter { } fn emit_messages_default(&mut self, level: &Level, - macro_backtrace: bool, + external_macro_backtrace: bool, message: &Vec<(String, Style)>, code: &Option<DiagnosticId>, span: &MultiSpan, @@ -1196,7 +1196,7 @@ impl EmitterWriter { message, code, level, - macro_backtrace, + external_macro_backtrace, max_line_num_len, false) { Ok(()) => { @@ -1218,7 +1218,7 @@ impl EmitterWriter { &child.styled_message(), &None, &child.level, - macro_backtrace, + external_macro_backtrace, max_line_num_len, true) { Err(e) => panic!("failed to emit error: {}", e), diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 99d94aaf912..605cfc5ed12 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -233,11 +233,10 @@ pub use diagnostic_builder::DiagnosticBuilder; /// (fatal, bug, unimpl) may cause immediate exit, /// others log errors for later reporting. pub struct Handler { + pub flags: HandlerFlags, + err_count: Cell<usize>, 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>>>, @@ -248,28 +247,55 @@ pub struct Handler { emitted_diagnostics: RefCell<FxHashSet<u128>>, } +#[derive(Default)] +pub struct HandlerFlags { + pub can_emit_warnings: bool, + pub treat_err_as_bug: bool, + pub external_macro_backtrace: bool, +} + 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 { + Handler::with_tty_emitter_and_flags( + color_config, + cm, + HandlerFlags { + can_emit_warnings, + treat_err_as_bug, + .. Default::default() + }) + } + + pub fn with_tty_emitter_and_flags(color_config: ColorConfig, + cm: Option<Rc<CodeMapper>>, + flags: HandlerFlags) + -> Handler { let emitter = Box::new(EmitterWriter::stderr(color_config, cm, false)); - Handler::with_emitter(can_emit_warnings, treat_err_as_bug, macro_backtrace, emitter) + Handler::with_emitter_and_flags(emitter, flags) } pub fn with_emitter(can_emit_warnings: bool, treat_err_as_bug: bool, - macro_backtrace: bool, e: Box<Emitter>) -> Handler { + Handler::with_emitter_and_flags( + e, + HandlerFlags { + can_emit_warnings, + treat_err_as_bug, + .. Default::default() + }) + } + + pub fn with_emitter_and_flags(e: Box<Emitter>, flags: HandlerFlags) -> Handler { Handler { + flags, 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), @@ -297,7 +323,7 @@ impl Handler { -> DiagnosticBuilder<'a> { let mut result = DiagnosticBuilder::new(self, Level::Warning, msg); result.set_span(sp); - if !self.can_emit_warnings { + if !self.flags.can_emit_warnings { result.cancel(); } result @@ -310,14 +336,14 @@ impl Handler { let mut result = DiagnosticBuilder::new(self, Level::Warning, msg); result.set_span(sp); result.code(code); - if !self.can_emit_warnings { + if !self.flags.can_emit_warnings { result.cancel(); } result } pub fn struct_warn<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> { let mut result = DiagnosticBuilder::new(self, Level::Warning, msg); - if !self.can_emit_warnings { + if !self.flags.can_emit_warnings { result.cancel(); } result @@ -380,7 +406,7 @@ impl Handler { } fn panic_if_treat_err_as_bug(&self) { - if self.treat_err_as_bug { + if self.flags.treat_err_as_bug { panic!("encountered error with `-Z treat_err_as_bug"); } } @@ -422,7 +448,7 @@ impl Handler { panic!(ExplicitBug); } pub fn delay_span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: &str) { - if self.treat_err_as_bug { + if self.flags.treat_err_as_bug { self.span_bug(sp, msg); } let mut diagnostic = Diagnostic::new(Level::Bug, msg); @@ -447,7 +473,7 @@ impl Handler { self.span_bug(sp, &format!("unimplemented {}", msg)); } pub fn fatal(&self, msg: &str) -> FatalError { - if self.treat_err_as_bug { + if self.flags.treat_err_as_bug { self.bug(msg); } let mut db = DiagnosticBuilder::new(self, Fatal, msg); @@ -455,7 +481,7 @@ impl Handler { FatalError } pub fn err(&self, msg: &str) { - if self.treat_err_as_bug { + if self.flags.treat_err_as_bug { self.bug(msg); } let mut db = DiagnosticBuilder::new(self, Error, msg); @@ -508,7 +534,7 @@ impl Handler { panic!(self.fatal(&s)); } pub fn emit(&self, msp: &MultiSpan, msg: &str, lvl: Level) { - if lvl == Warning && !self.can_emit_warnings { + if lvl == Warning && !self.flags.can_emit_warnings { return; } let mut db = DiagnosticBuilder::new(self, lvl, msg); @@ -519,7 +545,7 @@ impl Handler { } } pub fn emit_with_code(&self, msp: &MultiSpan, msg: &str, code: DiagnosticId, lvl: Level) { - if lvl == Warning && !self.can_emit_warnings { + if lvl == Warning && !self.flags.can_emit_warnings { return; } let mut db = DiagnosticBuilder::new_with_code(self, lvl, Some(code), msg); |
