Skip to content

Commit

Permalink
Make Diagnostic::span_fatal unconditionally raise an error
Browse files Browse the repository at this point in the history
It had no callers which didn't immediately call `raise()`, and this
unifies the behavior with `Session`.
  • Loading branch information
jyn514 committed May 9, 2021
1 parent e49f447 commit 96509b4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 19 deletions.
4 changes: 1 addition & 3 deletions compiler/rustc_ast_lowering/src/expr.rs
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_errors/src/lib.rs
Expand Up @@ -634,19 +634,19 @@ impl Handler {
DiagnosticBuilder::new(self, Level::Note, msg)
}

pub fn span_fatal(&self, span: impl Into<MultiSpan>, msg: &str) -> FatalError {
pub fn span_fatal(&self, span: impl Into<MultiSpan>, msg: &str) -> ! {
self.emit_diag_at_span(Diagnostic::new(Fatal, msg), span);
FatalError
FatalError.raise()
}

pub fn span_fatal_with_code(
&self,
span: impl Into<MultiSpan>,
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<MultiSpan>, msg: &str) {
Expand Down
14 changes: 5 additions & 9 deletions compiler/rustc_parse/src/lexer/mod.rs
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/cgu_reuse_tracker.rs
Expand Up @@ -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)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_session/src/session.rs
Expand Up @@ -421,15 +421,15 @@ impl Session {
}

pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
self.diagnostic().span_fatal(sp, msg).raise()
self.diagnostic().span_fatal(sp, msg)
}
pub fn span_fatal_with_code<S: Into<MultiSpan>>(
&self,
sp: S,
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()
Expand Down

0 comments on commit 96509b4

Please sign in to comment.