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

Strange 'expected' and 'found' #67381

Closed
hirrolot opened this issue Dec 17, 2019 · 3 comments
Closed

Strange 'expected' and 'found' #67381

hirrolot opened this issue Dec 17, 2019 · 3 comments

Comments

@hirrolot
Copy link
Contributor

hirrolot commented Dec 17, 2019

Consider these two examples:

  1. https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=1e43b7cb813eeac58982933266b7bdf3
    Error:
error[E0271]: type mismatch resolving `<std::slice::Iter<'_, {integer}> as std::iter::Iterator>::Item == i32`
 --> src/main.rs:4:5
  |
1 | fn consume<I: Iterator<Item = i32>>(_: I) {}
  |    -------             ---------- required by this bound in `consume`
...
4 |     consume([1, 2, 3].into_iter());
  |     ^^^^^^^ expected reference, found i32
  |
  = note: expected type `&{integer}`
             found type `i32`
  1. https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=528121c8b1f50ed2c761e9932f7d792a
    Error:
error[E0308]: mismatched types
 --> src/main.rs:4:13
  |
4 |     consume(&123);
  |             ^^^^
  |             |
  |             expected i32, found &{integer}
  |             help: consider removing the borrow: `123`
  |
  = note: expected type `i32`
             found type `&{integer}`

expected in the first example's error message is related to the call's context, but in the second one, it is related to the function's signature. Is it a bug?

rustc

1.39.0 stable

@memoryruins
Copy link
Contributor

Thanks for reporting. This was fixed in #65977

Nightly's current output for 1

error[E0271]: type mismatch resolving `<std::slice::Iter<'_, {integer}> as std::iter::Iterator>::Item == i32`
 --> src/main.rs:4:5
  |
1 | fn consume<I: Iterator<Item = i32>>(_: I) {}
  |    -------             ---------- required by this bound in `consume`
...
4 |     consume([1, 2, 3].into_iter());
  |     ^^^^^^^ expected `i32`, found reference
  |
  = note:   expected type `i32`
          found reference `&{integer}`

1.41.0-nightly 2019-12-16 99b89533d4cdf7682ea4

@jonas-schievink
Copy link
Contributor

Closing as fixed.

@hirrolot
Copy link
Contributor Author

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants