Skip to content

Redundant import leaks prelude import #121312

Open
@eopb

Description

@eopb

Code

use std::convert::TryFrom;

pub trait Foo<T>: TryFrom<T> {}

Current output

Compiling playground v0.0.1 (/playground)
warning: the item `TryFrom` is imported redundantly
   --> src/lib.rs:1:5
    |
1   | use std::convert::TryFrom;
    |     ^^^^^^^^^^^^^^^^^^^^^
    |
   ::: /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:129:13
    |
129 |     pub use core::prelude::rust_2021::*;
    |             ------------------------ the item `TryFrom` is already defined here
    |
    = note: `#[warn(unused_imports)]` on by default

Desired output

Compiling playground v0.0.1 (/playground)
warning: the item `TryFrom` is imported redundantly
   --> src/lib.rs:1:5
    |
1   | use std::convert::TryFrom;
    |     ^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `TryFrom` is imported in the 2021 edition prelude
    = note: `#[warn(unused_imports)]` on by default

Rationale and extra context

The pub use core::prelude::rust_2021::*; import is a compiler detail. The user did not write that line so it's confusing to display it to them.

Other cases

No response

Rust Version

rustc 1.78.0-nightly (2bf78d12d 2024-02-18)
binary: rustc
commit-hash: 2bf78d12d33ae02d10010309a0d85dd04e7cff72
commit-date: 2024-02-18
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

Anything else?

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=cafa3c0983d012f7430097f0fbd32e4f

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions