@@ -38,20 +38,17 @@ rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
3838// uses a HOF to parse anything, and <source> includes file and
3939// `source_str`.
4040
41- /// A variant of 'panictry!' that works on a `Vec<Diag>` instead of a single `Diag`.
42- macro_rules! panictry_buffer {
43- ( $e: expr) => { {
44- use std:: result:: Result :: { Err , Ok } ;
45- match $e {
46- Ok ( e) => e,
47- Err ( errs) => {
48- for e in errs {
49- e. emit( ) ;
50- }
51- FatalError . raise( )
41+ // Unwrap the result if `Ok`, otherwise emit the diagnostics and abort.
42+ fn unwrap_or_emit_fatal < T > ( expr : Result < T , Vec < Diag < ' _ > > > ) -> T {
43+ match expr {
44+ Ok ( expr) => expr,
45+ Err ( errs) => {
46+ for err in errs {
47+ err. emit ( ) ;
5248 }
49+ FatalError . raise ( )
5350 }
54- } } ;
51+ }
5552}
5653
5754pub fn parse_crate_from_file < ' a > ( input : & Path , psess : & ' a ParseSess ) -> PResult < ' a , ast:: Crate > {
@@ -85,7 +82,7 @@ pub fn parse_crate_attrs_from_source_str(
8582
8683/// Creates a new parser from a source string.
8784pub fn new_parser_from_source_str ( psess : & ParseSess , name : FileName , source : String ) -> Parser < ' _ > {
88- panictry_buffer ! ( maybe_new_parser_from_source_str( psess, name, source) )
85+ unwrap_or_emit_fatal ( maybe_new_parser_from_source_str ( psess, name, source) )
8986}
9087
9188/// Creates a new parser from a source string. Returns any buffered errors from lexing the initial
@@ -111,7 +108,7 @@ pub fn new_parser_from_file<'a>(psess: &'a ParseSess, path: &Path, sp: Option<Sp
111108 err. emit ( ) ;
112109 } ) ;
113110
114- panictry_buffer ! ( maybe_source_file_to_parser( psess, source_file) )
111+ unwrap_or_emit_fatal ( maybe_source_file_to_parser ( psess, source_file) )
115112}
116113
117114/// Given a session and a `source_file`, return a parser. Returns any buffered errors from lexing
@@ -147,7 +144,7 @@ pub fn source_file_to_stream(
147144 source_file : Lrc < SourceFile > ,
148145 override_span : Option < Span > ,
149146) -> TokenStream {
150- panictry_buffer ! ( maybe_source_file_to_stream( psess, source_file, override_span) )
147+ unwrap_or_emit_fatal ( maybe_source_file_to_stream ( psess, source_file, override_span) )
151148}
152149
153150/// Given a source file, produces a sequence of token trees. Returns any buffered errors from
0 commit comments