Skip to content

Commit 1137fb1

Browse files
committed
libsyntax/ext: trailing commas in builtin macros
Most notably this changes 'syntax::ext::base::get_single_str_from_tts' to accept a trailing comma, and revises the documentation so that this aspect is not surprising. I made this change under the understanding that this crate is private rustc implementation detail (I hope this is correct!). After reviewing all call sites, I believe the revised semantics are closer to the intended spirit of the function.
1 parent 96eed86 commit 1137fb1

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/libsyntax/ext/base.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -890,8 +890,8 @@ pub fn check_zero_tts(cx: &ExtCtxt,
890890
}
891891
}
892892

893-
/// Extract the string literal from the first token of `tts`. If this
894-
/// is not a string literal, emit an error and return None.
893+
/// Interpreting `tts` as a comma-separated sequence of expressions,
894+
/// expect exactly one string literal, or emit an error and return None.
895895
pub fn get_single_str_from_tts(cx: &mut ExtCtxt,
896896
sp: Span,
897897
tts: &[tokenstream::TokenTree],
@@ -903,6 +903,8 @@ pub fn get_single_str_from_tts(cx: &mut ExtCtxt,
903903
return None
904904
}
905905
let ret = panictry!(p.parse_expr());
906+
let _ = p.eat(&token::Comma);
907+
906908
if p.token != token::Eof {
907909
cx.span_err(sp, &format!("{} takes 1 argument", name));
908910
}

src/libsyntax_ext/cfg.rs

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pub fn expand_cfg<'cx>(cx: &mut ExtCtxt,
2828
let mut p = cx.new_parser_from_tts(tts);
2929
let cfg = panictry!(p.parse_meta_item());
3030

31+
let _ = p.eat(&token::Comma);
32+
3133
if !p.eat(&token::Eof) {
3234
cx.span_err(sp, "expected 1 cfg-pattern");
3335
return DummyResult::expr(sp);

0 commit comments

Comments
 (0)