-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Tracking issue for "macro naming and modularisation" (RFC #1561) #35896
Comments
One question I don't think was ever answered on the RFC thread is if providing a way for current macros to opt in is feasible. Just throwing this out there as to make sure it doesn't get forgotten. My vote is obviously for yes we can, but I'm also obviously not on a team, or even an active contributor beyond these discussions. |
@camlorn this was actually address in my final edit to the RFC before merging. To summarise, it might be possible but we need implementation experience to be sure and to work out exactly how it might work. So, basically punting on the issue for now. It is certainly an area where I think we need to tread extremely carefully. |
macros: Future proof `#[no_link]` This PR future proofs `#[no_link]` for macro modularization (cc #35896). First, we resolve all `#[no_link] extern crate`s. `#[no_link]` crates without `#[macro_use]` or `#[macro_reexport]` are not resolved today, this is a [breaking-change]. For example, ```rust ``` Any breakage can be fixed by simply removing the `#[no_link] extern crate`. Second, `#[no_link] extern crate`s will define an empty module in type namespace to eventually allow importing the crate's macros with `use`. This is a [breaking-change], for example: ```rust mod syntax {} //< This becomes a duplicate error. ``` r? @nrc
c.f. #37732 (comment) |
Another problem with local_inner_macros: #52726 I guess since cargo-fix can't assume anything beyond the current crate, the only things it could do that would actually work are (a) nothing, or (b) somehow crawl the macro expansion and see which macros you really need to import. When cargo-fixing a macro-exporting crate, there's a question of whether to suggest A->B or A->C. |
Yes, I would say it this way: a library itself uses only one edition, but is always compatible with all editions - that is, you can depend on it whatever edition you are in. When we say that multiple editions can be compiled together, I think we are not expressing this compatibility forcefully enough: it is not possible to write a library that can only be depended on by crates on one edition or another. Library authors don't even have to worry about compatibility with multiple editions; they simply are compatible always. (Also unless somethings changed recently (and I don't think so, based on @dtolnay's post), the only thing editions change related to this issue are turning on some lints. Macro imports don't behave differently between 2015 and 2018 edition.) |
@dtolnay I want to clarify one thing based on your chart: you suggest that the "1" column options (using @Manishearth makes this comment that I don't understand:
I don't know what it means to "ask people to use them;" I haven't heard about this plan and it seems dubious. If we think people should use these warnings, we should have them turned on. As a rule, I do not believe we should ever have allow by default lints we recommend that you turn on; this is From my perspective, it seems like we should evaluate each 2018 idiom lint for disruptiveness and turn it on as soon as it seems like a net benefit. This will probably leave the macro related ones off for some time until the ecosystem has moved off the "A" system onto the "B" and "C" systems. Its unfortunate, but its the long term cost we're paying for having stabilized the "A" system for 1.0. |
It's not quite this, it's not The original plan was that we recommend a two step edition migration process. In the first step you turn on the migration lints and fix those, then you upgrade the edition in Cargo, and do the same again with the idiom lints. Ideally, this would be managed by cargo fix. The idiom lints aren't ones you keep enabled in perpetuity; you flip them on when you use cargo fix (or cargo fix flips them on for you), and when you're done with the upgrade you flip them off. We can make them on by default on 2018 a couple months into the edition if we wish, with the hope that everyone has The reason they're not just on by default is because these lints are super noisy and really need to be run with cargo fix. This is all being discussed in #52679 Given that many of the idiom lints are rather broken the current plan may just be to not recommend this for a while, and have a gradual rollout. |
@Manishearth thanks for the clarification! I think really when you say we recommend that you turn them on, the issue is what behavior I'll reply more about the general problem on the issue you linked. So I think the open issue here can be scoped down to this: what will For macro authorsIf For macro usersAssuming
Its possible that our behavior should change over time. It also occurs to me that if we do either 2 or 3, the user is likely to have a lock file that locks them to a version of the package that is incompatible. If we do any of these fixes, we should probably |
Since I was just reading about |
Probably a bad idea, but we could add another hack: What I still don't get is the business about "foundational crates". Sure, crates that are managed by the core team are special and we trust y'all, but how is Joe the Macro Author supposed to know whether their crate is special enough to ignore the |
@durka Since the version needed to compile a project with |
But lazy_static will be threading the needle by upgrading to B. |
Since options B2 and C2 work the only thing you have to watch out for is a dependency still using A. I assume detecting that a dependency is using option B is possible since that presumably is reflected in the metadata, so that should be easy to upgrade. Option C is likely undecidable, but the heuristic could just be "if dependency is Rust 2018 then they should be using option C" and upgrade the user (will break if a crate has updated to Rust 2018 but not transitioned to option C)? |
@withoutboats this plan seems pretty good! I think changing behavior over time is definitely something we should also try for; be pessimistic at first for macro users , and over time start suggesting fixes. There's also a lot of interesting stuff here that can be done by teaching cargo fix about good and bad macro crate versions. |
Building on @Nemo157's comment, if we can get this metadata for each of your dependencies:
That could be a good heuristic for whether or not we should upgrade their macro invokations. But I'm not sure how well the current set up allows rustfix to operate differently depending on the dependency metadata like this. We could consider disallowing option C on 2015, so that anyone who wants to stay on 2015 will switch to B, which we can detect, and anyone who wants to switch to C will move to 2018, which we can also detect. |
Well, we have crater, and we can use that to obtain this metadata ourselves and hardcode it (and hardcode what versions fix the problem) I don't expect there to be that many macro crates affected, especially if we only consider popular ones. The problem is that people depend on these. |
Wait, why is this still open? Everything on the roadmap is checked off. What's blocking this other than working out the kinks of a potential edition lint? |
Tracking issues close when stabilized. |
Stabilize `use_extern_macros` Closes #35896
I have a question. Why do we need to import macros to use them? For example: extern crate crossbeam;
use crossbeam::channel;
// Doesn't compile unless we uncomment this line:
// use self::channel::select;
fn main() {
channel::select! {
default => {}
}
} It is surprising to me that this code doesn't compile unless we import the macro. Is this intentional behavior or a bug? |
@stjepang maybe The expansion should use |
@dtolnay Oh right, that was indeed the issue. Thank you! :) |
Could I please request some transparency on what exactly is implemented by this "tracking issue" and what continued plans there are related to RFC 1561? My understanding of the process is that a tracking issue is not a place for discussion of how new features work (other than internal details), however I see a lot of discussion here of what exactly the new macro modularisation rules are. Perhaps part of the problem is that RFC 1561 is vague and far too broad. For example, 1561 declares the following which does not appear to be covered here (and does not appear to be possible on the latest nightly under either edition):
All documentation I can find is either hopelessly out of date or refers back to this issue. |
@dhardy unfortunately the transparency here is all written down, but it takes some effort to sift through it. What's stabilized here is described online and further tracking issues track remaining work items for known unstable items in the compiler. Work that hasn't ever been implemented from the original RFC doesn't currently have tracking issues, but they can definitely be created! |
* See <rust-lang/rust#35896 (comment)>. * This means #[macro_use] and #[macro_export(local_inner_macros)] can be obsolete. * See also <https://stackoverflow.com/a/67140319>
Tracking issue for rust-lang/rfcs#1561.
Roadmap: #35896 (comment).
cc @nrc @jseyfried
The text was updated successfully, but these errors were encountered: