1
Fork 0

Reduce the amount of explicit FatalError.raise()

Instead use dcx.abort_if_error() or guar.raise_fatal() instead. These
guarantee that an error actually happened previously and thus we don't
silently abort.
This commit is contained in:
bjorn3 2024-12-20 14:08:24 +00:00
parent 8a1f8039a7
commit 701e2f708b
6 changed files with 22 additions and 41 deletions

View file

@ -3,7 +3,6 @@
use std::path::Path;
use rustc_ast::{self as ast, attr};
use rustc_errors::FatalError;
use rustc_span::{Span, Symbol, sym};
use crate::Session;
@ -90,11 +89,10 @@ pub fn find_crate_name(sess: &Session, attrs: &[ast::Attribute]) -> Symbol {
}
pub fn validate_crate_name(sess: &Session, s: Symbol, sp: Option<Span>) {
let mut err_count = 0;
let mut guar = None;
{
if s.is_empty() {
err_count += 1;
sess.dcx().emit_err(CrateNameEmpty { span: sp });
guar = Some(sess.dcx().emit_err(CrateNameEmpty { span: sp }));
}
for c in s.as_str().chars() {
if c.is_alphanumeric() {
@ -103,8 +101,7 @@ pub fn validate_crate_name(sess: &Session, s: Symbol, sp: Option<Span>) {
if c == '_' {
continue;
}
err_count += 1;
sess.dcx().emit_err(InvalidCharacterInCrateName {
guar = Some(sess.dcx().emit_err(InvalidCharacterInCrateName {
span: sp,
character: c,
crate_name: s,
@ -113,12 +110,12 @@ pub fn validate_crate_name(sess: &Session, s: Symbol, sp: Option<Span>) {
} else {
None
},
});
}));
}
}
if err_count > 0 {
FatalError.raise();
if let Some(guar) = guar {
guar.raise_fatal();
}
}