Skip to content
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

tarpaulin and check-cfg #127271

Closed
Urgau opened this issue Jul 3, 2024 · 4 comments
Closed

tarpaulin and check-cfg #127271

Urgau opened this issue Jul 3, 2024 · 4 comments
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues.

Comments

@Urgau
Copy link
Member

Urgau commented Jul 3, 2024

Some of the crates I'm developing use

#[cfg(not(tarpaulin))

as recommended here: Ignoring Code in Files (Tarpaulin Readme)

It seems other projects do this too: GitHub Code Search

The recommended Cargo Toml section:

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

does not fix this.

Neither does:

unexpected_cfgs = { level = "warn", check-cfg = ['cfg(not(tarpaulin_include))'] }

because:

error: invalid `--check-cfg` argument: `cfg(not(tarpaulin_include))`
  |
  = note: `not(tarpaulin_include)` is invalid
  = note: `cfg()` arguments must be simple identifiers, `any()` or `values(...)`
  = note: visit <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more details

Maybe this should be done differently on tarpaulin's side, or I can just edit my build.rs. But maybe this should be supported.

Originally posted by @barafael in #124800 (comment)

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 3, 2024
@Urgau
Copy link
Member Author

Urgau commented Jul 3, 2024

@barafael I tried reproducing the issue locally but I'm unable to do so.

I created a new Cargo project added #[cfg(not(tarpaulin_include)] to the add function, then did cargo +nightly check, got the warning, then added the cfg to the Cargo.toml

[package]
name = "my_lib"
version = "0.1.0"
edition = "2021"

[dependencies]

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

and the re-did cargo +nightly check the warning was successfully removed.

Did you check on beta or nightly? Are the beta/nightly version update to date?
If the issue still reproduce, could you provide a reproducer code.

@taiki-e
Copy link
Member

taiki-e commented Jul 3, 2024

Some of the crates I'm developing use

#[cfg(not(tarpaulin))

This is "tarpaulin".

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

And this adds "tarpaulin_include" , not "tarpaulin".

@barafael
Copy link

barafael commented Jul 3, 2024

And this adds "tarpaulin_include" , not "tarpaulin".

correct, my bad. It's #![cfg(not(tarpaulin_include))]

@barafael
Copy link

barafael commented Jul 3, 2024

@Urgau never mind, I got confused, all works as expected. Thanks!

@Urgau Urgau closed this as completed Jul 3, 2024
@Urgau Urgau added C-discussion Category: Discussion or questions that doesn't represent real issues. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues.
Projects
None yet
Development

No branches or pull requests

4 participants