diff options
| author | bors <bors@rust-lang.org> | 2023-01-11 17:01:44 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-01-11 17:01:44 +0000 |
| commit | ef4046e4f3932991971cdb64915172899532aece (patch) | |
| tree | 0d19af73ce4d98d239abf182b4dc07a44dff124f /compiler/rustc_errors/src/lib.rs | |
| parent | b22c152958eade17a71d899b29a2d39bcc77aa48 (diff) | |
| parent | 9aeef61820b4cd14b3f4cab601a95b15ced5862e (diff) | |
| download | rust-ef4046e4f3932991971cdb64915172899532aece.tar.gz rust-ef4046e4f3932991971cdb64915172899532aece.zip | |
Auto merge of #106730 - Nilstrieb:rollup-f7p8dsa, r=Nilstrieb
Rollup of 9 pull requests Successful merges: - #106321 (Collect and emit proper backtraces for `delay_span_bug`s) - #106397 (Check `impl`'s `where` clauses in `consider_impl_candidate` in experimental solver) - #106427 (Improve fluent error messages) - #106570 (add tests for div_duration_* functions) - #106648 (Polymorphization cleanup) - #106664 (Remove unnecessary lseek syscall when using std::fs::read) - #106709 (Disable "split dwarf inlining" by default.) - #106715 (Autolabel and ping wg for changes to new solver) - #106717 (fix typo LocalItemId -> ItemLocalId) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_errors/src/lib.rs')
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index b4d23e96f8f..535812fb0e2 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -11,6 +11,10 @@ #![feature(never_type)] #![feature(result_option_inspect)] #![feature(rustc_attrs)] +#![feature(yeet_expr)] +#![feature(try_blocks)] +#![feature(box_patterns)] +#![feature(error_reporter)] #![allow(incomplete_features)] #[macro_use] @@ -40,8 +44,8 @@ use rustc_span::source_map::SourceMap; use rustc_span::HashStableContext; use rustc_span::{Loc, Span}; -use std::any::Any; use std::borrow::Cow; +use std::error::Report; use std::fmt; use std::hash::Hash; use std::num::NonZeroUsize; @@ -55,11 +59,14 @@ mod diagnostic; mod diagnostic_builder; mod diagnostic_impls; pub mod emitter; +pub mod error; pub mod json; mod lock; pub mod registry; mod snippet; mod styled_buffer; +#[cfg(test)] +mod tests; pub mod translation; pub use diagnostic_builder::IntoDiagnostic; @@ -364,9 +371,9 @@ pub use rustc_span::fatal_error::{FatalError, FatalErrorMarker}; /// or `.span_bug` rather than a failed assertion, etc. pub struct ExplicitBug; -/// Signifies that the compiler died with an explicit call to `.delay_good_path_bug` +/// Signifies that the compiler died with an explicit call to `.delay_*_bug` /// rather than a failed assertion, etc. -pub struct GoodPathBug; +pub struct DelayedBugPanic; pub use diagnostic::{ AddToDiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgValue, DiagnosticId, @@ -399,7 +406,7 @@ struct HandlerInner { warn_count: usize, deduplicated_err_count: usize, emitter: Box<dyn Emitter + sync::Send>, - delayed_span_bugs: Vec<Diagnostic>, + delayed_span_bugs: Vec<DelayedDiagnostic>, delayed_good_path_bugs: Vec<DelayedDiagnostic>, /// This flag indicates that an expected diagnostic was emitted and suppressed. /// This is used for the `delayed_good_path_bugs` check. @@ -505,11 +512,7 @@ impl Drop for HandlerInner { if !self.has_errors() { let bugs = std::mem::replace(&mut self.delayed_span_bugs, Vec::new()); - self.flush_delayed( - bugs, - "no errors encountered even though `delay_span_bug` issued", - ExplicitBug, - ); + self.flush_delayed(bugs, "no errors encountered even though `delay_span_bug` issued"); } // FIXME(eddyb) this explains what `delayed_good_path_bugs` are! @@ -520,9 +523,8 @@ impl Drop for HandlerInner { if !self.has_any_message() && !self.suppressed_expected_diag { let bugs = std::mem::replace(&mut self.delayed_good_path_bugs, Vec::new()); self.flush_delayed( - bugs.into_iter().map(DelayedDiagnostic::decorate), + bugs, "no warnings or errors encountered even though `delayed_good_path_bugs` issued", - GoodPathBug, ); } @@ -622,7 +624,14 @@ impl Handler { ) -> SubdiagnosticMessage { let inner = self.inner.borrow(); let args = crate::translation::to_fluent_args(args); - SubdiagnosticMessage::Eager(inner.emitter.translate_message(&message, &args).to_string()) + SubdiagnosticMessage::Eager( + inner + .emitter + .translate_message(&message, &args) + .map_err(Report::new) + .unwrap() + .to_string(), + ) } // This is here to not allow mutation of flags; @@ -1223,11 +1232,7 @@ impl Handler { pub fn flush_delayed(&self) { let mut inner = self.inner.lock(); let bugs = std::mem::replace(&mut inner.delayed_span_bugs, Vec::new()); - inner.flush_delayed( - bugs, - "no errors encountered even though `delay_span_bug` issued", - ExplicitBug, - ); + inner.flush_delayed(bugs, "no errors encountered even though `delay_span_bug` issued"); } } @@ -1287,7 +1292,9 @@ impl HandlerInner { // once *any* errors were emitted (and truncate `delayed_span_bugs` // when an error is first emitted, also), but maybe there's a case // in which that's not sound? otherwise this is really inefficient. - self.delayed_span_bugs.push(diagnostic.clone()); + let backtrace = std::backtrace::Backtrace::force_capture(); + self.delayed_span_bugs + .push(DelayedDiagnostic::with_backtrace(diagnostic.clone(), backtrace)); if !self.flags.report_delayed_bugs { return Some(ErrorGuaranteed::unchecked_claim_error_was_emitted()); @@ -1562,7 +1569,6 @@ impl HandlerInner { } let mut diagnostic = Diagnostic::new(Level::DelayedBug, msg); diagnostic.set_span(sp.into()); - diagnostic.note(&format!("delayed at {}", std::panic::Location::caller())); self.emit_diagnostic(&mut diagnostic).unwrap() } @@ -1605,12 +1611,13 @@ impl HandlerInner { fn flush_delayed( &mut self, - bugs: impl IntoIterator<Item = Diagnostic>, + bugs: impl IntoIterator<Item = DelayedDiagnostic>, explanation: impl Into<DiagnosticMessage> + Copy, - panic_with: impl Any + Send + 'static, ) { let mut no_bugs = true; - for mut bug in bugs { + for bug in bugs { + let mut bug = bug.decorate(); + if no_bugs { // Put the overall explanation before the `DelayedBug`s, to // frame them better (e.g. separate warnings from them). @@ -1633,9 +1640,9 @@ impl HandlerInner { self.emit_diagnostic(&mut bug); } - // Panic with `ExplicitBug` to avoid "unexpected panic" messages. + // Panic with `DelayedBugPanic` to avoid "unexpected panic" messages. if !no_bugs { - panic::panic_any(panic_with); + panic::panic_any(DelayedBugPanic); } } |
