Skip to content

trait bounds on concrete types erase other trait implementations #132959

Closed as not planned
@lolbinarycat

Description

@lolbinarycat

I tried this code:

fn six<T>() -> usize where u8: Into<T> {
    6_u8.into()
}

I expected to see this happen: code compiles

Instead, this happened: type mismatch error

error[E0308]: mismatched types
 --> src/lib.rs:2:5
  |
1 | fn six<T>() -> usize where u8: Into<T> {
  |        -       ----- expected `usize` because of return type
  |        |
  |        found this type parameter
2 |     6_u8.into()
  |     ^^^^^^^^^^^ expected `usize`, found type parameter `T`
  |
  = note:        expected type `usize`
          found type parameter `T`

Meta

rustc --version --verbose:

rustc 1.84.0-nightly (759e07f06 2024-10-30)
binary: rustc
commit-hash: 759e07f063fb8e6306ff1bdaeb70af56a878b415
commit-date: 2024-10-30
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions