Skip to content

Cannot run cargo clippy with --example #1169

@kennytm

Description

@kennytm

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions