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