rust/src/libsyntax_ext
bors ddab91a5de Auto merge of #48056 - ExpHP:macro-commas, r=dtolnay
Comprehensively support trailing commas in std/core macros

I carefully organized the changes into four commits:

* Test cases
* Fixes for `macro_rules!` macros
* Fixes for builtin macros
* Docs for builtins

**I can easily scale this back to just the first two commits for now if such is desired.**

### Breaking (?) changes

* This fixes #48042, which is a breaking change that I hope people can agree is just a bugfix for an extremely dark corner case.

* To fix five of the builtins, 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 (hopefully correct) understanding that `libsyntax` is private rustc implementation detail.** After reviewing all call sites (which were, you guessed it, *precisely those five macros*), I believe the revised semantics are closer to the intended spirit of the function.

### Changes which may require concensus

Up until now, it could be argued that some or all the following macros did not conceptually take a comma-separated list, because they only took one argument:

  * **`cfg(unix,)`** (most notable since cfg! is unique in taking a meta tag)
  * **`include{,_bytes,_str}("file.rs",)`**  (in item form this might be written as "`include!{"file.rs",}`" which is even slightly more odd)
  * **`compile_error("message",);`**
  * **`option_env!("PATH",)`**
  * **`try!(Ok(()),)`**

So I think these particular changes may require some sort of consensus.  **All of the fixes for builtins are included this list, so if we want to defer these decisions to later then I can scale this PR back to just the first two commits.**

### Other notes/general requests for comment

* Do we have a big checklist somewhere of "things to do when adding macros?" My hope is for `run-pass/macro-comma-support.rs` to remain comprehensive.
* Originally I wanted the tests to also comprehensively forbid double trailing commas.  However, this didn't work out too well: [see this gist and the giant FIXME in it](https://gist.github.com/ExpHP/6fc40e82f3d73267c4e590a9a94966f1#file-compile-fail_macro-comma-support-rs-L33-L50)
* I did not touch `select!`. It appears to me to be a complete mess, and its trailing comma mishaps are only the tip of the iceberg.
* There are [some compile-fail test cases](5fa97c35da/src/test/compile-fail/macro-comma-behavior.rs (L49-L52)) that didn't seem to work (rustc emits errors, but compile-fail doesn't acknowledge them), so they are disabled. Any clues? (Possibly related: These happen to be precisely the set of errors which are tagged by rustc as "this error originates in a macro outside of the current crate".)

---

Fixes #48042
Closes #46241
2018-02-28 07:10:05 +00:00
..
deriving Replace dummy spans with empty spans 2018-02-18 00:10:40 +09:00
asm.rs Make inline assembly volatile if it has no outputs. Fixes #46026 2018-02-05 15:56:44 +01:00
Cargo.toml Move unused-extern-crate to late pass 2017-08-27 19:02:24 +09:00
cfg.rs libsyntax/ext: trailing commas in builtin macros 2018-02-07 12:48:21 -05:00
compile_error.rs Stabilize the compile_error_macro feature 2017-07-25 07:09:31 -07:00
concat.rs Produce expansion info for more builtin macros 2017-09-04 11:03:19 +02:00
concat_idents.rs Produce expansion info for more builtin macros 2017-09-04 11:03:19 +02:00
env.rs Produce expansion info for more builtin macros 2017-09-04 11:03:19 +02:00
format.rs Add secondary span pointing at the statement (error span) 2018-01-16 18:13:43 -08:00
format_foreign.rs Use Try syntax for Option in place of macros or match 2017-12-09 14:18:33 -08:00
global_asm.rs Replace dummy spans with empty spans 2018-02-18 00:10:40 +09:00
lib.rs Use hygiene to access the injected crate (core or std) from builtin macros. 2017-12-09 17:22:07 -08:00
log_syntax.rs make emit_feature_err take a ParseSess 2016-09-26 07:07:41 +02:00
proc_macro_impl.rs Do not capture stderr in the compiler. Instead just panic silently for fatal errors 2018-01-26 04:52:30 +01:00
proc_macro_registrar.rs Change ast::Visibility to Spanned type 2018-02-18 00:10:40 +09:00
trace_macros.rs Move syntax::util::interner -> syntax::symbol, cleanup. 2016-11-20 23:40:20 +00:00