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

Comments

Projects
None yet
6 participants
@thelink2012
Copy link

thelink2012 commented May 10, 2015

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

This comment has been minimized.

Copy link
Member

steveklabnik commented Nov 29, 2016

Triage: no change

@keeperofdakeys

This comment has been minimized.

Copy link
Contributor

keeperofdakeys commented Dec 15, 2016

This might be fixed now
ping @jseyfried

@jseyfried

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor

LeoTestard commented Dec 15, 2016

@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

This comment has been minimized.

Copy link
Contributor

jseyfried commented Dec 15, 2016

@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

bors added a commit that referenced this issue Oct 10, 2018

Auto merge of #54977 - estebank:macro-arg-parse, r=<try>
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

Rollup merge of rust-lang#54977 - estebank:macro-arg-parse, r=pnkfelix
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

Rollup merge of rust-lang#54977 - estebank:macro-arg-parse, r=pnkfelix
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.

@bors bors closed this in #54977 Oct 25, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.