Skip to content

Trait impl hidden by trait bound on function #51586

Closed
@stephaneyfx

Description

@stephaneyfx

I could have sworn I read a similar issue a couple of days/weeks ago but I could not find it back. #37138 seems related too.
Shoudn't this code compile? playground

struct A;
trait Foo<T> {}
impl Foo<i32> for A {}

fn f<T>(_: T) where A: Foo<T> {
    g(3i32);
    // Works:
    // g::<i32>(3);
}

fn g<T>(_: T) where A: Foo<T> {}

fn main() {
    f(3);
}
error[E0308]: mismatched types
 --> src/main.rs:6:7
  |
6 |     g(3i32);
  |       ^^^^ expected type parameter, found i32
  |
  = note: expected type `T`
             found type `i32`

error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inferenceArea: Type inferenceA-trait-systemArea: Trait systemA-type-systemArea: Type systemC-bugCategory: This is a bug.WG-traitsWorking group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions