Skip to content

Warning in 2024 edition: unexpected cfg condition name: trybuild #20

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

Open
leecbaker opened this issue Mar 16, 2025 · 1 comment
Open
Assignees

Comments

@leecbaker
Copy link

When consuming this crate from Rust 2024 edition code, the following warning message is generated. It's not immediately obvious what the code is trying to do (#[cfg(trybuild)]).

warning: unexpected `cfg` condition name: `trybuild`
  --> simple/src/main.rs:6:5
   |
6  | /     #[message_bundle(
7  | |         resources = [
8  | |             ("l10n/en-US/messages.ftl", "en-US"),
9  | |             ("l10n/fr-CH/messages.ftl", "fr-CH"),
10 | |         ],
11 | |         default_language = "en-US")]
   | |____________________________________^
   |
   = help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `fmt_debug`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `ub_checks`, `unix`, and `windows`
   = note: using a cfg inside a attribute macro will use the cfgs from the destination crate and not the ones from the defining crate
   = help: try referring to `message_bundle` crate for guidance on how handle this unexpected cfg
   = help: the attribute macro `message_bundle` may come from an old version of the `fluent_static_macros` crate, try updating your dependency with `cargo update -p fluent_static_macros`
   = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
   = note: `#[warn(unexpected_cfgs)]` on by default
   = note: this warning originates in the attribute macro `message_bundle` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: `procmacro` (bin "procmacro") generated 1 warning

Reproducing

Reproduction of warning is fairly easy:

  • Modify the simple example to use the 2024 edition by changing examples/simple/Cargo.toml:4 from 2021 to 2024 edition:
-edition = "2021"
+edition = "2024"
  • Compile the example
$ rustc --version
rustc 1.85.0 (4d91de4e4 2025-02-17)
$ pwd
/Users/$me/fluent-static/examples/simple
$ cargo build

Origin code

crates/macros/src/lib.rs:36-41

                    quote! {
                        #[cfg(trybuild)]
                        const _: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR_OVERRIDE"), "/", #path));
                        #[cfg(not(trybuild))]
                        const _: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/", #path));
                    }

Compiled using

@zaytsev
Copy link
Owner

zaytsev commented Mar 16, 2025

Thanks for the detailed report.

                    quote! {
                        #[cfg(trybuild)]
                        const _: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR_OVERRIDE"), "/", #path));
                        #[cfg(not(trybuild))]
                        const _: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/", #path));
                    }

is basically a hack/workaround to make cargo build aware of changes in external file.
And until rust-lang/rust#99515 stabilized I don't see other options to implement this.

AFAIK #[cfg(trybuild)] is the only way to detect that code is running inside of test env created by trybuild

I'll take a look into this sometime next week, but for now I'd suggest to disable warning with

[lints.rust]
unexpected_cfgs = "allow"

@zaytsev zaytsev self-assigned this Mar 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants