diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-12-20 21:32:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-20 21:32:30 +0100 |
| commit | 4a792fdce11fde240ccd1a0ac9b5b3d73cd4979f (patch) | |
| tree | 28e6c9dd9ace6ad7def7597e1156e5f120771651 /compiler/rustc_session/src | |
| parent | 1a992573e6ecc8d276d132ca476202b0921ea7df (diff) | |
| parent | 701e2f708b95d508f90ffd5a3b234335662ae521 (diff) | |
| download | rust-4a792fdce11fde240ccd1a0ac9b5b3d73cd4979f.tar.gz rust-4a792fdce11fde240ccd1a0ac9b5b3d73cd4979f.zip | |
Rollup merge of #134561 - bjorn3:less_fatal_error_raise, r=compiler-errors
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.
Diffstat (limited to 'compiler/rustc_session/src')
| -rw-r--r-- | compiler/rustc_session/src/output.rs | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/compiler/rustc_session/src/output.rs b/compiler/rustc_session/src/output.rs index bd103e86e26..ff0419d06bf 100644 --- a/compiler/rustc_session/src/output.rs +++ b/compiler/rustc_session/src/output.rs @@ -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(); } } |
