X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc_errors%2Flib.rs;h=827e9b831f32d711978c1b0c960fc90aabc4ab49;hb=f998e275cae5320e75871c626c0f88eaef83d5e4;hp=2279ed859540811d6d45d536323493ba0cf08c87;hpb=f48e576756cd0c360e5522974fc8d5867b439092;p=rust.git diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 2279ed85954..827e9b831f3 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -10,6 +10,7 @@ pub use emitter::ColorConfig; +use log::debug; use Level::*; use emitter::{is_case_difference, Emitter, EmitterWriter}; @@ -174,6 +175,15 @@ fn push_trailing( self.substitutions .iter() + .filter(|subst| { + // Suggestions coming from macros can have malformed spans. This is a heavy + // handed approach to avoid ICEs by ignoring the suggestion outright. + let invalid = subst.parts.iter().any(|item| cm.is_valid_span(item.span).is_err()); + if invalid { + debug!("splice_lines: suggestion contains an invalid span: {:?}", subst); + } + !invalid + }) .cloned() .map(|mut substitution| { // Assumption: all spans are in the same file, and all spans @@ -182,7 +192,7 @@ fn push_trailing( // Find the bounding span. let lo = substitution.parts.iter().map(|part| part.span.lo()).min().unwrap(); - let hi = substitution.parts.iter().map(|part| part.span.hi()).min().unwrap(); + let hi = substitution.parts.iter().map(|part| part.span.hi()).max().unwrap(); let bounding_span = Span::with_root_ctxt(lo, hi); let lines = cm.span_to_lines(bounding_span).unwrap(); assert!(!lines.lines.is_empty()); @@ -278,7 +288,6 @@ struct HandlerInner { err_count: usize, deduplicated_err_count: usize, emitter: Box, - continue_after_error: bool, delayed_span_bugs: Vec, /// This set contains the `DiagnosticId` of all emitted diagnostics to avoid @@ -402,7 +411,6 @@ pub fn with_emitter_and_flags( err_count: 0, deduplicated_err_count: 0, emitter, - continue_after_error: true, delayed_span_bugs: Vec::new(), taught_diagnostics: Default::default(), emitted_diagnostic_codes: Default::default(), @@ -412,10 +420,6 @@ pub fn with_emitter_and_flags( } } - pub fn set_continue_after_error(&self, continue_after_error: bool) { - self.inner.borrow_mut().continue_after_error = continue_after_error; - } - // This is here to not allow mutation of flags; // as of this writing it's only used in tests in librustc. pub fn can_emit_warnings(&self) -> bool { @@ -672,10 +676,6 @@ pub fn abort_if_errors(&self) { self.inner.borrow_mut().abort_if_errors() } - pub fn abort_if_errors_and_should_abort(&self) { - self.inner.borrow_mut().abort_if_errors_and_should_abort() - } - /// `true` if we haven't taught a diagnostic with this code already. /// The caller must then teach the user about such a diagnostic. /// @@ -696,7 +696,6 @@ pub fn emit_diagnostic(&self, diagnostic: &Diagnostic) { fn emit_diag_at_span(&self, mut diag: Diagnostic, sp: impl Into) { let mut inner = self.inner.borrow_mut(); inner.emit_diagnostic(diag.set_span(sp)); - inner.abort_if_errors_and_should_abort(); } pub fn emit_artifact_notification(&self, path: &Path, artifact_type: &str) { @@ -830,14 +829,6 @@ fn has_errors_or_delayed_span_bugs(&self) -> bool { self.has_errors() || !self.delayed_span_bugs.is_empty() } - fn abort_if_errors_and_should_abort(&mut self) { - self.emit_stashed_diagnostics(); - - if self.has_errors() && !self.continue_after_error { - FatalError.raise(); - } - } - fn abort_if_errors(&mut self) { self.emit_stashed_diagnostics(); @@ -853,7 +844,6 @@ fn span_bug(&mut self, sp: impl Into, msg: &str) -> ! { fn emit_diag_at_span(&mut self, mut diag: Diagnostic, sp: impl Into) { self.emit_diagnostic(diag.set_span(sp)); - self.abort_if_errors_and_should_abort(); } fn delay_span_bug(&mut self, sp: impl Into, msg: &str) {