Skip to content

Commit d5aafb8

Browse files
committed
Use struct_fatal in new_parser_from_file.
It's a little more concise, and the standard way to do it.
1 parent f5c0cd0 commit d5aafb8

File tree

1 file changed

+4
-5
lines changed
  • compiler/rustc_parse/src

1 file changed

+4
-5
lines changed

compiler/rustc_parse/src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_ast::tokenstream::TokenStream;
1919
use rustc_ast::{AttrItem, Attribute, MetaItem};
2020
use rustc_ast_pretty::pprust;
2121
use rustc_data_structures::sync::Lrc;
22-
use rustc_errors::{Diagnostic, FatalError, Level, PResult};
22+
use rustc_errors::{Diagnostic, PResult};
2323
use rustc_session::parse::ParseSess;
2424
use rustc_span::{FileName, SourceFile, Span};
2525

@@ -118,12 +118,11 @@ pub fn maybe_new_parser_from_source_str(
118118
pub fn new_parser_from_file<'a>(sess: &'a ParseSess, path: &Path, sp: Option<Span>) -> Parser<'a> {
119119
let source_file = sess.source_map().load_file(path).unwrap_or_else(|e| {
120120
let msg = format!("couldn't read {}: {}", path.display(), e);
121-
let mut diag = Diagnostic::new(Level::Fatal, msg);
121+
let mut err = sess.dcx.struct_fatal(msg);
122122
if let Some(sp) = sp {
123-
diag.span(sp);
123+
err.span(sp);
124124
}
125-
sess.dcx.emit_diagnostic(diag);
126-
FatalError.raise();
125+
err.emit();
127126
});
128127

129128
panictry_buffer!(&sess.dcx, maybe_source_file_to_parser(sess, source_file))

0 commit comments

Comments
 (0)