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

'cargo check --all-targets --workspace' fails on stable #890

Closed
RalfJung opened this issue Jul 24, 2022 · 9 comments
Closed

'cargo check --all-targets --workspace' fails on stable #890

RalfJung opened this issue Jul 24, 2022 · 9 comments
Labels

Comments

@RalfJung
Copy link
Contributor

Running cargo check --all-targets --workspace on stable fails with the following error:

error[E0554]: `#![feature]` may not be used on the stable release channel
 --> crossbeam-channel/benches/crossbeam.rs:1:12
  |
1 | #![feature(test)]
  |            ^^^^

    Checking crossbeam-queue v0.3.6 (/home/r/src/rust/lib-crates/crossbeam/crossbeam-queue)
For more information about this error, try `rustc --explain E0554`.
error: could not compile `crossbeam-channel` due to previous error

In particular this means opening crossbeam in vscode with rust-analyzer on a stable toolchain will show that error.

@taiki-e
Copy link
Member

taiki-e commented Jul 24, 2022

This is a common problem with all Rust crates running benchmarks using the built-in benchmark suite. A simple workaround is to use --tests --examples instead of --all-targets on stable.

I would accept a patch to use criterion in benchmarks, but there is no motivation on our part to address this since this situation is so common.

@taiki-e taiki-e closed this as not planned Won't fix, can't repro, duplicate, stale Jul 24, 2022
@RalfJung
Copy link
Contributor Author

A simple workaround is to use --tests --examples instead of --all-targets on stable.

That doesn't help for vscode showing errors each time I open crossbeam.

@RalfJung
Copy link
Contributor Author

Ah, putting this into the settings helps:

    "rust-analyzer.checkOnSave.overrideCommand": [
        "cargo", "check", "--lib", "--bins", "--tests", "--examples", "--workspace", "--message-format=json"
    ],

I wonder if this should be the default for RA...

@RalfJung
Copy link
Contributor Author

RalfJung commented Aug 9, 2022

Sadly that work-around doesn't work, since it will break on packages that don't have a libs crate.

I don't think there is a way right now to configure RA globally that would just make this work. :/

@taiki-e
Copy link
Member

taiki-e commented Aug 9, 2022

--tests should implicitly enable --lib if exists because the library must be built to build the test (--bins as well).

So, I think "--tests --examples instead of --all-targets" mentioned in the above comment should be enough.

@RalfJung
Copy link
Contributor Author

RalfJung commented Aug 9, 2022

The lib crate could have unit tests disabled though.

@taiki-e
Copy link
Member

taiki-e commented Aug 9, 2022

Unit tests don't seem disabled.

$ cargo new --lib repro
$ cd repro
$ echo '#[test]
fn a() {
    let _; // failed to compile
}
' > src/tests.rs
$ echo '#[cfg(test)] mod tests;' > src/lib.rs
$ cargo check --tests            
    Checking repro v0.1.0 (/Users/taiki/projects/tmp/c/repro)
error[E0282]: type annotations needed
 --> src/tests.rs:3:9
  |
3 |     let _; // failed to compile
  |         ^
  |
help: consider giving this pattern a type
  |
3 |     let _: _; // failed to compile
  |          +++

For more information about this error, try `rustc --explain E0282`.

@RalfJung
Copy link
Contributor Author

RalfJung commented Aug 9, 2022

But you can disable them in Cargo.toml

[lib]
test = false

@RalfJung
Copy link
Contributor Author

RalfJung commented Aug 9, 2022

FWIW for now I have simply pinned my crossbeam folder to a nightly rustc to work around this. Crossbeam so far is the only crate I have encountered that is affected by this. (I can believe that it is common, there are simply not that many crates I submit patches to, and of the around two dozen or so, crossbeam is the only one with this problem.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants