Git Product home page Git Product logo

Comments (4)

Nilstrieb avatar Nilstrieb commented on June 30, 2024

@Urgau

from rust.

wesleywiser avatar wesleywiser commented on June 30, 2024

It seems to me that since the file is included in both build.rs and the built program, even if rustc-check-cfg suppressed the warnings about the surplus exe config in the program I might still wind up facing warnings about exe in the build.rs, since the println has not run at the time the build.rs is built. However I don't think this is the problem above, because in that case I would have expected the number of warnings to halve on adding the suppression line, not stay the same.

Your analysis here is correct, I think you just missed this tiny note which is that cargo suppresses identical warnings 🙂

Before uncommenting the cargo:rustc-cfg-check line:

...
warning: `spritetest` (build script) generated 4 warnings
warning: `spritetest` (bin "spritetest") generated 4 warnings (4 duplicates)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 11.66s

After:

...
warning: `spritetest` (build script) generated 4 warnings
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.47s

@Urgau what's the right way to deal with check-cfg warnings originating in build.rs?

from rust.

Urgau avatar Urgau commented on June 30, 2024

Adding the check-cfg args directly in the lint config should do it12.

Cargo.toml:

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(exe)'] }

Footnotes

  1. Note that this was added very recently, around 2 nightly version ago, be sure to update to the latest nightly.

  2. Note that using the check-cfg lint config currently produce a warning on beta, we are working on fixing that.

from rust.

mcclure avatar mcclure commented on June 30, 2024

Adding the check-cfg args directly in the lint config should do it12.

Cargo.toml:

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(exe)'] }

Footnotes

  1. Note that this was added very recently, around 2 nightly version ago, be sure to update to the latest nightly.
  2. Note that using the check-cfg lint config currently produce a warning on beta, we are working on fixing that.

Thank you, I should have updated to NEWEST nightly before filing. I see that with 2024-05-20 nightly rustc the [lint] IS recommended in a hint, so this hint would have solved my problem if I had upgraded this morning before filing.

The lint works as expected and my problem is resolved (lint removes warnings where println does not).

I have a recommendation. If you are merging build.rs and executable warnings, then in principle you know that my "exe" cfg warnings are coming (in part) from build.rs. Currently, you display two recommendations*, the build.rs print and the [lint]. In the case of a cfg warning originating from a build.rs, the build.rs print! will not help and you know that ahead of time. Therefore for these warnings, I suggest you omit the build.rs print recommendation and show only the [lint] recommendation.

If that is impractical, then you may close this issue.

* with rustc 1.80.0-nightly (b92758a9a 2024-05-20) I get:

warning: unexpected `cfg` condition name: `exe`
 --> src/rkyv_types.rs:6:7
  |
6 | #[cfg(exe)]
  |       ^^^
  |
  = help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `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`, `windows`
  = help: consider using a Cargo feature instead
  = help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
           [lints.rust]
           unexpected_cfgs = { level = "warn", check-cfg = ['cfg(exe)'] }
  = help: or consider adding `println!("cargo::rustc-check-cfg=cfg(exe)");` to the top of the `build.rs`
  = 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

from rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.