diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index bf70a41fd79e0..ea0770daf0eed 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -1236,9 +1236,7 @@ impl<'hir> LoweringContext<'_, 'hir> { (Some(..), Some(..), HalfOpen) => hir::LangItem::Range, (None, Some(..), Closed) => hir::LangItem::RangeToInclusive, (Some(..), Some(..), Closed) => unreachable!(), - (_, None, Closed) => { - self.diagnostic().span_fatal(span, "inclusive range with no end").raise() - } + (_, None, Closed) => self.diagnostic().span_fatal(span, "inclusive range with no end"), }; let fields = self.arena.alloc_from_iter( diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 6aee769298bd8..dc1664bb2baa8 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -634,9 +634,9 @@ impl Handler { DiagnosticBuilder::new(self, Level::Note, msg) } - pub fn span_fatal(&self, span: impl Into, msg: &str) -> FatalError { + pub fn span_fatal(&self, span: impl Into, msg: &str) -> ! { self.emit_diag_at_span(Diagnostic::new(Fatal, msg), span); - FatalError + FatalError.raise() } pub fn span_fatal_with_code( @@ -644,9 +644,9 @@ impl Handler { span: impl Into, msg: &str, code: DiagnosticId, - ) -> FatalError { + ) -> ! { self.emit_diag_at_span(Diagnostic::new_with_code(Fatal, Some(code), msg), span); - FatalError + FatalError.raise() } pub fn span_err(&self, span: impl Into, msg: &str) { @@ -692,6 +692,7 @@ impl Handler { db } + // NOTE: intentionally doesn't raise an error so rustc_codegen_ssa only reports fatal errors in the main thread pub fn fatal(&self, msg: &str) -> FatalError { self.inner.borrow_mut().fatal(msg) } diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs index bd8dfd678a97b..1c2f9a9645fe0 100644 --- a/compiler/rustc_parse/src/lexer/mod.rs +++ b/compiler/rustc_parse/src/lexer/mod.rs @@ -148,15 +148,11 @@ impl<'a> StringReader<'a> { None => "unterminated block comment", }; let last_bpos = self.pos; - self.sess - .span_diagnostic - .struct_span_fatal_with_code( - self.mk_sp(start, last_bpos), - msg, - error_code!(E0758), - ) - .emit(); - FatalError.raise(); + self.sess.span_diagnostic.span_fatal_with_code( + self.mk_sp(start, last_bpos), + msg, + error_code!(E0758), + ); } // Skip non-doc comments @@ -315,57 +311,41 @@ impl<'a> StringReader<'a> { let (lit_kind, mode, prefix_len, postfix_len) = match kind { rustc_lexer::LiteralKind::Char { terminated } => { if !terminated { - self.sess - .span_diagnostic - .struct_span_fatal_with_code( - self.mk_sp(start, suffix_start), - "unterminated character literal", - error_code!(E0762), - ) - .emit(); - FatalError.raise(); + self.sess.span_diagnostic.span_fatal_with_code( + self.mk_sp(start, suffix_start), + "unterminated character literal", + error_code!(E0762), + ) } (token::Char, Mode::Char, 1, 1) // ' ' } rustc_lexer::LiteralKind::Byte { terminated } => { if !terminated { - self.sess - .span_diagnostic - .struct_span_fatal_with_code( - self.mk_sp(start + BytePos(1), suffix_start), - "unterminated byte constant", - error_code!(E0763), - ) - .emit(); - FatalError.raise(); + self.sess.span_diagnostic.span_fatal_with_code( + self.mk_sp(start + BytePos(1), suffix_start), + "unterminated byte constant", + error_code!(E0763), + ) } (token::Byte, Mode::Byte, 2, 1) // b' ' } rustc_lexer::LiteralKind::Str { terminated } => { if !terminated { - self.sess - .span_diagnostic - .struct_span_fatal_with_code( - self.mk_sp(start, suffix_start), - "unterminated double quote string", - error_code!(E0765), - ) - .emit(); - FatalError.raise(); + self.sess.span_diagnostic.span_fatal_with_code( + self.mk_sp(start, suffix_start), + "unterminated double quote string", + error_code!(E0765), + ) } (token::Str, Mode::Str, 1, 1) // " " } rustc_lexer::LiteralKind::ByteStr { terminated } => { if !terminated { - self.sess - .span_diagnostic - .struct_span_fatal_with_code( - self.mk_sp(start + BytePos(1), suffix_start), - "unterminated double quote byte string", - error_code!(E0766), - ) - .emit(); - FatalError.raise(); + self.sess.span_diagnostic.span_fatal_with_code( + self.mk_sp(start + BytePos(1), suffix_start), + "unterminated double quote byte string", + error_code!(E0766), + ) } (token::ByteStr, Mode::ByteStr, 2, 1) // b" " } diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 70a5ac6f15ec2..72fdc78c30cbc 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -144,11 +144,7 @@ impl AttemptLocalParseRecovery { } impl<'a> Parser<'a> { - pub(super) fn span_fatal_err>( - &self, - sp: S, - err: Error, - ) -> DiagnosticBuilder<'a> { + pub(super) fn span_err>(&self, sp: S, err: Error) -> DiagnosticBuilder<'a> { err.span_err(sp, self.diagnostic()) } diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 20e8b0f6425ce..553ffda814fe9 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1326,7 +1326,7 @@ impl<'a> Parser<'a> { token::CloseDelim(token::Brace) => {} token::DocComment(..) => { let previous_span = self.prev_token.span; - let mut err = self.span_fatal_err(self.token.span, Error::UselessDocComment); + let mut err = self.span_err(self.token.span, Error::UselessDocComment); self.bump(); // consume the doc comment let comma_after_doc_seen = self.eat(&token::Comma); // `seen_comma` is always false, because we are inside doc block diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 74481e236f31c..ec11f2d3add92 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -525,7 +525,7 @@ impl<'a> Parser<'a> { fn ident_or_err(&mut self) -> PResult<'a, (Ident, /* is_raw */ bool)> { self.token.ident().ok_or_else(|| match self.prev_token.kind { TokenKind::DocComment(..) => { - self.span_fatal_err(self.prev_token.span, Error::UselessDocComment) + self.span_err(self.prev_token.span, Error::UselessDocComment) } _ => self.expected_ident_found(), }) diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 592f64f4a399f..b40eed8c5d118 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -168,7 +168,7 @@ impl<'a> Parser<'a> { fn error_outer_attrs(&self, attrs: &[Attribute]) { if let [.., last] = attrs { if last.is_doc_comment() { - self.span_fatal_err(last.span, Error::UselessDocComment).emit(); + self.span_err(last.span, Error::UselessDocComment).emit(); } else if attrs.iter().any(|a| a.style == AttrStyle::Outer) { self.struct_span_err(last.span, "expected statement after outer attribute").emit(); } diff --git a/compiler/rustc_session/src/cgu_reuse_tracker.rs b/compiler/rustc_session/src/cgu_reuse_tracker.rs index 0eec12aa03f2d..a9e14754334c1 100644 --- a/compiler/rustc_session/src/cgu_reuse_tracker.rs +++ b/compiler/rustc_session/src/cgu_reuse_tracker.rs @@ -112,7 +112,7 @@ impl CguReuseTracker { not recorded", cgu_user_name, cgu_name ); - diag.span_fatal(error_span.0, &msg).raise(); + diag.span_fatal(error_span.0, &msg) } } } diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index e7dfc4b8c4128..acb2a1ae7efa9 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -421,7 +421,7 @@ impl Session { } pub fn span_fatal>(&self, sp: S, msg: &str) -> ! { - self.diagnostic().span_fatal(sp, msg).raise() + self.diagnostic().span_fatal(sp, msg) } pub fn span_fatal_with_code>( &self, @@ -429,7 +429,7 @@ impl Session { msg: &str, code: DiagnosticId, ) -> ! { - self.diagnostic().span_fatal_with_code(sp, msg, code).raise() + self.diagnostic().span_fatal_with_code(sp, msg, code) } pub fn fatal(&self, msg: &str) -> ! { self.diagnostic().fatal(msg).raise() @@ -492,12 +492,6 @@ impl Session { pub fn warn(&self, msg: &str) { self.diagnostic().warn(msg) } - pub fn opt_span_warn>(&self, opt_sp: Option, msg: &str) { - match opt_sp { - Some(sp) => self.span_warn(sp, msg), - None => self.warn(msg), - } - } /// Delay a span_bug() call until abort_if_errors() #[track_caller] pub fn delay_span_bug>(&self, sp: S, msg: &str) {