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

Clippy incorrectly reports redundant imported items #12373

Closed
Robbepop opened this issue Feb 28, 2024 · 1 comment
Closed

Clippy incorrectly reports redundant imported items #12373

Robbepop opened this issue Feb 28, 2024 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@Robbepop
Copy link

Robbepop commented Feb 28, 2024

Summary

For my crate wasmi_core in https://github.com/wasmi-labs/wasmi/tree/master/crates/core I see the following warnings when running clippy on nightly channel:

warning: the item `Box` is imported redundantly
   --> crates/wasmi/src/store.rs:32:5
    |
32  | use alloc::boxed::Box;
    |     ^^^^^^^^^^^^^^^^^
    |
   ::: /Users/robin/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:125:13
    |
125 |     pub use super::v1::*;
    |             --------- the item `Box` is already defined here

Many more warnings pop up, but they all are very similar to the one above.
This import is required for proper no_std builds.

In lib.rs we do:

#[cfg(not(feature = "std"))]
extern crate alloc;

Thus alloc is always available as crate root import.

Lint Name

unused_imports

Reproducer

  • Clone the repository https://github.com/wasmi-labs/wasmi (rev = a2f299af2f97af3691e195a4473abaa93bca72f7)
  • Install clippy from current nightly channel. (I use clippy 0.1.78 (ef324565 2024-02-27))
  • Run cargo +nightly clippy -p wasmi_core

Version

rustc 1.78.0-nightly (ef324565d 2024-02-27)
binary: rustc
commit-hash: ef324565d071c6d7e2477a195648549e33d6a465
commit-date: 2024-02-27
host: aarch64-apple-darwin
release: 1.78.0-nightly
LLVM version: 18.1.0

Additional Labels

No response

@Robbepop Robbepop added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Feb 28, 2024
@Alexendoo
Copy link
Member

This is from rustc so you'd see the same with a cargo check, the lint was expanded to cover more cases - rust-lang/rust#117772

The code is evaluated with the std feature enabled where the import is redundant, but cfging every time you import Vec from alloc is understandably a hassle. It would be worth bringing up in rust-lang/rust#121708 this use case for wanting to disable the redundant import warnings

@Alexendoo Alexendoo closed this as not planned Won't fix, can't repro, duplicate, stale Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

2 participants