Strange error message when `use`ing a particular crate

This code compiles and runs file:

// use rusoto_s3;
fn f() -> bool {
    let x: u16 = 1234;
    let y: u8 = 1;
    x / 100 != y.into()
}
fn main() {
    println!("{}", f())
}

But when I uncomment use rusoto_s3, I get the following error message:

error[E0283]: type annotations needed for `u16`
 --> src/main.rs:6:13
  |
4 |     let x: u16 = 1234;
  |         - consider giving `x` a type
5 |     let y: u8 = 1;
6 |     x / 100 != y.into()
  |             ^^ cannot infer type for type `u16`
  |
  = note: cannot satisfy `u16: PartialEq<_>`

What could be causing this?

Cargo.toml is as follows:

[package]
name = "test_rust"
version = "0.1.0"
authors = ["Brennan Vincent <brennan@umanwizard.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rusoto_s3 = "0.45.0"

In the standard library, u16 only implements PartialEq<u16>, so type inference knows that's the only possibility for y.into(). It looks like rusoto_s3 (or one of its dependencies) is adding some other PartialEq<T> for u16, so when you pull that into the build, y.into() becomes ambiguous.

That said, I agree the error message is not helpful, just like this issue:

2 Likes