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