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

Array of tuples containing functions trip on type inference? #74231

Open
glandium opened this issue Jul 11, 2020 · 3 comments
Open

Array of tuples containing functions trip on type inference? #74231

glandium opened this issue Jul 11, 2020 · 3 comments
Labels
C-bug Category: This is a bug.

Comments

@glandium
Copy link
Contributor

Consider the following code:

fn foo(_s: &mut [u8]) {}

fn bar(_s: &mut [u8]) {}

fn main() {
    let _works = [foo, bar];
    //let _doesnt_work = [(foo,), (bar,)];
    let _explicit_works: [(fn(&mut[u8]),);2] = [(foo,), (bar,)];
}

I expected the second assignment to be equivalent to the third.

Instead, compilation fails with:

error[E0308]: mismatched types
 --> src/main.rs:7:34
  |
7 |     let _doesnt_work = [(foo,), (bar,)];
  |                                  ^^^ expected fn item, found a different fn item
  |
  = note: expected fn item `for<'r> fn(&'r mut [u8]) {foo}`
             found fn item `for<'r> fn(&'r mut [u8]) {bar}`

Nightly has a better error message:

  = note: expected fn item `for<'r> fn(&'r mut [u8]) {foo}`
             found fn item `for<'r> fn(&'r mut [u8]) {bar}`
  = note: different `fn` items always have unique types, even if their signatures are the same
  = help: change the expected type to be function pointer `for<'r> fn(&'r mut [u8])`
  = help: if the expected type is due to type inference, cast the expected `fn` to a function pointer: `foo as for<'r> fn(&'r mut [u8])`

But with that clarification, I'd actually expect the first assignement to fail with the same error, but it doesn't.

@glandium glandium added the C-bug Category: This is a bug. label Jul 11, 2020
@jonas-schievink
Copy link
Member

I don't think coercions are supposed to work on inner fields

@eggyal
Copy link
Contributor

eggyal commented Jun 4, 2021

I don't think coercions are supposed to work on inner fields

I'm not sure that holds, because _explicit_works is a working example of the exact coercion on inner fields that's required here... is this not instead an inference issue (when trying to compute a mutual supertype of two tuple types)?

@masonk
Copy link

masonk commented Jun 5, 2021

The reference states:

a tuple is a coercion site to type (U_0, U_1, ..., U_n). Each sub-expression is a coercion site to the respective type, e.g. the zeroth sub-expression is a coercion site to type U_0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants