@@ -1161,6 +1161,18 @@ pub fn check_zero_tts(cx: &ExtCtxt<'_>, sp: Span, tts: TokenStream, name: &str)
1161
1161
}
1162
1162
}
1163
1163
1164
+ /// Parse an expression. On error, emit it, advancing to `Eof`, and return `None`.
1165
+ fn parse_expr ( p : & mut parser:: Parser < ' _ > ) -> Option < P < ast:: Expr > > {
1166
+ match p. parse_expr ( ) {
1167
+ Ok ( e) => return Some ( e) ,
1168
+ Err ( mut err) => err. emit ( ) ,
1169
+ }
1170
+ while p. token != token:: Eof {
1171
+ p. bump ( ) ;
1172
+ }
1173
+ None
1174
+ }
1175
+
1164
1176
/// Interpreting `tts` as a comma-separated sequence of expressions,
1165
1177
/// expect exactly one string literal, or emit an error and return `None`.
1166
1178
pub fn get_single_str_from_tts (
@@ -1174,7 +1186,7 @@ pub fn get_single_str_from_tts(
1174
1186
cx. span_err ( sp, & format ! ( "{} takes 1 argument" , name) ) ;
1175
1187
return None ;
1176
1188
}
1177
- let ret = panictry ! ( p . parse_expr( ) ) ;
1189
+ let ret = parse_expr ( & mut p ) ? ;
1178
1190
let _ = p. eat ( & token:: Comma ) ;
1179
1191
1180
1192
if p. token != token:: Eof {
@@ -1183,8 +1195,8 @@ pub fn get_single_str_from_tts(
1183
1195
expr_to_string ( cx, ret, "argument must be a string literal" ) . map ( |( s, _) | s. to_string ( ) )
1184
1196
}
1185
1197
1186
- /// Extracts comma-separated expressions from `tts`. If there is a
1187
- /// parsing error, emit a non-fatal error and return `None`.
1198
+ /// Extracts comma-separated expressions from `tts`.
1199
+ /// On error, emit it, and return `None`.
1188
1200
pub fn get_exprs_from_tts (
1189
1201
cx : & mut ExtCtxt < ' _ > ,
1190
1202
sp : Span ,
@@ -1193,7 +1205,7 @@ pub fn get_exprs_from_tts(
1193
1205
let mut p = cx. new_parser_from_tts ( tts) ;
1194
1206
let mut es = Vec :: new ( ) ;
1195
1207
while p. token != token:: Eof {
1196
- let expr = panictry ! ( p . parse_expr( ) ) ;
1208
+ let expr = parse_expr ( & mut p ) ? ;
1197
1209
1198
1210
// Perform eager expansion on the expression.
1199
1211
// We want to be able to handle e.g., `concat!("foo", "bar")`.
0 commit comments