-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 future-incompatibility lint deprecated_cfg_attr_crate_type_name
#91632
Comments
I've filed a PR to make this deny-by-default: #99784 |
…, r=Mark-Simulacrum Make forward compatibility lint deprecated_cfg_attr_crate_type_name deny by default Turns the forward compatibility lint added by rust-lang#83744 to deprecate `cfg_attr` usage with `#![crate_type]` and `#![crate_name]` attributes into deny by default. Copying the example from rust-lang#83744: ```Rust #![crate_type = "lib"] // remains working #![cfg_attr(foo, crate_type = "bin")] // will stop working ``` Over 8 months have passed since rust-lang#83744 was merged so I'd say this gives ample time for people to have been warned, so we can make the warning stronger. No usage was found via grep.app except for one, which was in an unmaintained code base that didn't seem to be used in the open source eco system. The crater run conducted in rust-lang#83744 also didn't show up anything. cc rust-lang#91632 - tracking issue for the lint
…, r=Mark-Simulacrum Make forward compatibility lint deprecated_cfg_attr_crate_type_name deny by default Turns the forward compatibility lint added by rust-lang#83744 to deprecate `cfg_attr` usage with `#![crate_type]` and `#![crate_name]` attributes into deny by default. Copying the example from rust-lang#83744: ```Rust #![crate_type = "lib"] // remains working #![cfg_attr(foo, crate_type = "bin")] // will stop working ``` Over 8 months have passed since rust-lang#83744 was merged so I'd say this gives ample time for people to have been warned, so we can make the warning stronger. No usage was found via grep.app except for one, which was in an unmaintained code base that didn't seem to be used in the open source eco system. The crater run conducted in rust-lang#83744 also didn't show up anything. cc rust-lang#91632 - tracking issue for the lint
Since the grep.app seach conducted in the original PR there have been two new crates using it, despite the lint: #![cfg_attr(feature = "js", crate_type = "cdylib")]
#![cfg_attr(feature = "js", crate_type = "rlib")] azul: #![cfg_attr(feature ="cdylib", crate_type = "cdylib")]
#![cfg_attr(feature ="staticlib", crate_type = "staticlib")]
#![cfg_attr(feature ="rlib", crate_type = "rlib")] Both uses were added in 2021, after #83744 was opened and before it was merged. Also both only modify Maybe one could extend cargo to support |
Wouldn't |
It should actually, good point. Maybe the |
This doesn't work for me. My understanding is that |
Right, |
Oh that's very interesting, I didn't know that. I always assumed |
Nice, seems the azul usage has been removed in the meantime: fschutt/azul@6096a1b#diff-2486c782348527d5e8a121166f399ed1449c5960b8079859b573cbc5f8b184c2L3 Now only the usage in wasmer is remaining. It has been reduced to a single attr: I wonder whether it would be possible to enable |
Note that the docs still suggest this attribute |
Using plain |
Is there a recommended way for feature-controlled RUSTFLAGS='--crate-type cdylib' cargo build --features cdylib P.S. Good point @bjorn3, thx. |
|
thx, i think i will have to:
|
With |
@rustbot labels +I-lang-nominated Let's discuss whether to make this a hard error in Rust 2024. |
The problem is that sometimes
So try doing something like this in
Only attempt to compile |
Or, the only way I think, that is just write my own |
That's what was suggested in #91632 (comment) and what I'm doing since then. And I didn't have any issue with it so far, so would definitely recommend if that's something your project would permit. |
Yes, this solution is actually similar to a make script, except that it's written in Rust. So if we envision an elegant way to handle this situation without using this "make script" approach, it might be to add this logic to |
I don't think there is any "elegant" solution to this problem, but there is a bunch of solutions:
I think it's fine to live without an "elegant" solution because the use cases are pretty niche. |
5.1. Since "not all use cases require panic support", I think the Rust compiler should completely disable "eh_personality" by default if |
deprecated_cfg_attr_crate_type_name
lintdeprecated_cfg_attr_crate_type_name
deprecated_cfg_attr_crate_type_name
deprecated_cfg_attr_crate_type_name
…, r=Urgau Make deprecated_cfg_attr_crate_type_name a hard error Turns the forward compatibility lint added by rust-lang#83744 into a hard error, so now, while the `#![crate_name]` and `#![crate_type]` attributes are still allowed in raw form, they are now forbidden to be nested inside a `#![cfg_attr()]` attribute. The following will now be an error: ```Rust #![cfg_attr(foo, crate_name = "foobar")] #![cfg_attr(foo, crate_type = "bin")] ``` This code will continue working and is not deprecated: ```Rust #![crate_name = "foobar"] #![crate_type = "lib"] ``` The reasoning for this is explained in rust-lang#83744: it allows us to not have to cfg-expand in order to determine the crate's type and name. As of filing the PR, exactly two years have passed since rust-lang#99784 has been merged, which has turned the lint's default warning level into an error, so there has been ample time to move off the now-forbidden syntax. cc rust-lang#91632 - tracking issue for the lint
Closing as #129670 has been merged. It's on the path to being a hard error in the 1.83.0 release of Rust. |
I've tried to work on the followup refactor to #129670 to remove mutable state from directory for the incr comp session dir
general ordering concernsWith this change it's easier to determine the crate name earlier in the compilation, which might be useful for structuring the state. All one needs is to peek into the provided source file, with no other state needed. Obtaining the crate name and crate type are very dependency-free operations now. |
I think it would now be possible to revert #114622 in a way that doesn't re-introduce the global mutable state in TyCtxt. This would also allow rust/compiler/rustc_incremental/src/persist/fs.rs Lines 611 to 612 in 06d261d
rust/compiler/rustc_interface/src/util.rs Lines 466 to 470 in 06d261d
#![crate_type] correctly at all right now.) And rust/compiler/rustc_driver_impl/src/lib.rs Lines 752 to 753 in 06d261d
rust/compiler/rustc_driver_impl/src/lib.rs Line 766 in 06d261d
|
Incidentally my open PR #127581 does away with recomputing the crate name inside |
What is this lint about
The
deprecated_cfg_attr_crate_type_name
lint detects uses of the#![cfg_attr(..., crate_type = "...")]
and#![cfg_attr(..., crate_name = "...")]
attributes to conditionally specify the crate type and name in the source code. For example:#![cfg_attr(debug_assertions, crate_type = "lib")]
Explanation
The
#![crate_type]
and#![crate_name]
attributes require a hack in the compiler to be able to change the used crate type and crate name after macros have been expanded. Neither attribute works in combination with Cargo as it explicitly passes--crate-type
and--crate-name
on the commandline. These values must match the value used in the source code to prevent an error.How to fix this warning/error
To fix the warning use
--crate-type
on the commandline when running rustc instead of#![cfg_attr(..., crate_type = "...")]
and--crate-name
instead of#![cfg_attr(..., crate_name = "...")]
.We are interested to hear about any/all use cases for conditional
#![crate_type]
and#![crate_name]
attributes.Current status
deprecated_cfg_attr_crate_type_name
lint as warn-by-defaultdeprecated_cfg_attr_crate_type_name
lint deny-by-defaultdeprecated_cfg_attr_crate_type_name
lint a hard errorThe text was updated successfully, but these errors were encountered: