Skip to content

Strange 'expected' and 'found' #67381

Closed
Closed
@hirrolot

Description

@hirrolot

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions