-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Warn when macro shadows previous definition #20277
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -640,6 +640,9 @@ pub fn expand_item_mac(it: P<ast::Item>, fld: &mut MacroExpander) | |
// need to be marked. Not that it could be marked anyway. | ||
// create issue to recommend refactoring here? | ||
fld.cx.syntax_env.insert(intern(name[]), ext); | ||
// Keep track of this macro definition both within the crate | ||
// context and (if applicable) in its exports. | ||
fld.cx.macros.push(it.clone()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that this quite catches shadowing per-se because you could have two disjoint modules with the same macro with the same name, but they're not shadowing one another. Where you had the logic before I believe was the correct place to put the logic. Did the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately The following idea definitely isn't the most elegant approach: instead of having the whole There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think something like that is the way to go. I'd probably avoid |
||
if attr::contains_name(it.attrs[], "macro_export") { | ||
fld.cx.exported_macros.push(it); | ||
} | ||
|
@@ -1209,7 +1212,10 @@ pub fn expand_crate(parse_sess: &parse::ParseSess, | |
} | ||
|
||
let mut ret = expander.fold_crate(c); | ||
// Copy the list of all macro expansions and exported macros into | ||
// the crate. | ||
ret.exported_macros = expander.cx.exported_macros.clone(); | ||
ret.macros = expander.cx.macros.clone(); | ||
parse_sess.span_diagnostic.handler().abort_if_errors(); | ||
return ret; | ||
} | ||
|
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.
Due to this being a known feature of the macro system, this should be
Allow
by default.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.
Gotcha, fixed!