Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to fall through past $:lifetime matcher #51477

Closed
dtolnay opened this issue Jun 10, 2018 · 3 comments · Fixed by #51480
Closed

Unable to fall through past $:lifetime matcher #51477

dtolnay opened this issue Jun 10, 2018 · 3 comments · Fixed by #51480
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@dtolnay
Copy link
Member

dtolnay commented Jun 10, 2018

This is similar to the same buggy behavior we saw for $:ident matchers fixed in 1.20.0.

For example in Rust 1.19 the following code fails to compile with the message "expected ident, found @", but correctly prints ident followed by other as of 1.20.

macro_rules! m {
    ($ident:ident) => { println!("ident"); };
    ($other:tt) => { println!("other"); };
}

fn main() {
    m!(ident);
    m!(@);
}

The $:lifetime matcher is currently broken in the same way.

macro_rules! m {
    ($lifetime:lifetime) => { println!("lifetime"); };
    ($other:tt) => { println!("other"); };
}

fn main() {
    m!('lifetime);
    m!(@);
}
error: expected a lifetime, found `@`
 --> src/main.rs:8:8
  |
8 |     m!(@);
  |        ^

rustc 1.28.0-nightly (2a00629 2018-06-09)

@sgrif @durka

@dtolnay dtolnay added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Jun 10, 2018
@dtolnay
Copy link
Member Author

dtolnay commented Jun 10, 2018

The ident issue was #27832, so mentioning @kennytm who fixed that one in #42913. Would you be interested in taking a look at this similar case?

@kennytm
Copy link
Member

kennytm commented Jun 10, 2018

Duplicate of #50903. @jrlusby should still be working on it I think?

@dtolnay
Copy link
Member Author

dtolnay commented Jun 10, 2018

Thanks! Let's continue to track this as part of #50903.

@dtolnay dtolnay closed this as completed Jun 10, 2018
bors added a commit that referenced this issue Jun 11, 2018
Enable fall through past $:lifetime matcher

```rust
macro_rules! is_lifetime {
    ($lifetime:lifetime) => { true };
    ($other:tt) => { false };
}

fn main() {
    println!("{}", is_lifetime!('lifetime));
    println!("{}", is_lifetime!(@));
}
```

Before this fix, the `is_lifetime!` invocation would fail to compile with:

```
error: expected a lifetime, found `@`
 --> src/main.rs:8:33
  |
8 |     println!("{}", is_lifetime!(@));
  |                                 ^
```

Fixes #50903.
Fixes #51477.

r? @kennytm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants