Commit Graph

2765 Commits

Author SHA1 Message Date
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](https://github.com/ExpHP/rust/blob/5fa97c35da2f0ee/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
Manish Goregaokar b52b33a386 Rollup merge of #48143 - nikomatsakis:termination_trait_in_tests, r=eddyb
Termination trait in tests

Support the `Termination` trait in unit tests (cc https://github.com/rust-lang/rust/issues/43301)

Also, a drive-by fix for #47075.

This is joint work with @bkchr.
2018-02-24 12:47:58 -08:00
Niko Matsakis 0625d4c282 begin crate-relative paths with crate 2018-02-22 17:31:37 -05:00
Seiichi Uchida b5099a708d Replace dummy spans with empty spans 2018-02-18 00:10:40 +09:00
Seiichi Uchida d6bdf296a4 Change ast::Visibility to Spanned type 2018-02-18 00:10:40 +09:00
bors b8398d947d Auto merge of #47752 - mark-i-m:at-most-once-rep, r=nikomatsakis
Implement `?` macro repetition

See rust-lang/rfcs#2298 (with disposition merge)
2018-02-11 18:11:01 +00:00
Michael Lamparski 1137fb1935 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.
2018-02-07 12:48:21 -05:00
Mark Mansi 549534e438 Update a few comments 2018-01-30 16:20:46 -06:00
Jonathan Goodman a99b5db56a stabilize match_beginning_vert 2018-01-30 16:00:55 -06:00
Mark Mansi 786b2ca155 Fix trailing whitespace 2018-01-30 12:45:35 -06:00
Mark Mansi 3859eca851 Improved tests + typo fixes + assert 2018-01-30 12:42:51 -06:00
Mark Mansi 3c15405c25 Add feature gate + tests 2018-01-30 12:42:51 -06:00
Mark Mansi 51ef7393ef Fix typo in error message + update tests 2018-01-30 12:41:04 -06:00
Mark Mansi f59b821944 Attempted fix for ? kleene op 2018-01-30 12:41:04 -06:00
Mark Mansi 5ac48ec826 Run rustfmt on macro_parser.rs 2018-01-30 12:38:02 -06:00
Mark Mansi c33649cd8e Run rustfmt on quoted.rs 2018-01-30 12:32:41 -06:00
Mark Mansi bb8110c1fc Update the macro parser to allow at most once repetitions for ? Kleene 2018-01-30 12:30:41 -06:00
Mark Mansi 760879bc88 Allow ? as a KleeneOp in the macro parser 2018-01-30 12:30:41 -06:00
kennytm f06a391a40 Rollup merge of #47732 - mark-i-m:markim_comments_0001, r=jseyfried
Run rustfmt and add doc comments to libsyntax/ext/tt/macro_parser.rs

Similar to #47603

cc @theotherphil since you reviewed my other PR 😄

And because they are already assigned on #47603:

r? @arielb1
2018-01-30 17:10:52 +08:00
kennytm 3e39180706 Rollup merge of #47603 - mark-i-m:markim_comments_0000, r=jseyfried
Run rustfmt and add doc comments to libsyntax/ext/tt/quoted.rs

I was already going to try to understand this code to try to implement rust-lang/rfcs#2298. I figured I would put that knowledge into comments and share... This PR contains _no changes_ to the code itself -- just formatting and comments.

I'm not sure what the best way to do this is. I plan to make more such PR for other files, but I figured it would have fewer conflicts if I do it file by file...
2018-01-30 17:10:49 +08:00
Mark Mansi 576294237b fix typos 2018-01-29 17:08:11 -06:00
Mark Mansi 2184400be7 Update comment 2018-01-29 16:37:57 -06:00
Mark Mansi e2d558ad56 A few more comments 2018-01-26 14:47:24 -06:00
Mark Mansi 02d1d92878 Still more comments 2018-01-26 14:47:24 -06:00
Mark Mansi b01b481db3 Added/improved comments 2018-01-26 14:47:24 -06:00
Mark Mansi 6d4ed65585 Added lots of comments + minor reorganization 2018-01-26 14:47:24 -06:00
Mark Mansi 0d7f193dd3 Added a bunch of comments to macro_parser.rs 2018-01-26 14:47:24 -06:00
Mark Mansi ac0c16d3b5 Run rustfmt on /libsyntax/ext/tt/macro_parser.rs 2018-01-26 14:47:24 -06:00
John Kåre Alsaker 9a8d6b8bb5 Do not capture stderr in the compiler. Instead just panic silently for fatal errors 2018-01-26 04:52:30 +01:00
John Kåre Alsaker ccf0d8399e Adds support for immovable generators. Move checking of invalid borrows across suspension points to borrowck. Fixes #44197, #45259 and #45093. 2018-01-23 05:10:38 +01:00
Mark Mansi ca0c080569 Fix typos 2018-01-21 16:03:47 -06:00
Mark Mansi 49431d4966 Add a bunch of doc comments 2018-01-19 16:39:54 -06:00
Mark Mansi c4befe1710 Run rustfmt and add comments 2018-01-19 15:46:15 -06:00
kennytm 35bf7f844c Rollup merge of #47481 - estebank:unused-args, r=arielb1
Point at unused arguments for format string

Avoid overlapping spans by only pointing at the arguments that are not
being used in the argument string. Enable libsyntax to have diagnostics
with multiple primary spans by accepting `Into<MultiSpan>` instead of
`Span`.

Partially addresses #41850.
2018-01-18 01:57:25 +08:00
Esteban Küber a4660dfea2 Point at unused arguments for format string
Avoid overlapping spans by only pointing at the arguments that are not
being used in the argument string. Enable libsyntax to have diagnostics
with multiple primary spans by accepting `Into<MultiSpan>` instead of
`Span`.
2018-01-15 21:38:12 -08:00
Carol (Nichols || Goulding) e168aa385b Reexport -> re-export in prose and documentation comments 2018-01-15 13:36:53 -05:00
Eduard-Mihai Burtescu 210ac01792 rustc: use {U,I}size instead of {U,I}s shorthands. 2018-01-04 03:12:04 +02:00
Malo Jaffré cbb32a9418 Fix docs for future pulldown migration 2018-01-01 14:44:12 +01:00
Matt Peterson f55242583c Cleanup 2017-12-28 11:52:50 -05:00
Matt Peterson b284419064 Add feature gate macro_lifetime_matcher 2017-12-28 11:33:44 -05:00
Matt Peterson 0e53360af6 Fix build and add a macro lifetime labels test 2017-12-28 11:32:05 -05:00
Michael Hewson e12b87096a replace parse_lifetime with expect_lifetime
made `parser::Parser::expect_lifetime` public, so it can be called from `macro_parser::parse_nt`
2017-12-28 11:32:05 -05:00
Michael Hewson 03a51019a4 Resurrecting #33135
Started rebasing @sgrif's PR #33135 off of current master. (Well, actually merging it into a new branch based off current master.)

The following files still need to be fixed or at least reviewed:

- `src/libsyntax/ext/tt/macro_parser.rs`: calls `Parser::parse_lifetime`, which doesn't exist anymore
- `src/libsyntax/parse/parser.rs`: @sgrif added an error message to `Parser::parse_lifetime`. Code has since been refactored, so I just took it out for now.
- `src/libsyntax/ext/tt/transcribe.rs`: This code has been refactored bigtime. Not sure whether @sgrif's changes here are still necessary. Took it out for this commit.
2017-12-28 11:32:05 -05:00
bors 5f7aeaf6e2 Auto merge of #47013 - topecongiro:issue-46655, r=petrochenkov
Do not expand a derive invocation when derive is not allowed

Closes #46655.

The first commit is what actually closes #46655. The second one is just a refactoring I have done while waiting on a test.
2017-12-28 06:45:31 +00:00
bors 6c06bfaeba Auto merge of #47017 - topecongiro:issue-33469, r=estebank
Do not panic on interpolated token inside quote macro

Closes #33469.
2017-12-28 01:25:38 +00:00
Seiichi Uchida d1aa29ba32 Do not panic on interpolated token inside quote macro 2017-12-26 22:11:18 +09:00
Seiichi Uchida 18da3c671b Do not expand a derive invocation when derive is not allowed
1. Change the return type of `expand_invoc()` and its subroutines to
   `Option<Expansion>` from `Expansion`.
2. Return `None` when expanding a derive invocation if the item cannot
   have derive on it (in `expand_derive_invoc()`).
2017-12-26 16:47:32 +09:00
est31 e5c3aac0b4 Make column macro output 1 based and document it 2017-12-24 02:20:06 +01:00
bors c2ecab1121 Auto merge of #46732 - estebank:silence-recovered-blocks, r=petrochenkov
Do not emit type errors on recovered blocks

When a parse error occurs on a block, the parser will recover and create
a block with the statements collected until that point. Now a flag
stating that a recovery has been performed in this block is propagated
so that the type checker knows that the type of the block (which will be
identified as `()`) shouldn't be checked against the expectation to
reduce the amount of irrelevant diagnostic errors shown to the user.

Fix #44579.
2017-12-22 07:22:33 +00:00
bors ba2741594b Auto merge of #46922 - kennytm:rollup, r=kennytm
Rollup of 14 pull requests

- Successful merges: #46636, #46780, #46784, #46809, #46814, #46820, #46839, #46847, #46858, #46878, #46884, #46890, #46898, #46918
- Failed merges:
2017-12-21 23:01:27 +00:00