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

Consider pass macro invocation arguments as AST instead of TokenTree #12488

Closed
edwardw opened this issue Feb 23, 2014 · 6 comments
Closed

Consider pass macro invocation arguments as AST instead of TokenTree #12488

edwardw opened this issue Feb 23, 2014 · 6 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

Comments

@edwardw
Copy link
Contributor

edwardw commented Feb 23, 2014

That way, more sophisticated and precise transformation can be performed against AST before being passed into macro definitions. The main use case right now would be hygiene let bindings and loop labels.

Is this doable?

cc #12262 #10607 #12338

@sfackler
Copy link
Member

The macro invocation syntax is almost entirely freeform. I'm not sure how much more parsing can be done while still supporting stuff like

let map = make_map!(Hey, dude! This map should have type collections::HashMap. 
                    It contains mappings "a" => 1, "b" => 2, "c" => 3);

@pnkfelix
Copy link
Member

cc me.

@edwardw
Copy link
Contributor Author

edwardw commented Feb 25, 2014

I don't know. My hunch is since it is parsed inside macro definition anyway, we should be able to do something at the invocation site as well.

@huonw
Copy link
Member

huonw commented Feb 25, 2014

Macros can also be passed many different AST nodes, like an expression, an item, an ident, a block, a pattern, etc. etc., and there's no way to tell which the macro wants without knowing the definition of the macro (i.e. intertwining parsing and macro expansion, which is a strong negative in my mind).

And it's not necessarily "obvious" what a macro wants from the definition, e.g. a procedural macro written in Rust may change what it wants to be fed in non-obvious ways.

@jbclements
Copy link
Contributor

Yes, the point of macros is that you don't parse before the macro has had a crack at it. That's an important property of the MTWT model. I move that we close this issue.

@steveklabnik steveklabnik added O-macos Operating system: macOS A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) and removed O-macos Operating system: macOS labels Jan 23, 2015
@steveklabnik
Copy link
Member

Yes, I think this can be closed. This would need an RFC today, and I'm not even sure it's what we would want.

flip1995 pushed a commit to flip1995/rust that referenced this issue Jun 13, 2024
Disable `indexing_slicing` for custom Index impls

Fixes rust-lang/rust-clippy#11525

Disables `indexing_slicing` for custom Index impls, specifically any implementations that also do not have a `get` method anywhere along the deref chain (so, for example, it still lints on Vec, which has its `get` method as part of the deref chain).

Thanks `@y21` for pointing me in the right direction with a couple of handy util functions for deref chain and inherent methods, saved a headache there!

changelog: FP: Disable `indexing_slicing` for custom Index impls
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, ..)
Projects
None yet
Development

No branches or pull requests

6 participants