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

Allow concat_idents! in type positions as well as in expression positions #33735

Merged
merged 1 commit into from
May 23, 2016

Conversation

jseyfried
Copy link
Contributor

@jseyfried jseyfried commented May 19, 2016

This allows the concat_idents! macro in type positions as well as in expression positions.
r? @nrc

@@ -9,7 +9,7 @@
// except according to those terms.

use syntax::ast::{self, TokenTree};
use syntax::codemap::Span;
use syntax::codemap::{Span, Spanned};
Copy link
Contributor

@oli-obk oli-obk May 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like you didn't use the Spanned type after all. (travis fails because it's unused)

Copy link
Contributor Author

@jseyfried jseyfried May 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed.

@jseyfried jseyfried force-pushed the concat_idents_in_ty_positions branch from e6e0d5e to e992794 Compare May 19, 2016 09:26
@retep998
Copy link
Member

Would this allow me to change this macro for example to only take $name and replace $inner with concat_idents!($name, __)?

macro_rules! DECLARE_HANDLE {
    ($name:ident, $inner:ident) => {
        pub enum $inner { }
        pub type $name = *mut $inner;
    };
}

@jseyfried
Copy link
Contributor Author

jseyfried commented May 20, 2016

@retep998
Sadly, it would not, since macro invocations cannot expand to idents.

I think it would be a good idea to allow macro invocations in the ident positions that are easy to parse -- everything but path segments (we plan to support paths::in::invocations!()) and $i: ident matchers (for backwards compatibility). We could still use concatenated idents as path segments via a built-in macro, for example concat_path!(foo::bar, concat_idents!(Ba, z)) => foo::bar::Baz.

However, that would require an RFC. Also, I believe it has been suggested that we instead implement "early-phase" macros invoked with !! (concat_idents!!(Fo, o)) that expand before parsing the token tree into AST. These early-phase invocations would be usable everywhere.

In the meantime, we could write a third party syntax extension with_concat_idents defined so that (for example) with_concat_idents!(foo, bar, |x| { ... x ... }) expands to ... foobar ....

This would allow you to change the macro to only take $name:

macro_rules! DECLARE_HANDLE {
    ($name:ident) => {
        with_concat_idents!($name, __, |inner| {
            pub enum inner { }
            pub type $name = *mut inner;
        });
    }
}

@nrc
Copy link
Member

nrc commented May 23, 2016

@bors: r+

@bors
Copy link
Contributor

bors commented May 23, 2016

📌 Commit e992794 has been approved by nrc

@bors
Copy link
Contributor

bors commented May 23, 2016

⌛ Testing commit e992794 with merge 213c773...

@alexcrichton
Copy link
Member

@bors: retry force clean

@bors
Copy link
Contributor

bors commented May 23, 2016

⌛ Testing commit e992794 with merge 72db775...

@alexcrichton
Copy link
Member

@bors: retry force clean

@bors
Copy link
Contributor

bors commented May 23, 2016

⌛ Testing commit e992794 with merge 1ccada6...

bors added a commit that referenced this pull request May 23, 2016
Allow `concat_idents!` in type positions as well as in expression positions

This allows the `concat_idents!` macro in type positions as well as in expression positions.
r? @nrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants