Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trait impl hidden by trait bound on function #51586

Closed
stephaneyfx opened this issue Jun 16, 2018 · 5 comments
Closed

Trait impl hidden by trait bound on function #51586

stephaneyfx opened this issue Jun 16, 2018 · 5 comments
Labels
A-inference Area: Type inference A-traits Area: Trait system A-typesystem Area: The type system C-bug Category: This is a bug. WG-traits Working group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804

Comments

@stephaneyfx
Copy link
Contributor

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
@stokhos stokhos added the A-specialization Area: Trait impl specialization label Jun 16, 2018
@stephaneyfx
Copy link
Contributor Author

@stokhos, I looked at issues labeled with A-specialization and they seem to relate to the specialization feature in Rust. The example code in this issue does not make use of this feature, only of plain old trait impls. Is this label appropriate?

@Centril Centril added A-typesystem Area: The type system A-traits Area: Trait system A-inference Area: Type inference C-bug Category: This is a bug. WG-traits Working group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804 and removed A-specialization Area: Trait impl specialization labels Jun 21, 2018
@Centril
Copy link
Contributor

Centril commented Jun 21, 2018

Seems like a bug?

Just to illustrate that this is not specific to i32 and having the same type variable names (tested on nightly, etc.):

#![crate_type = "lib"]

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

fn f<T0>(_: T0) where A: Foo<T0> {
    g::<_>(B); // expected type `T0`
}

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

But this works fine:

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

fn main() { g::<_>(B); }

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

@stephaneyfx
Copy link
Contributor Author

@Centril: As requested, I tried with older rust versions and the original example is rejected even by rust 1.0.0: https://godbolt.org/g/ECbAi4

@Centril
Copy link
Contributor

Centril commented Jun 21, 2018

@stephaneyfx Great, thank you ❤️; then at least there's no regression :)

@stephaneyfx
Copy link
Contributor Author

This looks very much like #24066 and the original example not compiling seems to be intentional: see comments starting at #33108 (comment), especially from @eddyb and @aturon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inference Area: Type inference A-traits Area: Trait system A-typesystem Area: The type system C-bug Category: This is a bug. WG-traits Working group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804
Projects
None yet
Development

No branches or pull requests

3 participants