Skip to content

False positive in bound for is not a trait #147356

@A4-Tacks

Description

@A4-Tacks

Code

use std::str::FromStr;
fn foo<T: FromStr>() -> T
where
    <T as FromStr>::Err: Debug,
{
    "".parse().unwrap()
}

Current output

error[E0404]: expected trait, found derive macro `Debug`
 --> src/bin/main.rs:4:26
  |
4 |     <T as FromStr>::Err: Debug,
  |                          ^^^^^ not a trait
  |
help: constrain the associated type to `Debug`
  |
4 -     <T as FromStr>::Err: Debug,
4 +     T: FromStr<Err = Debug>,
  |
help: consider importing this trait instead
  |
1 + use std::fmt::Debug;
  |

For more information about this error, try `rustc --explain E0404`.

Desired output

error[E0404]: expected trait, found derive macro `Debug`
 --> src/bin/main.rs:4:26
  |
4 |     <T as FromStr>::Err: Debug,
  |                          ^^^^^ not a trait
  |
help: consider importing this trait instead
  |
1 + use std::fmt::Debug;
  |

For more information about this error, try `rustc --explain E0404`.

Rationale and extra context

When the name is not found or is not a trait, there is a false positive

Other cases

use std::str::FromStr;
fn foo<T: FromStr>() -> T
where
    <T as FromStr>::Err: some_unknown_name,
{
    "".parse().unwrap()
}

Rust Version

rustc 1.91.0-nightly (040a98af7 2025-08-20)
binary: rustc
commit-hash: 040a98af70f0a7da03f3d5356531b28a2a7a77e4
commit-date: 2025-08-20
host: aarch64-unknown-linux-gnu
release: 1.91.0-nightly
LLVM version: 21.1.0

Anything else?

No response

Metadata

Metadata

Assignees

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