From 56c90774a94e521283030caa12c1bf8d9bc16be4 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 19 Jul 2018 17:53:44 +0200 Subject: Make sure the compiler actually panics on `delay_span_bug` Even if that is just happening because of `abort_if_errors` --- src/librustc_errors/diagnostic_builder.rs | 2 +- src/librustc_errors/lib.rs | 32 +++++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) (limited to 'src/librustc_errors') diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index 9c7b7ea3395..24ece514a47 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -132,7 +132,7 @@ impl<'a> DiagnosticBuilder<'a> { /// locally in whichever way makes the most sense. pub fn delay_as_bug(&mut self) { self.level = Level::Bug; - *self.handler.delayed_span_bug.borrow_mut() = Some(self.diagnostic.clone()); + self.handler.delay_as_bug(self.diagnostic.clone()); self.cancel(); } diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index f18a7bd9136..06c49b3a103 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -274,7 +274,7 @@ pub struct Handler { err_count: AtomicUsize, emitter: Lock>, continue_after_error: LockCell, - delayed_span_bug: Lock>, + delayed_span_bug: Lock>, // This set contains the `DiagnosticId` of all emitted diagnostics to avoid // emitting the same diagnostic with extended help (`--teach`) twice, which @@ -299,9 +299,25 @@ thread_local!(pub static TRACK_DIAGNOSTICS: Cell = pub struct HandlerFlags { pub can_emit_warnings: bool, pub treat_err_as_bug: bool, + pub report_delayed_bugs: bool, pub external_macro_backtrace: bool, } +impl Drop for Handler { + fn drop(&mut self) { + if self.err_count() == 0 { + let mut bugs = self.delayed_span_bug.borrow_mut(); + let has_bugs = !bugs.is_empty(); + for bug in bugs.drain(..) { + DiagnosticBuilder::new_diagnostic(self, bug).emit(); + } + if has_bugs { + panic!("no errors encountered even though `delay_span_bug` issued"); + } + } + } +} + impl Handler { pub fn with_tty_emitter(color_config: ColorConfig, can_emit_warnings: bool, @@ -346,7 +362,7 @@ impl Handler { err_count: AtomicUsize::new(0), emitter: Lock::new(e), continue_after_error: LockCell::new(true), - delayed_span_bug: Lock::new(None), + delayed_span_bug: Lock::new(Vec::new()), taught_diagnostics: Lock::new(FxHashSet()), emitted_diagnostic_codes: Lock::new(FxHashSet()), emitted_diagnostics: Lock::new(FxHashSet()), @@ -503,11 +519,18 @@ impl Handler { } pub fn delay_span_bug>(&self, sp: S, msg: &str) { if self.flags.treat_err_as_bug { + // FIXME: don't abort here if report_delayed_bugs is off self.span_bug(sp, msg); } let mut diagnostic = Diagnostic::new(Level::Bug, msg); diagnostic.set_span(sp.into()); - *self.delayed_span_bug.borrow_mut() = Some(diagnostic); + self.delay_as_bug(diagnostic); + } + fn delay_as_bug(&self, diagnostic: Diagnostic) { + if self.flags.report_delayed_bugs { + DiagnosticBuilder::new_diagnostic(self, diagnostic.clone()).emit(); + } + self.delayed_span_bug.borrow_mut().push(diagnostic); } pub fn span_bug_no_panic>(&self, sp: S, msg: &str) { self.emit(&sp.into(), msg, Bug); @@ -615,9 +638,6 @@ impl Handler { pub fn abort_if_errors(&self) { if self.err_count() == 0 { - if let Some(bug) = self.delayed_span_bug.borrow_mut().take() { - DiagnosticBuilder::new_diagnostic(self, bug).emit(); - } return; } FatalError.raise(); -- cgit 1.4.1-3-g733a5 From bab5eb41a7f3f755708527d97a1f8bf09b15d570 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Sat, 21 Jul 2018 16:09:10 +0200 Subject: Sequence-field should have plural name --- src/librustc_errors/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/librustc_errors') diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 06c49b3a103..c0f07645f49 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -274,7 +274,7 @@ pub struct Handler { err_count: AtomicUsize, emitter: Lock>, continue_after_error: LockCell, - delayed_span_bug: Lock>, + delayed_span_bugs: Lock>, // This set contains the `DiagnosticId` of all emitted diagnostics to avoid // emitting the same diagnostic with extended help (`--teach`) twice, which @@ -306,7 +306,7 @@ pub struct HandlerFlags { impl Drop for Handler { fn drop(&mut self) { if self.err_count() == 0 { - let mut bugs = self.delayed_span_bug.borrow_mut(); + let mut bugs = self.delayed_span_bugs.borrow_mut(); let has_bugs = !bugs.is_empty(); for bug in bugs.drain(..) { DiagnosticBuilder::new_diagnostic(self, bug).emit(); @@ -362,7 +362,7 @@ impl Handler { err_count: AtomicUsize::new(0), emitter: Lock::new(e), continue_after_error: LockCell::new(true), - delayed_span_bug: Lock::new(Vec::new()), + delayed_span_bugs: Lock::new(Vec::new()), taught_diagnostics: Lock::new(FxHashSet()), emitted_diagnostic_codes: Lock::new(FxHashSet()), emitted_diagnostics: Lock::new(FxHashSet()), @@ -530,7 +530,7 @@ impl Handler { if self.flags.report_delayed_bugs { DiagnosticBuilder::new_diagnostic(self, diagnostic.clone()).emit(); } - self.delayed_span_bug.borrow_mut().push(diagnostic); + self.delayed_span_bugs.borrow_mut().push(diagnostic); } pub fn span_bug_no_panic>(&self, sp: S, msg: &str) { self.emit(&sp.into(), msg, Bug); -- cgit 1.4.1-3-g733a5