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

Macro invocations allow type parameters in the path #28558

Closed
Manishearth opened this issue Sep 21, 2015 · 6 comments · Fixed by #34495
Closed

Macro invocations allow type parameters in the path #28558

Manishearth opened this issue Sep 21, 2015 · 6 comments · Fixed by #34495
Labels
A-grammar Area: The grammar of Rust A-parser Area: The parsing of Rust source code to an AST. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Manishearth
Copy link
Member

vec::<T,U,V,W::X::Y<Z>>![1,2,3,4]; is valid syntax and compiles to a regular vector.

This is because macros use Paths, not Idents as their names. Multi-segment paths are disallowed, but the path can have type parameters.

We can move macros to Idents, however this would not be backwards compatible since anyone using vec::<T>![1,2] would get a syntax error (even though the original syntax is meaningless). It's still a bug, so perhaps we can get away with this breaking change.

Thoughts?

cc @eddyb @alexcrichton

@Manishearth Manishearth added I-wrong A-grammar Area: The grammar of Rust A-parser Area: The parsing of Rust source code to an AST. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 21, 2015
@eddyb
Copy link
Member

eddyb commented Sep 21, 2015

I'd say fix it and do a crater run.

@alexcrichton
Copy link
Member

Sounds like a plan to me

@DemiMarie
Copy link
Contributor

Ping?

@eddyb
Copy link
Member

eddyb commented Jun 27, 2016

@drbo I don't think anyone worked on it.
In case someone wants to work on it, the two relevant points are type macros and expressions macros.
It should be possible to error if the path is absolute, has more than one component, or any lifetime/type parameters. We can then do a crater run to see if these are used in the wild for some reason.

@eddyb
Copy link
Member

eddyb commented Jun 27, 2016

cc @jseyfried @petrochenkov @nrc

@jseyfried
Copy link
Contributor

I fixed this in #34495.

Manishearth added a commit to Manishearth/rust that referenced this issue Jun 29, 2016
…ons, r=eddyb

Forbid type parameters and global paths in macro invocations

Fixes rust-lang#28558.
This is a [breaking-change]. For example, the following would break:
```rust
macro_rules! m { () => { () } }
fn main() {
    m::<T>!(); // Type parameters are no longer allowed in macro invocations
    ::m!(); // Global paths are no longer allowed in macro invocations
}
```
Any breakage can be fixed by removing the type parameters or the leading `::` (respectively).

r? @eddyb
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-parser Area: The parsing of Rust source code to an AST. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants