Skip to content

Improve documentation on cap-lints  #5998

@behnam

Description

@behnam

I'm looking at some docs for the --cap-lints and it's not clear what the expected behavior is.

In https://doc.rust-lang.org/rustc/lints/levels.html, we have:

This feature is used heavily by Cargo; it will pass --cap-lints allow when compiling your dependencies, so that if they have any warnings, they do not pollute the output of your build.

In rust-lang/rfcs#1193 we have:

Cargo will then pass --cap-lints allow to all upstream dependencies when compiling code.

And in #1830 we have:

This commit adds support to Cargo to pass --cap-lints allow to all upstream
dependencies instead of -A warings. This should serve the same purpose of
suppressing warnings in upstream dependencies as well as preventing widespread
breakage whenever a change to a lint is introduced in the compiler.

And the RFC has similar wordings, with an emphasis at the end:

Modifications to existing lints to emit new warnings will not get triggered, and new lints will also be entirely suppressed only for upstream dependencies.


Reading all the docs above, I'm not sure what "upstream dependencies" mean exactly. From the rustc doc, it seems that it's just any dependent crate.

But my guess is that Cargo doesn't want to disable such warnings when working in a workspace. So, probably "upstream" means any dependency out of current manifest's workspace.

But, setting up a simple test tells me neither of the above is right, and I'm guessing again that "upstream" would mean anything not fetched from the local machine. (Which is a bit more confusing, because I would expect the same behavior if using a remote git repo or using a local checkout of that the same repo--both being outside of my current workspace.)


This is the library:

my-lint-error/src/lib.rs

#[deny(missing_copy_implementations)]

pub struct Foo {
    pub field: i32
}

and this is the caller:

my-caller-app/src/main.rs

extern crate my_lint_error;

fn main() {
    println!("Hello, world!");
}

and the caller's manifest has:

[dependencies]
my-lint-error = { path="../my-lint-error/" }

The build fails with the lint error coming from the dependency:

$ cargo build --manifest-path my-caller-app/Cargo.toml -v
   Compiling my-lint-error v0.1.0 (file:///.../my-lint-error)
     Running `rustc --crate-name my_lint_error /.../my-lint-error/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=a5f75dbabcaae9e9 -C extra-filename=-a5f75dbabcaae9e9 --out-dir /.../my-caller-app/target/debug/deps -C incremental=/.../my-caller-app/target/debug/incremental -L dependency=/.../my-caller-app/target/debug/deps`
error: type could implement `Copy`; consider adding `impl Copy`
 --> /.../my-lint-error/src/lib.rs:3:1
  |
3 | / pub struct Foo {
4 | |     pub field: i32
5 | | }
  | |_^
  |
note: lint level defined here
 --> /.../my-lint-error/src/lib.rs:1:8
  |
1 | #[deny(missing_copy_implementations)]
  |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

error: Could not compile `my-lint-error`.

Caused by:
  process didn't exit successfully: `rustc --crate-name my_lint_error /.../my-lint-error/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=a5f75dbabcaae9e9 -C extra-filename=-a5f75dbabcaae9e9 --out-dir /.../my-caller-app/target/debug/deps -C incremental=/.../my-caller-app/target/debug/incremental -L dependency=/.../my-caller-app/target/debug/deps` (exit code: 1)

The test shows how a deny error from a library is breaking cargo build in a dependent crate. Looking at the rustc command, there's no --cap-lints passed in. Running the same command with --cap-lints allow builds the dependent without any issues. Therefore, I'm guessing there's a bug here in Cargo.

What do you think? Did I miss something in the docs?

PS. I'm on today's nightly and my ~/.cargo/config only has a bunch of aliases, so I believe my personal configuration is not causing this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-documenting-cargo-itselfArea: Cargo's documentationA-lintsArea: rustc lint configurationS-needs-team-inputStatus: Needs input from team on whether/how to proceed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions