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

Unused imports not detected in dependencies #16868

Closed
bfops opened this issue Aug 30, 2014 · 3 comments
Closed

Unused imports not detected in dependencies #16868

bfops opened this issue Aug 30, 2014 · 3 comments

Comments

@bfops
Copy link
Contributor

bfops commented Aug 30, 2014

I believe the following set-up should trigger unused import warnings in dep/dep.rs, but it doesn't!

rustc 0.12.0-pre-nightly (2e92c67 2014-08-28 23:56:20 +0000)

Cargo.toml:

[package]

name = "testbed"
version = "0.0.0"
authors = []

[[bin]]

name = "testbed"
path = "./main.rs"

[dependencies.dep]
name = "dep"
path = "dep"

main.rs:

#[main]
pub fn main() {
}

dep/Cargo.toml:

[package]
name = "dep"
version = "0.0.0"
authors = []

[lib]
name = "dep"
path = "dep.rs"

dep/dep.rs:

use std::iter;
@ftxqxd
Copy link
Contributor

ftxqxd commented Aug 30, 2014

I don’t think this is a bug in Rust, just a bug in Cargo. I believe Cargo silences the output of compiling dependencies unless they fail. Running cargo build --verbose gives the command it runs:

rustc dep/dep.rs --crate-name dep --crate-type lib -C metadata=deadbeefdeadbeef -C extra-filename=-deadbeefdeadbeef --out-dir target/deps --dep-info target/.fingerprint/dep-deadbeefdeadbeef/dep-lib-dep -L target/deps -L target/deps

Running this command manually gives the warning as it should.

Moreover, if dep/dep.rs contains an error that occurs after the unused import warning does:

use std::iter;

pub fn f() {
    let _x: Box<str> = box *"hello world";
}

then the warning is printed correctly, followed by the error this code causes (in this case, an ICE).

@alexcrichton
Copy link
Member

Yes, this belongs in the cargo repository. Currently cargo captures all output of the compiler (intentionally) for dependencies, and does not print it by default (which causes the behavior you're seeing).

@bfops
Copy link
Contributor Author

bfops commented Aug 31, 2014

Good point! My mistake, thanks! I'll report it on cargo.

bors added a commit to rust-lang-ci/rust that referenced this issue Mar 31, 2024
fix: handle attributes when typing curly bracket

fix rust-lang#16848.

When inserting a `{`, if it is identified that the front part of `expr` is `attr`, we consider it as inserting `{}` around the entire `expr` (excluding the attr part).
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

3 participants