xd009642/tarpaulin

tarpaulin_include needs adaptation for the new rust cfg checking lint

Closed this issue · 2 comments

A project that uses #[cfg(not(tarpaulin_include))] cfg as directed in the README will emit a warning on current nightlies due to the new unexpected_cfgs lint of rustc.

It would be a good idea to document this fact and suggest mitigation options like adding cfg(tarpaulin_include) to the [lints.rust.unexpected_cfgs] of Cargo.toml.

This is how I did it in my project:

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

Longer term, it would probably be a good idea to investigate if an alternative with better ergonomics than checking a cfg that does not exist in the eyes of rustc can be provided.

So looking at it I think the warning that rust gives you is perfectly fine and guides a user to do the right thing:

warning: unexpected `cfg` condition name: `tarpaulin_include`
 --> src/main.rs:1:12
  |
1 | #![cfg(not(tarpaulin_include))] 
  |            ^^^^^^^^^^^^^^^^^
  |
  = 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`, and `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(tarpaulin_include)'] }
  = help: or consider adding `println!("cargo::rustc-check-cfg=cfg(tarpaulin_include)");` 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

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

Tarpaulin does also support #[no_coverage] and if someone is willing to turn on the register toolchain nightly feature #[tarpaulin::skip]. I'll probably just rework the readme to put more emphasis on #[no_coverage] so people try to go to that first and leave it for rust to convey an adequate warning/suggestion.

There we go, pushed some readme changes now