-
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
parser warning "macro
is experimental" interacts badly with module-level cfg
#104633
Comments
Two bits:
#![cfg(FALSE)]
fn test() {
do yeet;
} is a hard error for the unstable/experimental syntax. The unstable syntaxes that are only warnings when cfgd out is more an unfortunate happenstance, since this makes them at least somewhat syntax-stable. The ones uplifted to warnings by #99935 were ones crater said were essentially not being used at the time it was originally tested. |
Yes. But there are cases where one wants the entire crate to be cfg'd out, and that's where I ran into this. (See #104634 for the work-around. This is related to this
I assume this only works for
The thing is, this should work, since I am setting the feature gate #![feature(yeet_expr)]
#![cfg(FALSE_DOES_NOT_EXIST_IN_CFG)]
fn test() {
do yeet;
} If the parser has to parse all the things that are being |
I vaguely remember some discussions, but this seems slightly different? I am running in a nightly compiler either way. I am not asking that a stable compiler accept such a file. I don't think there is a stability risk here. The problem is that there is no way to set a If the parser goes over the entire file, no matter the |
Ah, this part, it may be doable, yes. |
If a |
move core::arch into separate file This works around rust-lang#104633 which otherwise leads to warnings in miri-test-libstd.
I have something similar. In SNAFU, I have a number of crates that are only for testing purposes. I was experimenting with Cargo.toml [package]
name = "repro"
version = "0.1.0"
edition = "2021"
[dependencies] src/lib.rs #![cfg(test)]
#![feature(yeet_expr)]
fn x() -> Result<(), i32> {
do yeet 0;
}
Is this the same case, or should I open a new issue? |
It's the same issue. I agree that it's reasonable to apply at least the If they were outer attributes, #[feature(...)]
#[cfg(...)]
crate {
} the |
@CAD97 yes that would resolve the issue for me. :) |
I guess that would technically be a breaking change since this will currently compile on stable #![feautre(...)]
#![cfg(notathing)] However, this generates an empty crate, so... doesn't seem terribly likely? The |
move core::arch into separate file This works around rust-lang/rust#104633 which otherwise leads to warnings in miri-test-libstd.
|
It turns out stuff breaks if features are considered for fully unconfigured crates #108221 (comment). |
This is not how it currently works in other places in the language, the attribute expansion algorithm always picks Things also break if we change the order to be fully left-to-right (I tried it, it would be nice to have this kind of simplification - #83331). I guess we could make an exception and change the order for the specific list of "very early" attributes, but I'm not sure it's good idea, maybe we should just leave this papercut alone. |
On the other hand it then becomes impossible to fully unconfigure a crate if it directly contains unstable syntax, which also doesn't seem right. I'll try to implement this left-to-right amendment for a second crater run, let's see what happens. |
Yeah, that is what prompted this issue. It can be worked around (by moving all unstable syntax our of the
Sounds plausible. Another option might be to special-case only |
Next attempt - #110141. |
…pkin expand: Change how `#![cfg(FALSE)]` behaves on crate root Previously it removed all other attributes from the crate root. Now it removes only attributes below itself (during both regular expansion and pre-configuration). So it becomes possible to configure some global crate properties even for fully unconfigured crates. Fixes rust-lang#104633 Part of rust-lang#110082
…pkin expand: Change how `#![cfg(FALSE)]` behaves on crate root Previously it removed all other attributes from the crate root. Now it removes only attributes below itself (during both regular expansion and pre-configuration). So it becomes possible to configure some global crate properties even for fully unconfigured crates. Fixes rust-lang#104633 Part of rust-lang#110082
…pkin expand: Change how `#![cfg(FALSE)]` behaves on crate root Previously it removed all other attributes from the crate root. Now it removes only attributes below itself (during both regular expansion and pre-configuration). So it becomes possible to configure some global crate properties even for fully unconfigured crates. Fixes rust-lang#104633 Part of rust-lang#110082
Hm, this had some odd fallout in miri-test-libstd, not sure what is going on there |
Okay it's mostly resolved by reordering as one would expect: #112535. But one strange lint remains: warning: unknown lint: `fuzzy_provenance_casts`
--> std_miri_test/../library/std/src/lib.rs:610:1
|
610 | #[allow(dead_code, unused_attributes, fuzzy_provenance_casts)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the `fuzzy_provenance_casts` lint is unstable
= note: see issue #95228 <https://github.com/rust-lang/rust/issues/95228> for more information
= help: add `#![feature(strict_provenance)]` to the crate attributes to enable
= note: `#[warn(unknown_lints)]` on by default @petrochenkov looks like it is processing that |
Given code like this
what I expect should happen is that this works fine, since the feature flag is set so the parser should accept parsing the
pub macro
, and also the file is anyway empty aftercfg
expansion. However, I get a warning instead:It looks like the
cfg
does disable the feature flag, but does not disable parsing of the rest of the file. That is a problem, since it means it is impossible tocfg
-out an entire file that contains experimental syntax. I thought I could fix this by ordering thecfg
after thefeature
, but as the example shows that does not help.This probably started happening with #99935.
Cc @CAD97 @petrochenkov
The text was updated successfully, but these errors were encountered: