about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMichael Lamparski <diagonaldevice@gmail.com>2018-02-07 09:32:26 -0500
committerMichael Lamparski <diagonaldevice@gmail.com>2018-02-07 12:48:21 -0500
commit1137fb193583971f35e1d4b3cfcb25725948da4f (patch)
tree9cdab0fc2cd3facbad058dddd2125e323ba8dff3 /src
parent96eed862a08f0ee1d234f4f83419dd46fe58ccef (diff)
downloadrust-1137fb193583971f35e1d4b3cfcb25725948da4f.tar.gz
rust-1137fb193583971f35e1d4b3cfcb25725948da4f.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/libsyntax/ext/base.rs6
-rw-r--r--src/libsyntax_ext/cfg.rs2
2 files changed, 6 insertions, 2 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs
index 025aa94ce06..520ec942e42 100644
--- a/src/libsyntax/ext/base.rs
+++ b/src/libsyntax/ext/base.rs
@@ -890,8 +890,8 @@ pub fn check_zero_tts(cx: &ExtCtxt,
     }
 }
 
-/// Extract the string literal from the first token of `tts`. If this
-/// is not a string literal, emit an error and return None.
+/// Interpreting `tts` as a comma-separated sequence of expressions,
+/// expect exactly one string literal, or emit an error and return None.
 pub fn get_single_str_from_tts(cx: &mut ExtCtxt,
                                sp: Span,
                                tts: &[tokenstream::TokenTree],
@@ -903,6 +903,8 @@ pub fn get_single_str_from_tts(cx: &mut ExtCtxt,
         return None
     }
     let ret = panictry!(p.parse_expr());
+    let _ = p.eat(&token::Comma);
+
     if p.token != token::Eof {
         cx.span_err(sp, &format!("{} takes 1 argument", name));
     }
diff --git a/src/libsyntax_ext/cfg.rs b/src/libsyntax_ext/cfg.rs
index 1d8dc406468..1eeba9b30b8 100644
--- a/src/libsyntax_ext/cfg.rs
+++ b/src/libsyntax_ext/cfg.rs
@@ -28,6 +28,8 @@ pub fn expand_cfg<'cx>(cx: &mut ExtCtxt,
     let mut p = cx.new_parser_from_tts(tts);
     let cfg = panictry!(p.parse_meta_item());
 
+    let _ = p.eat(&token::Comma);
+
     if !p.eat(&token::Eof) {
         cx.span_err(sp, "expected 1 cfg-pattern");
         return DummyResult::expr(sp);