-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Macros bypass other feature gates #12122
Comments
This will likely require an overhaul of the |
Hm, and that won't necessarily work because macro invocations no longer exist in the ast after expansion. This may be a little though. |
It's a bit hacky, but we can always just run feature gating before and after expansion like we already do with |
It'd require a bit of trickyness since std-injection uses |
I feel like the check should happen where the macro is declared, not where it's used. (Currently neither happens of course, which is definitely wrong.) |
Feature gating after expansion means that clients of your macro will have to turn on feature gates even though they aren't using those features themselves. I feel like clients of a macro should not have to suffer the burden of dealing with this, especially as they only way they'll even know what gates to turn on is to compile, fail, and read the error message. Is there any way the feature gating machinery could read the macro definition and see the problem there? |
That would be hard for macro_rules! hey ( () => { #[feature(log_syntax)] log_syntax!() } ) and then rustc could run feature gating before and after expansion. It'd clutter up macros a bit though. |
Could the macro embed information about what feature gates are in effect at its definition, and then mark the generated AST with that same feature gate information? |
That'd be doable, but it'd have to be a manual opt-in thing by the macro author. |
It'd also preferably be mixed with properly scoped |
This definitely blocks unfeature-gating But it is technically not otherwise a 1.0 blocker. Yes it seems like enough of a trap to assign P-high; so that's what we're doing. |
Nominating, I believe our story around macros has changed in the meantime. |
I have a few ideas for this that involve parsing the rhs of each arm in the |
I've been thinking recently as well that we should just feature gate the entire expansion of the macro, regardless of where it came from. The parts that may be difficult to get around:
I'm not actually sure that the list is too long, so we may be able to surmount most of it! One example of we really need to check expansions is that the |
If we can get away with it I still think we should gate the macro definition as well, so as to not surprise unsuspecting users with libraries that are supposedly stable. |
Agreed! |
assigning 1.0 milestone; there are real problems that we need to resolve here, but we can also claim "just a bug" in many respects |
we believe this to be fixed now. At least, the playpen warned now on this updated example: #![feature(macro_rules)]
// This should be required
// #[feature(log_syntax)];
macro_rules! hey { () => { log_syntax!() } }
fn main() {
hey!()
} |
add to_string_trait_impl lint closes rust-lang#12076 changelog: [`to_string_trait_impl`]: add lint for direct `ToString` implementations
This uses the
log_syntax!
macro without thelog_syntax
feature gate:Nominating.
The text was updated successfully, but these errors were encountered: