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.
This commit is contained in:
parent
96eed862a0
commit
1137fb1935
@ -890,8 +890,8 @@ pub fn check_zero_tts(cx: &ExtCtxt,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the string literal from the first token of `tts`. If this
|
/// Interpreting `tts` as a comma-separated sequence of expressions,
|
||||||
/// is not a string literal, emit an error and return None.
|
/// expect exactly one string literal, or emit an error and return None.
|
||||||
pub fn get_single_str_from_tts(cx: &mut ExtCtxt,
|
pub fn get_single_str_from_tts(cx: &mut ExtCtxt,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
tts: &[tokenstream::TokenTree],
|
tts: &[tokenstream::TokenTree],
|
||||||
@ -903,6 +903,8 @@ pub fn get_single_str_from_tts(cx: &mut ExtCtxt,
|
|||||||
return None
|
return None
|
||||||
}
|
}
|
||||||
let ret = panictry!(p.parse_expr());
|
let ret = panictry!(p.parse_expr());
|
||||||
|
let _ = p.eat(&token::Comma);
|
||||||
|
|
||||||
if p.token != token::Eof {
|
if p.token != token::Eof {
|
||||||
cx.span_err(sp, &format!("{} takes 1 argument", name));
|
cx.span_err(sp, &format!("{} takes 1 argument", name));
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,8 @@ pub fn expand_cfg<'cx>(cx: &mut ExtCtxt,
|
|||||||
let mut p = cx.new_parser_from_tts(tts);
|
let mut p = cx.new_parser_from_tts(tts);
|
||||||
let cfg = panictry!(p.parse_meta_item());
|
let cfg = panictry!(p.parse_meta_item());
|
||||||
|
|
||||||
|
let _ = p.eat(&token::Comma);
|
||||||
|
|
||||||
if !p.eat(&token::Eof) {
|
if !p.eat(&token::Eof) {
|
||||||
cx.span_err(sp, "expected 1 cfg-pattern");
|
cx.span_err(sp, "expected 1 cfg-pattern");
|
||||||
return DummyResult::expr(sp);
|
return DummyResult::expr(sp);
|
||||||
|
Loading…
Reference in New Issue
Block a user