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

Cannot run cargo clippy with --example #1169

Closed
kennytm opened this issue Aug 17, 2016 · 5 comments
Closed

Cannot run cargo clippy with --example #1169

kennytm opened this issue Aug 17, 2016 · 5 comments

Comments

@kennytm
Copy link
Member

kennytm commented Aug 17, 2016

When trying to run cargo clippy --example ..., the tool will error with:

error: extra arguments to rustc can only be passed to one target, consider filtering
the package by passing e.g. --lib or --bin NAME to specify a single target


Repro steps:

  1. Create a cargo project with the following structure

    project/
        Cargo.toml
        src/
            ...
        examples/
            one.rs
    
  2. Fill in one.rs with:

    /// BadComment.
    pub fn main() {
    }
  3. Run clippy:

    $ cargo clippy --example one
  4. Expecting a lint on /// BadComment. Got the error above instead.


Note that using the plugin, or running the lint via cargo rustc works fine:

$ cargo rustc --example one -- -L path/to/libclippy.dylib -Z extra-plugins=clippy
   Compiling test3 v0.1.0 (file:///path/to/project)
warning: you should put `BadComment` between ticks in the documentation, #[warn(doc_markdown)] on by default
 --> examples/one.rs:1:5
  |
1 | /// BadComment.
  |     ^^^^^^^^^^
  |
  = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#doc_markdown

    Finished debug [unoptimized + debuginfo] target(s) in 0.31 secs

Running cargo clippy without using any arguments will not lint the examples:

$ cargo clippy
   Compiling test3 v0.1.0 (file:///path/to/project)
    Finished debug [unoptimized + debuginfo] target(s) in 0.8 secs

Clippy version: v0.0.82

$ rustc -vV
rustc 1.12.0-nightly (197be89f3 2016-08-15)
binary: rustc
commit-hash: 197be89f367d1240d5f9cd9c4efd77812775354e
commit-date: 2016-08-15
host: x86_64-apple-darwin
release: 1.12.0-nightly

$ cargo -vV
cargo 0.13.0-nightly (cd8ad10 2016-08-15)
@Manishearth
Copy link
Member

I guess this is a cargo bug? We run cargo rustc --example foo -- <some arguments> for that command. cargo rustc errors if you don't select a bin/lib for a multitarget project, but it should work with --example

@kennytm
Copy link
Member Author

kennytm commented Aug 17, 2016

@Manishearth As I mentioned in the report, cargo rustc --example one -- -L path/to/libclippy.dylib -Z extra-plugins=clippy does work 😉 but cargo clippy --example one does not.

@oli-obk
Copy link
Contributor

oli-obk commented Aug 17, 2016

We don't even support cargo clippy --lib anymore, cargo clippy runs on all bin and lib targets. We probably need to add examples to the list of stuff that needs to be checked.

@oli-obk
Copy link
Contributor

oli-obk commented Aug 17, 2016

#1171 runs clippy on examples, too. But still no way to specify to only run on one example.

@phansch
Copy link
Member

phansch commented Mar 30, 2018

Looks like this was fixed with #2582, too:

$ cargo new repro && cd repro

$ echo >examples/one.rs '
fn main() {
    1111111111111111;
    ()
}
'

$ echo >examples/two.rs '
fn main() {
    2222222222222222;
    ()
}
'

Running cargo clippy --example one only lints example one and running cargo clippy --example two only lints example two.

To repro with the original example, it's now required to add #[warn(doc_markdown)] because the doc_markdown lint is now in the pedantic group which is allow by default.

I'm going ahead and close it, but feel free to re-open if it's still causing problems.

@phansch phansch closed this as completed Mar 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants