Skip to content

"item TryFrom is imported redundantly" doesn't have automatic fix #121315

Open
@fintelia

Description

@fintelia

Recently rustc starting warning on imports of TryFrom that are redundant with the prelude.

use std::convert::TryFrom;

fn main() {
    let _ = u32::try_from(5i32);
}

produces:

warning: the item `TryFrom` is imported redundantly
   --> src/main.rs:1:5
    |
1   | use std::convert::TryFrom;
    |     ^^^^^^^^^^^^^^^^^^^^^
    |
   ::: /home/jonathan/.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

Sadly, there's no automatic fix suggested here. For a single case it isn't too bad to do manually, but in a larger project the output may look more like:

$ cargo check --all-targets --all-features --message-format=short
    Checking image v0.24.8 (/home/jonathan/git/image)
src/io/mod.rs:3:5: warning: the item `TryFrom` is imported redundantly
src/codecs/avif/decoder.rs:6:5: warning: the item `TryFrom` is imported redundantly
src/codecs/bmp/decoder.rs:2:5: warning: the item `TryFrom` is imported redundantly
src/codecs/bmp/decoder.rs:4:25: warning: the item `Iterator` is imported redundantly
src/codecs/dxt.rs:10:5: warning: the item `TryFrom` is imported redundantly
src/codecs/farbfeld.rs:19:20: warning: the item `TryFrom` is imported redundantly
src/codecs/farbfeld.rs:19:29: warning: the item `TryInto` is imported redundantly
src/codecs/gif.rs:29:5: warning: the item `TryFrom` is imported redundantly
src/codecs/gif.rs:30:5: warning: the item `TryInto` is imported redundantly
src/codecs/hdr/decoder.rs:5:5: warning: the item `TryFrom` is imported redundantly
src/codecs/hdr/decoder.rs:7:5: warning: the item `Iterator` is imported redundantly
src/codecs/ico/decoder.rs:2:5: warning: the item `TryFrom` is imported redundantly
src/codecs/jpeg/decoder.rs:1:5: warning: the item `TryFrom` is imported redundantly
src/codecs/jpeg/encoder.rs:4:5: warning: the item `TryFrom` is imported redundantly
src/codecs/pnm/decoder.rs:1:5: warning: the item `TryFrom` is imported redundantly
src/codecs/pnm/decoder.rs:2:5: warning: the item `TryInto` is imported redundantly
src/codecs/tga/decoder.rs:11:5: warning: the item `TryFrom` is imported redundantly
src/codecs/tga/encoder.rs:6:11: warning: the item `TryFrom` is imported redundantly
src/codecs/tiff.rs:11:5: warning: the item `TryFrom` is imported redundantly
src/codecs/webp/encoder.rs:8:5: warning: the item `FromIterator` is imported redundantly
src/codecs/webp/decoder.rs:2:5: warning: the item `TryFrom` is imported redundantly
src/codecs/webp/extended.rs:1:5: warning: the item `TryInto` is imported redundantly
src/codecs/webp/huffman.rs:1:5: warning: the item `TryInto` is imported redundantly
src/codecs/webp/lossless.rs:7:5: warning: the item `TryFrom` is imported redundantly
src/codecs/webp/lossless.rs:8:5: warning: the item `TryInto` is imported redundantly
src/codecs/webp/lossless_transform.rs:1:5: warning: the item `TryFrom` is imported redundantly
src/codecs/webp/lossless_transform.rs:2:5: warning: the item `TryInto` is imported redundantly
src/codecs/webp/vp8.rs:16:5: warning: the item `TryInto` is imported redundantly
src/animation.rs:2:5: warning: the item `Iterator` is imported redundantly
src/image.rs:2:5: warning: the item `TryFrom` is imported redundantly
src/imageops/colorops.rs:548:28: warning: the item `ImageBuffer` is imported redundantly
src/codecs/hdr/decoder.rs:1024:9: warning: the item `Cursor` is imported redundantly
src/codecs/png.rs:792:9: warning: the item `ImageDecoder` is imported redundantly
src/codecs/png.rs:795:27: warning: the item `Read` is imported redundantly
warning: `image` (lib) generated 30 warnings
warning: `image` (lib test) generated 34 warnings (30 duplicates)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.67s

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-papercutDiagnostics: An error or lint that needs small tweaks.T-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