-
Notifications
You must be signed in to change notification settings - Fork 13.3k
find macro-feature occurrences within macro args #22245
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
find macro-feature occurrences within macro args #22245
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
This doesn't quite catch everything, e.g. macro_rules! foo {
($x: ident) => {
$x!("")
}
}
foo!(asm) is valid, AFAIK. |
Note: I am not actually thrilled with the approach I used here; it "works", and we may want to include it nonetheless. But I probably need (for other checks, namely the check for placement- (And if I do the latter, then the fix given here has a lower priority.) |
@huonw yes, it doesn't catch that. The main thing it catches that my "inject-a-marker" approach would not catch is a scenario where the user has a macro that discards its input. (And that probably is not so important to catch.) The other thing I have been wondering is if there are legitimate macros that this check would erroneously reject. |
52174fc
to
9f78885
Compare
Oh, I just thought of an alternate way to do this sort of feature gating: just register the existence of the various macro-related pub fn expand_quote_tokens<'cx>(cx: &'cx mut ExtCtxt,
sp: Span,
tts: &[ast::TokenTree])
-> Box<base::MacResult+'cx> {
cx.sess.macro_features.gate(/* name of the feature */ "asm", /* name of the macro */ "asm"); where the This is then "perfect": any expansion of such a macro will be caught. The discarding-input macro is a possible downside, as well as being slightly error prone since we have to remember to insert the check (but it seems any scheme has this). |
impl<'a> MacroVisitor<'a> { | ||
fn check_ident(&self, id: ast::Ident, span: Span) { | ||
for &(s, readable) in &[("asm", "inline assembly"), | ||
("log_syntax", "`log_syntax!`"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: indentation
@huonw huh. I always thought of |
So, this code seems fine, though the technique @huonw suggests seems more robust. |
@nikomatsakis Indeed, I am in the process of implementing a feature much like the one @huonw suggested. (It is necessary for properly feature-gating the desugaring-based (We may still want to do something like this PR, because occurrences of the macro that are hidden under |
(hein, I'll just close this PR; I think I have something close to working for the other approach, and I am not really convinced by the corner case I outlined above.) |
In feature_gate::MacroVisitor, find feature occurrences within macro arguments.
Fix #22234