@@ -39,20 +39,17 @@ rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
3939// uses a HOF to parse anything, and <source> includes file and
4040// `source_str`.
4141
42- /// A variant of 'panictry!' that works on a `Vec<Diag>` instead of a single `Diag`.
43- macro_rules! panictry_buffer {
44- ( $e: expr) => { {
45- use std:: result:: Result :: { Err , Ok } ;
46- match $e {
47- Ok ( e) => e,
48- Err ( errs) => {
49- for e in errs {
50- e. emit( ) ;
51- }
52- FatalError . raise( )
42+ // Unwrap the result if `Ok`, otherwise emit the diagnostics and abort.
43+ fn unwrap_or_emit_fatal < T > ( expr : Result < T , Vec < Diag < ' _ > > > ) -> T {
44+ match expr {
45+ Ok ( expr) => expr,
46+ Err ( errs) => {
47+ for err in errs {
48+ err. emit ( ) ;
5349 }
50+ FatalError . raise ( )
5451 }
55- } } ;
52+ }
5653}
5754
5855pub fn parse_crate_from_file < ' a > ( input : & Path , psess : & ' a ParseSess ) -> PResult < ' a , ast:: Crate > {
@@ -86,7 +83,7 @@ pub fn parse_crate_attrs_from_source_str(
8683
8784/// Creates a new parser from a source string.
8885pub fn new_parser_from_source_str ( psess : & ParseSess , name : FileName , source : String ) -> Parser < ' _ > {
89- panictry_buffer ! ( maybe_new_parser_from_source_str( psess, name, source) )
86+ unwrap_or_emit_fatal ( maybe_new_parser_from_source_str ( psess, name, source) )
9087}
9188
9289/// Creates a new parser from a source string. Returns any buffered errors from lexing the initial
@@ -112,7 +109,7 @@ pub fn new_parser_from_file<'a>(psess: &'a ParseSess, path: &Path, sp: Option<Sp
112109 err. emit ( ) ;
113110 } ) ;
114111
115- panictry_buffer ! ( maybe_source_file_to_parser( psess, source_file) )
112+ unwrap_or_emit_fatal ( maybe_source_file_to_parser ( psess, source_file) )
116113}
117114
118115/// Given a session and a `source_file`, return a parser. Returns any buffered errors from lexing
@@ -148,7 +145,7 @@ pub fn source_file_to_stream(
148145 source_file : Lrc < SourceFile > ,
149146 override_span : Option < Span > ,
150147) -> TokenStream {
151- panictry_buffer ! ( maybe_source_file_to_stream( psess, source_file, override_span) )
148+ unwrap_or_emit_fatal ( maybe_source_file_to_stream ( psess, source_file, override_span) )
152149}
153150
154151/// Given a source file, produces a sequence of token trees. Returns any buffered errors from
0 commit comments