@@ -38,20 +38,17 @@ rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
38
38
// uses a HOF to parse anything, and <source> includes file and
39
39
// `source_str`.
40
40
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 ( ) ;
52
48
}
49
+ FatalError . raise ( )
53
50
}
54
- } } ;
51
+ }
55
52
}
56
53
57
54
pub 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(
85
82
86
83
/// Creates a new parser from a source string.
87
84
pub 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) )
89
86
}
90
87
91
88
/// 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
111
108
err. emit ( ) ;
112
109
} ) ;
113
110
114
- panictry_buffer ! ( maybe_source_file_to_parser( psess, source_file) )
111
+ unwrap_or_emit_fatal ( maybe_source_file_to_parser ( psess, source_file) )
115
112
}
116
113
117
114
/// 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(
147
144
source_file : Lrc < SourceFile > ,
148
145
override_span : Option < Span > ,
149
146
) -> 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) )
151
148
}
152
149
153
150
/// Given a source file, produces a sequence of token trees. Returns any buffered errors from
0 commit comments