Skip to content

Commit b28cc09

Browse files
committed
Support #[fatal(..)]
1 parent bfefefb commit b28cc09

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ impl<'a> AstValidator<'a> {
331331
let max_num_args: usize = u16::MAX.into();
332332
if fn_decl.inputs.len() > max_num_args {
333333
let Param { span, .. } = fn_decl.inputs[0];
334-
self.session.emit_err(FnParamTooMany { span, max_num_args });
334+
self.session.emit_fatal(FnParamTooMany { span, max_num_args });
335335
}
336336
}
337337

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub struct ForbiddenNonLifetimeParam {
106106
}
107107

108108
#[derive(SessionDiagnostic)]
109-
#[error(ast_passes::fn_param_too_many)]
109+
#[fatal(ast_passes::fn_param_too_many)]
110110
pub struct FnParamTooMany {
111111
#[primary_span]
112112
pub span: Span,

compiler/rustc_session/src/parse.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,17 @@ impl ParseSess {
360360
self.create_warning(warning).emit()
361361
}
362362

363+
pub fn create_fatal<'a>(
364+
&'a self,
365+
fatal: impl SessionDiagnostic<'a, !>,
366+
) -> DiagnosticBuilder<'a, !> {
367+
fatal.into_diagnostic(self)
368+
}
369+
370+
pub fn emit_fatal<'a>(&'a self, fatal: impl SessionDiagnostic<'a, !>) -> ! {
371+
self.create_fatal(fatal).emit()
372+
}
373+
363374
#[rustc_lint_diagnostics]
364375
pub fn struct_err(
365376
&self,
@@ -373,6 +384,11 @@ impl ParseSess {
373384
self.span_diagnostic.struct_warn(msg)
374385
}
375386

387+
#[rustc_lint_diagnostics]
388+
pub fn struct_fatal(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, !> {
389+
self.span_diagnostic.struct_fatal(msg)
390+
}
391+
376392
#[rustc_lint_diagnostics]
377393
pub fn struct_diagnostic<G: EmissionGuarantee>(
378394
&self,

compiler/rustc_session/src/session.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,15 @@ impl Session {
482482
pub fn emit_warning<'a>(&'a self, warning: impl SessionDiagnostic<'a, ()>) {
483483
self.parse_sess.emit_warning(warning)
484484
}
485+
pub fn create_fatal<'a>(
486+
&'a self,
487+
fatal: impl SessionDiagnostic<'a, !>,
488+
) -> DiagnosticBuilder<'a, !> {
489+
self.parse_sess.create_fatal(fatal)
490+
}
491+
pub fn emit_fatal<'a>(&'a self, fatal: impl SessionDiagnostic<'a, !>) {
492+
self.parse_sess.emit_fatal(fatal)
493+
}
485494
#[inline]
486495
pub fn err_count(&self) -> usize {
487496
self.diagnostic().err_count()

0 commit comments

Comments
 (0)