Skip to content

try_from_instead_of_from_str lint causes error when TryFrom::try_from parameter is not named 'value' #17877

Open

Description

@svix-jplatte

Summary

Clippy suggests a replacement that includes a hardcoded value: &str parameter, but the suggestion still uses the existing code's parameter name inside the function body.

Reproducer

Code:

#![allow(dead_code)]

struct Foo;

impl TryFrom<&str> for Foo {
    type Error = std::io::Error;

    fn try_from(s: &str) -> Result<Self, Self::Error> {
        _ = s;
        Ok(Self)
    }
}

Current output:

warning: `TryFrom<str>` could be `FromStr`
   ╭▸ src/lib.rs:5:1
   │
 5 │ ┏ impl TryFrom<&str> for Foo {
 6 │ ┃     type Error = std::io::Error;
 7 │ ┃
 8 │ ┃     fn try_from(s: &str) -> Result<Self, Self::Error> {
   ‡ ┃
12 │ ┃ }
   │ ┗━┛
   │
   ├ help: `FromStr` can also be implemented alongside `TryFrom` if you want to avoid breaking changes
   ├ help: for further information visit https://rust-lang.github.io/rust-clippy/main/index.html#try_from_instead_of_from_str
   ╰ note: `#[warn(clippy::try_from_instead_of_from_str)]` on by default
help: replace with
   ╭╴
 5 + impl core::str::FromStr for Foo {
 6 +     type Err = std::io::Error;
 7 + 
 8 +     fn from_str(value: &str) -> Result<Self, Self::Err> {
 9 +         let _ = s;
10 +         Ok(Self)
11 +     }
12 + }
   ╰╴

Desired output: The parameter should probably just use the same name as in the original impl, which would be a shorter diff than replacing all references in the body.

Version

rustc 1.101.0-nightly (822182db4 2026-10-13)
binary: rustc
commit-hash: 822182db4c4a1827256881d8c7aa685f0bcf2b11
commit-date: 2026-10-13
host: x86_64-unknown-linux-gnu
release: 1.101.0-nightly
LLVM version: 23.1.3

Additional Labels

@rustbot label +I-suggestion-causes-error

Activity

  1. added
    C-bugCategory: Clippy is not doing the correct thing
    on Oct 14, 2026
  2. added
    I-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied
    on Oct 14, 2026
  3. wasd243 commented on Oct 14, 2026

    @wasd243
    Contributor

    @rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions