rust-lang / rust-lang/rust-clippy

unnecessary_fallible_conversions can't `into` a `Result`, missing trait impl

Open
#14,987 2 comments 0 reactions 1 assignee View on GitHub

@profetia is already working on this.

Since Jun 6, 2025.

I-suggestion-causes-error
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Using the following flags

--force-warn clippy::unnecessary_fallible_conversions

this code:

//@ check-pass
//@ edition:2021
#![warn(redundant_imports)]

use std::convert::TryFrom;//~ WARNING the item `TryFrom` is imported redundantly
use std::convert::TryInto;//~ WARNING the item `TryInto` is imported redundantly

fn main() {
    let _e: Result<i32, _> = 8u8.try_into();
    let _f: Result<i32, _> = i32::try_from(8u8);
}

caused the following diagnostics:

    Checking _use-redundant-prelude-rust-2021 v0.1.0 (/tmp/icemaker_global_tempdir.o4hDRjvshrmO/icemaker_clippyfix_tempdir.S6ziQ0lIGuC1/_use-redundant-prelude-rust-2021)
warning: use of a fallible conversion when an infallible one could be used
 --> src/main.rs:9:34
  |
9 |     let _e: Result<i32, _> = 8u8.try_into();
  |                                  ^^^^^^^^ help: use: `into`
  |
  = note: converting `u8` to `i32` cannot fail
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_fallible_conversions
  = note: requested on the command line with `--force-warn clippy::unnecessary-fallible-conversions`

warning: use of a fallible conversion when an infallible one could be used
  --> src/main.rs:10:30
   |
10 |     let _f: Result<i32, _> = i32::try_from(8u8);
   |                              ^^^^^^^^^^^^^ help: use: `From::from`
   |
   = note: converting `u8` to `i32` cannot fail
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_fallible_conversions

warning: `_use-redundant-prelude-rust-2021` (bin "_use-redundant-prelude-rust-2021") generated 2 warnings
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s

However after applying these diagnostics, the resulting code:

//@ check-pass
//@ edition:2021
#![warn(redundant_imports)]

use std::convert::TryFrom;//~ WARNING the item `TryFrom` is imported redundantly
use std::convert::TryInto;//~ WARNING the item `TryInto` is imported redundantly

fn main() {
    let _e: Result<i32, _> = 8u8.into();
    let _f: Result<i32, _> = From::from(8u8);
}

no longer compiled:

    Checking _use-redundant-prelude-rust-2021 v0.1.0 (/tmp/icemaker_global_tempdir.o4hDRjvshrmO/icemaker_clippyfix_tempdir.S6ziQ0lIGuC1/_use-redundant-prelude-rust-2021)
error[E0277]: the trait bound `std::result::Result<i32, _>: std::convert::From<u8>` is not satisfied
 --> src/main.rs:9:34
  |
9 |     let _e: Result<i32, _> = 8u8.into();
  |                                  ^^^^ the trait `std::convert::From<u8>` is not implemented for `std::result::Result<i32, _>`
  |
  = note: required for `u8` to implement `std::convert::Into<std::result::Result<i32, _>>`

error[E0277]: the trait bound `std::result::Result<i32, _>: std::convert::From<u8>` is not satisfied
  --> src/main.rs:10:41
   |
10 |     let _f: Result<i32, _> = From::from(8u8);
   |                              ---------- ^^^ the trait `std::convert::From<u8>` is not implemented for `std::result::Result<i32, _>`
   |                              |
   |                              required by a bound introduced by this call

For more information about this error, try `rustc --explain E0277`.
error: could not compile `_use-redundant-prelude-rust-2021` (bin "_use-redundant-prelude-rust-2021" test) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: could not compile `_use-redundant-prelude-rust-2021` (bin "_use-redundant-prelude-rust-2021") due to 2 previous errors

Version:

rustc 1.89.0-nightly (cf423712b 2025-06-05)
binary: rustc
commit-hash: cf423712b9e95e9f6ec84b1ecb3d125e55ac8d56
commit-date: 2025-06-05
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.