-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Deprecate crate_type and crate_name nested inside #![cfg_attr] #83744
Deprecate crate_type and crate_name nested inside #![cfg_attr] #83744
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
55d8d5f
to
13a7a35
Compare
This comment has been minimized.
This comment has been minimized.
Support for this was introduced in #25399. Part of the rationale was: #25347 (comment)
This is actually not true.
Surprisingly
I thought it merely had to match, just like the crate name. |
@bjorn3 To confirm, based on your knowledge of the compiler internals, you believe that if we manage to remove this and require that these directives only appear at the top level if at all, we can substantially simplify the logic to handle them in the Rust compiler? Your description that it's "somewhat of a hack in rustc" sounds like there's simplification to be had, and that simplification would be a reasonable motivation to make this change if it turns out no crates use it. |
Indeed
IMHO yes. In addition |
The former seems like a sufficient rationale to give this a try. Starting a try run in preparation for a crater run. If the crater run comes back clean, this seems potentially reasonable. |
@bors try |
⌛ Trying commit 8e4eb5f3283e0d02c4d46d144e6146011d1d4e73 with merge 45d8b6e68beee1c9c1ce92ae258a7e02f8f13aa4... |
☀️ Try build successful - checks-actions |
@craterbot check |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
|
All regressions are spurious. They are either network errors or linkers crashing without any output. |
That's really good, although a crater report might not be best suited to turn up cases where these things may occur, as I expect them to be used mainly outside of cargo built codebases. I've looke for crate_type and crate_name on google's opensource code search, couldn't find anything that could cause a problem. I've used searchcode.com to look for any repos on gitlab or bitbucket, but no cfg_attr use showed up. crate_type, crate_name. Using searchcode.com for github turns up too much repetitive stuff for it to be sifted through reasonably in a manual fashion. Same goes for github's builtin search, no way to narrow it down. Anyone know of a better search engine? |
grep.app shows exactly one usage: https://github.com/dropbox/divans/blob/23459c22f8a63e0a70ef1b968402ae0b3682168f/src/lib.rs#L21 This also enables two feature gates when the same cfg is used and they use cargo so it shouldn't have any effect. (I believe grep.app doesn't search all of github, but it does search a large portion in my experience) |
Interesting, thanks for pointing to grep.app! I'm a bit familiar with the repo it found, having filed a PR against it in 2018. It has been ignored for 2 years until I closed it. In that same period, nothing else has been commited to the repo's master branch (or any other PR filed/merged). So it's kinda dead I'd say. It might be used internally at dropbox, idk. So overall the fallout is manageable I think. |
Can this land as is, or should I turn it into a future compatibility lint? |
Discussed during lang meeting today -- we agreed this doesn't need FCP given just adding a future compatibility warning. I'll take a look at the impl itself shortly and request changes or indicate approval modulo the rebase. |
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.
r=me with the future compat issue filed
71f5717
to
ec3ec98
Compare
ec3ec98
to
8f6a8d6
Compare
8f6a8d6
to
9b6c510
Compare
@bors r+ rollup |
📌 Commit 9b6c510 has been approved by |
This implements the proposal in #83676 (comment), with a future compatibility lint imposed on usage of crate_type/crate_name inside cfg's.
This is a compromise between removing
#![crate_type]
and#![crate_name]
completely and keeping them as a whole, which requires somewhat of a hack in rustc and is impossible to support by gcc-rust. By only removing#![crate_type]
and#![crate_name]
nested inside#![cfg_attr]
it becomes possible to parse them before a big chunk of the compiler has started.Replaces #83676
Rationale
As it currently is it is possible to try to access the stable crate id before it is actually set, which will panic. The fact that the Session contains mutable state beyond debugging things also doesn't completely sit well with me. Especially once parallel rustc becomes the default.
I think there is currently also a cyclic dependency where you need to set the stable crate id to be able to load crates, but you need to load crates to expand proc macro attributes that may define #![crate_name] or #![crate_type]. Currently crate level proc macro attributes are unstable or completely unsupported (can't remember which), so this is not a problem, but it may become an issue in the future.
Finally if we want to add incremental compilation to macro expansion or even parsing, we need the StableCrateId to be created together with the Session or even earlier as incremental compilation determines the incremental compilation session dir based on the StableCrateId.