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

Cannot use ty followed by >> on macro #25274

Closed
thelink2012 opened this issue May 10, 2015 · 5 comments
Closed

Cannot use ty followed by >> on macro #25274

thelink2012 opened this issue May 10, 2015 · 5 comments
Assignees
Labels
A-grammar Area: The grammar of Rust A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-feature-request Category: A feature request, i.e: not implemented / a PR.

Comments

@thelink2012
Copy link

Using ty followed by >> doesn't work in a macro but it does works when followed by > > instead. This seems very like one of the old C++03 template issues.

Using >>: http://is.gd/KTICUL

macro_rules! test {
    (
        fn fun() -> Option<Box<$t:ty>>;
    ) => {
        fn fun(x: $t) -> Option<Box<$t>>
        { Some(Box::new(x)) }
    }
}

test! {
    fn fun() -> Option<Box<i32>>;
}

fn main() {
    fun(0).unwrap();
}

Gives

<anon>:4:32: 4:37 error: `$t:ty` is followed by `>>`, which is not allowed for `ty` fragments
<anon>:4         fn fun() -> Option<Box<$t:ty>>;
                                        ^~~~~

Using > > instead of >> fixes it: http://is.gd/gSD3MR

Meta

All the tests were conducted on the playpen using the nightly and beta option (no difference) so I'm not sure about the version but the issue also happens on my local installation rustc 1.0.0-beta.3 (5241bf9c3 2015-04-25) (built 2015-04-25) (yep a bit outdated but cba to update eh).

@steveklabnik steveklabnik added A-grammar Area: The grammar of Rust A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) labels May 10, 2015
@steveklabnik
Copy link
Member

Triage: no change

@keeperofdakeys
Copy link
Contributor

This might be fixed now
ping @jseyfried

@jseyfried
Copy link
Contributor

jseyfried commented Dec 15, 2016

This is still a bug -- I believe the issue is that the follow set checker does not allow >> after ty fragments.
cc @LeoTestard

@LeoTestard
Copy link
Contributor

@jseyfried: I guess you meant ty instead of tt? Indeed, it seems to me that it's a bug since >> can already occur umambiguously after a type in the grammar so it should be added to the FOLLOW set.

I'm not sure what the procedure is for adding tokens to FOLLOW sets. Should we go through the RFC process or just assume that it's a bug in the current design and just make a PR for it?

@jseyfried
Copy link
Contributor

@LeoTestard

I guess you meant ty instead of tt?

Yeah, edited.

I'm not sure what the procedure is for adding tokens to FOLLOW sets.

I think we should assume it is a bug and make a PR to fix. Adding a comment on the RFC PR or tracking issue would probably be a good idea, but I don't think we need to go through the RFC process.

@jseyfried jseyfried self-assigned this Jan 17, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 22, 2017
bors added a commit that referenced this issue Oct 10, 2018
Accept `Option<Box<$t:ty>>` in macro argument

Given the following code, compile successfuly:

```
macro_rules! test {
    (
        fn fun() -> Option<Box<$t:ty>>;
    ) => {
        fn fun(x: $t) -> Option<Box<$t>>
        { Some(Box::new(x)) }
    }
}

test! {
    fn fun() -> Option<Box<i32>>;
}
```

Fix #25274.
kennytm added a commit to kennytm/rust that referenced this issue Oct 24, 2018
Accept `Option<Box<$t:ty>>` in macro argument

Given the following code, compile successfuly:

```
macro_rules! test {
    (
        fn fun() -> Option<Box<$t:ty>>;
    ) => {
        fn fun(x: $t) -> Option<Box<$t>>
        { Some(Box::new(x)) }
    }
}

test! {
    fn fun() -> Option<Box<i32>>;
}
```

Fix rust-lang#25274.
pietroalbini added a commit to pietroalbini/rust that referenced this issue Oct 25, 2018
Accept `Option<Box<$t:ty>>` in macro argument

Given the following code, compile successfuly:

```
macro_rules! test {
    (
        fn fun() -> Option<Box<$t:ty>>;
    ) => {
        fn fun(x: $t) -> Option<Box<$t>>
        { Some(Box::new(x)) }
    }
}

test! {
    fn fun() -> Option<Box<i32>>;
}
```

Fix rust-lang#25274.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-grammar Area: The grammar of Rust A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-feature-request Category: A feature request, i.e: not implemented / a PR.
Projects
None yet
Development

No branches or pull requests

6 participants