xd009642 / tarpaulin

A code coverage tool for Rust projects
https://crates.io/crates/cargo-tarpaulin
Apache License 2.0
2.5k stars 180 forks source link

Tarpaulin fails with `Error: cannot find attribute 'skip' in this scope"` with rust 1.52.0 even if skip isn't used #756

Closed Licenser closed 2 years ago

Licenser commented 3 years ago

Describe the bug

When trying to run tarpaulin in our project with rust v1.52.0 it fails with the error:

error: Broken pipe (os error 32)
warning: build failed, waiting for other jobs to finish...
error: Broken pipe (os error 32)
error: build failed
May 07 11:14:50.974 ERROR cargo_tarpaulin: Failed to compile tests! Error: cannot find attribute `skip` in this scope
Error: "Failed to compile tests! Error: cannot find attribute `skip` in this scope"

tarpaulin works with rust 1.51.0 and we do not use the skip attribute in the codebase

To Reproduce

clone https://github.com/tremor-rs/tremor-runtime and update the rust-toolchain file to 1.52.0

Expected behavior

projects working in 1.51.0 also work in 1.52.0

xd009642 commented 3 years ago

Interestingly, I got the same error but with a better message, it seems the error comes from an older version of bitvec which is used by nom (which is used by syslog_loose and hdrhistogram). It's bitvec 0.19.5 and they're currently on 0.22.3.

Also, nom can't update to the later bitvec which doesn't have the issue without bumping their MSRV so it might not be easily solvable. I think the issue there is likely down to the breaking change in the tarpaulin attributes and there is --avoid-cfg-tarpaulin to persist with the old behaviour (although that will make your tarpaulin attributes to ignore code useless).

I tried with --avoid-cfg-tarpaulin and got another issue with the crate procedural-masquerade (a member of rust-cssparser) so now just looking into that

xd009642 commented 3 years ago

oh I realised you're on 0.16.0 instead of one of the alphas so don't have --avoid-cfg-tarpaulin. But with 0.16.0 and 0.18.0-alpha3 I do get the skip error on rust 1.51 and 1.52 so not sure what changed there. Maybe one of the dependencies that pulled in bitvec had a patch bump that's being bought in that changes the bitvec version :thinking:

Licenser commented 3 years ago

Oi, would it be possible to ignore attributes in dependencies? Making sure that all 700 dependencies have their tests written with up-to-date tarpaulin attributes will be a bit of a nightmare. if tarpaulin gains more traction the rust ecosystem tendencies to small dependencies / crates could make that a bigger problem for breaking changes in the future.

Maybe one of the dependencies that pulled in bitvec had a patch bump that's being bought in that changes the bitvec version

they all should be locked in the lockfile so a updated rust-toolchaiun should :tm: not cause a change in dependencies

xd009642 commented 3 years ago

Oi, would it be possible to ignore attributes in dependencies?

We'd need a way to apply rust flags to only the top level crate and not the dependencies, unless there's something rust can do that I'm not aware of. I tried to do this once by calling rustc directly but it didn't work very well. The attributes also had the breaking change in 0.14.0 after I found minimal use of them in peoples code I don't expect a change like that again anytime soon. (Also, there is the flag to enable the legacy behaviour)

they all should be locked in the lockfile so a updated rust-toolchaiun should tm not cause a change in dependencies

So in my own production rust I rely on --locked to force it to use exactly what's in the lockfile as there seems to be some instances where things can slightly change

Licenser commented 3 years ago

I tried it with --locked, same codebase, ran tarpaulin with the rust-toolchain being 1.51.0 and it compiles then change the rust-toolchain to 1.52.1 and re-execute cargo tarpaulin --locked and it fails. I don't know what it is but something that changed between 1.51.0 and 1.52.0 did cause a degradation :(

r3dlight commented 3 years ago

Hi, Same issue here using Rust 1.52.0.

Compiling bitvec v0.19.5
error: Broken pipe (os error 32)
warning: build failed, waiting for other jobs to finish...
error: Broken pipe (os error 32)
error: build failed
May 11 13:17:29.567 ERROR cargo_tarpaulin: Failed to compile tests! Error: bitvec: cannot find attribute `skip` in this scope
Error: "Failed to compile tests! Error: bitvec: cannot find attribute `skip` in this scope"
Licenser commented 3 years ago

Update: I did try with the 18 alpha, which gets past it and compilation. the procedural-masquerade error is based on a false positive in a warning: https://github.com/rust-lang/rust/issues/83125 and can be solved with #![allow(proc_macro_back_compat)]

with that tarpaulin runs again :D

so the 18-alpha is a workaround but I'm still curious what causes the degradation :sweat_smile:

ralpha commented 3 years ago

Had the same issue, also with bitvec. Updating tarpaulin to the latest alpha version (EDIT: v0.18.x is out of alpha by now) ( cargo install cargo-tarpaulin --version 0.18.3 ) And adding the --avoid-cfg-tarpaulin flag solved the problem.

On my repo I had no further errors/warnings.

Geal commented 3 years ago

hello, I'm really sorry about the issues with bitvec and nom. I started the work on nom 7 which should fix them, but the rest of what I'd like to pass in that version is not ready yet, so in the meantime I published nom 7.0.0-alpha1 which only includes dependency updates. Could you check if it works for you?

Licenser commented 3 years ago

Hi Geal, don't be sorry :)! I can't test it sadly since nom isn't a direct dependency but rather pulled in in a number of different versions over a few other sub dependencies :(

Igosuki commented 3 years ago

@Licenser You can use [patch.crates-io] if you're feeling lucky

djc commented 3 years ago

With the tarpaulin 0.18.0 release, I still see this error in CI (GitHub Actions). Now that nom 7 has been released without the bitvec dependency enabled by default, is there some work we can do here? I looked into tarpaulin's dependency tree using cargo tree but did not any direct or indirect dependency on nom, so I'm a bit confused now.

0xAlcibiades commented 2 years ago

I'm still encountering this issue on the latest release.

xd009642 commented 2 years ago

@djc so it's not in tarpaulins dependency tree but rather projects wih tarpaulin being ran on them and there is the --avoid-cfg-tarpaulin flag to solve this. One thing I'm going to start doing is working on finding any users of nom 6 and submitting PRs to update the nom version to make sure as much as possible can be moved on from. I've just submitted this one which should fix it for tremor https://github.com/HdrHistogram/HdrHistogram_rust/pull/102 and any other users of the hdrhistogram crate

xd009642 commented 2 years ago

So anyone using hdrhistogram can now upgrade to 7.4.0 and that will be one more instance of skip removed from their dependency tree (and maybe the last one). I've just had to go to a PC without everything installed but iirc it was the only instance of skip in tremor @Licenser

jonhoo commented 2 years ago

7.4.0* :)

xd009642 commented 2 years ago

Oops, used to everyone being like me and too shy to go 1.0.0 :sweat_smile:

Geal commented 2 years ago

It's just a number, it's fine 😁

Licenser commented 2 years ago

I'll check :D

Licenser commented 2 years ago

Yay it is the last! :rocket:

Licenser commented 2 years ago

And with updating to 0.18.3 free 2% test coverage :D :rocket: from our side this is fully resolved :)

xd009642 commented 2 years ago

If everyone else with issues wants to check and let me know the projects if they still fail. I'll go on a hunt around the ecosystem upgrading things as needs be :smile: also if I don't hear anything else in a month or so I'll probably close this issue as inactive

ehiggs commented 2 years ago

I still get this on cargo-tarpaulin version: 0.18.5, rustc 1.56.1 (59eed8a2a 2021-11-01).

xd009642 commented 2 years ago

@ehiggs have you used --avoid-cfg-tarpaulin to switch to the legacy behaviour, and do you have the code open so I can track which dependency is bringing in the old style attributes?

ehiggs commented 2 years ago

I used cargo tarpaulin --avoid-cfg-tarpaulin and it worked now :tada: . You responded before I could delete my comment. :scream:

xd009642 commented 2 years ago

I was already on github doing some stuff :sweat_smile:. I'd still be interested in what the dependency is and if it's been updated or needs updating though

ehiggs commented 2 years ago
   Compiling bitvec v0.19.5
error: Broken pipe (os error 32)
warning: build failed, waiting for other jobs to finish...
error: Broken pipe (os error 32)
error: build failed
Nov 13 17:22:48.505 ERROR cargo_tarpaulin: Failed to compile tests! Error: bitvec: cannot find attribute `skip` in this scope
Error: "Failed to compile tests! Error: bitvec: cannot find attribute `skip` in this scope"
├── askama v0.10.5
│   ├── askama_derive v0.10.5 (proc-macro)
│   │   ├── askama_shared v0.11.1
│   │   │   ├── askama_escape v0.10.1
│   │   │   ├── humansize v1.1.1
│   │   │   ├── nom v6.1.2
│   │   │   │   ├── bitvec v0.19.5
│   │   │   │   │   ├── funty v1.1.0
│   │   │   │   │   ├── radium v0.5.3
│   │   │   │   │   ├── tap v1.0.1
│   │   │   │   │   └── wyz v0.2.0
│   │   │   │   ├── funty v1.1.0
│   │   │   │   ├── lexical-core v0.7.6
│   │   │   │   │   ├── arrayvec v0.5.2
│   │   │   │   │   ├── bitflags v1.3.2
│   │   │   │   │   ├── cfg-if v1.0.0
│   │   │   │   │   ├── ryu v1.0.5
│   │   │   │   │   └── static_assertions v1.1.0
│   │   │   │   └── memchr v2.4.1
│   │   │   │   [build-dependencies]
│   │   │   │   └── version_check v0.9.3
│   │   │   ├── num-traits v0.2.14
│   │   │   │   [build-dependencies]
│   │   │   │   └── autocfg v1.0.1
│   │   │   ├── percent-encoding v2.1.0
│   │   │   ├── proc-macro2 v1.0.30 (*)
│   │   │   ├── quote v1.0.10 (*)
│   │   │   ├── serde v1.0.130 (*)
│   │   │   ├── syn v1.0.80 (*)
│   │   │   └── toml v0.5.8
│   │   │       └── serde v1.0.130 (*)
│   │   ├── proc-macro2 v1.0.30 (*)
│   │   └── syn v1.0.80 (*)
│   ├── askama_escape v0.10.1
│   └── askama_shared v0.11.1 (*)
xd009642 commented 2 years ago

Okay just checked and the askama 0.12 beta has nom at 0.7 so you'll be able to remove the flag once the next version of askama is released (unless you wanted to move to a beta release ofc).

djc commented 2 years ago

The next version of Askama will hopefully be released soon, so it will no longer trigger this problem.

Licenser commented 2 years ago

Closing this as it's been resolved for us :)

0xAlcibiades commented 2 years ago

Seeing this again @xd009642:

Jul 22 19:51:04.606ERROR cargo_tarpaulin: Failed to compile tests! Error: coins-core: cannot find attribute `skip` in this scope
Error: "Failed to compile tests! Error: coins-core: cannot find attribute `skip` in this scope"
Error: The process '/home/runner/.cargo/bin/cargo' failed with exit code 1
xd009642 commented 2 years ago

@0xAlcibiades you can use --avoid-cfg-tarpaulin but whatever library is printing in the legacy skip macro should be updated (either bumping the dependency or PRing it and releasing a new one)