Rollup merge of #65974 - Centril:matcher-friendly-gating, r=petrochenkov

A scheme for more macro-matcher friendly pre-expansion gating

Pre-expansion gating will now avoid gating macro matchers that did not result in `Success(...)`. That is, the following is now OK despite `box 42` being a valid `expr` and that form being pre-expansion gated:

```rust
macro_rules! m {
    ($e:expr) => { 0 }; // This fails on the input below due to `, foo`.
    (box $e:expr, foo) => { 1 }; // Successful matcher, we should get `2`.
}

fn main() {
    assert_eq!(1, m!(box 42, foo));
}
```

Closes https://github.com/rust-lang/rust/issues/65846.

r? @petrochenkov
cc @Mark-Simulacrum
This commit is contained in:
Mazdak Farrokhzad 2019-11-07 08:51:57 +01:00 committed by GitHub
commit e19cb40fda
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 106 additions and 73 deletions

View file

@ -0,0 +1,14 @@
// run-pass
// Test that failing macro matchers will not cause pre-expansion errors
// even though they use a feature that is pre-expansion gated.
macro_rules! m {
($e:expr) => { 0 }; // This fails on the input below due to `, foo`.
($e:expr,) => { 1 }; // This also fails to match due to `foo`.
(box $e:expr, foo) => { 2 }; // Successful matcher, we should get `2`.
}
fn main() {
assert_eq!(2, m!(box 42, foo));
}