From 5363f350887b1e5b5dd21a86f88c8af9d7fea6da Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:18:25 +0200 Subject: Merging upstream version 1.67.1+dfsg1. Signed-off-by: Daniel Baumann --- src/test/ui/inference/cannot-infer-async.rs | 3 +- src/test/ui/inference/cannot-infer-closure.rs | 3 +- src/test/ui/inference/deref-suggestion.stderr | 12 +++---- src/test/ui/inference/issue-103587.rs | 12 +++++++ src/test/ui/inference/issue-103587.stderr | 40 +++++++++++++++++++++++ src/test/ui/inference/issue-104649.rs | 32 ++++++++++++++++++ src/test/ui/inference/issue-104649.stderr | 14 ++++++++ src/test/ui/inference/issue-71732.rs | 3 +- src/test/ui/inference/issue-72616.rs | 5 ++- src/test/ui/inference/issue-72616.stderr | 20 ++++++++++-- src/test/ui/inference/question-mark-type-infer.rs | 3 +- 11 files changed, 134 insertions(+), 13 deletions(-) create mode 100644 src/test/ui/inference/issue-103587.rs create mode 100644 src/test/ui/inference/issue-103587.stderr create mode 100644 src/test/ui/inference/issue-104649.rs create mode 100644 src/test/ui/inference/issue-104649.stderr (limited to 'src/test/ui/inference') diff --git a/src/test/ui/inference/cannot-infer-async.rs b/src/test/ui/inference/cannot-infer-async.rs index e7fabd0ff..b5152d04f 100644 --- a/src/test/ui/inference/cannot-infer-async.rs +++ b/src/test/ui/inference/cannot-infer-async.rs @@ -10,6 +10,7 @@ fn main() { let fut = async { make_unit()?; - Ok(()) //~ ERROR type annotations needed + Ok(()) + //~^ ERROR type annotations needed }; } diff --git a/src/test/ui/inference/cannot-infer-closure.rs b/src/test/ui/inference/cannot-infer-closure.rs index 1c350b18f..bd5d10b41 100644 --- a/src/test/ui/inference/cannot-infer-closure.rs +++ b/src/test/ui/inference/cannot-infer-closure.rs @@ -1,6 +1,7 @@ fn main() { let x = |a: (), b: ()| { Err(a)?; - Ok(b) //~ ERROR type annotations needed + Ok(b) + //~^ ERROR type annotations needed }; } diff --git a/src/test/ui/inference/deref-suggestion.stderr b/src/test/ui/inference/deref-suggestion.stderr index d729f2d68..034005697 100644 --- a/src/test/ui/inference/deref-suggestion.stderr +++ b/src/test/ui/inference/deref-suggestion.stderr @@ -157,11 +157,11 @@ error[E0308]: `if` and `else` have incompatible types --> $DIR/deref-suggestion.rs:69:12 | LL | let val = if true { - | _______________- -LL | | *a - | | -- expected because of this -LL | | } else if true { - | |____________^ + | ________________- +LL | | *a + | | -- expected because of this +LL | | } else if true { + | | ____________^ LL | || LL | || b LL | || } else { @@ -169,7 +169,7 @@ LL | || &0 LL | || }; | || ^ | ||_____| - | |______`if` and `else` have incompatible types + | |_____`if` and `else` have incompatible types | expected `i32`, found `&{integer}` error: aborting due to 13 previous errors diff --git a/src/test/ui/inference/issue-103587.rs b/src/test/ui/inference/issue-103587.rs new file mode 100644 index 000000000..11536f9f4 --- /dev/null +++ b/src/test/ui/inference/issue-103587.rs @@ -0,0 +1,12 @@ +fn main() { + let x = Some(123); + + if let Some(_) == x {} + //~^ ERROR expected `=`, found `==` + + if Some(_) = x {} + //~^ ERROR mismatched types + + if None = x { } + //~^ ERROR mismatched types +} diff --git a/src/test/ui/inference/issue-103587.stderr b/src/test/ui/inference/issue-103587.stderr new file mode 100644 index 000000000..b373fbfbb --- /dev/null +++ b/src/test/ui/inference/issue-103587.stderr @@ -0,0 +1,40 @@ +error: expected `=`, found `==` + --> $DIR/issue-103587.rs:4:20 + | +LL | if let Some(_) == x {} + | ^^ + | +help: consider using `=` here + | +LL | if let Some(_) = x {} + | ~ + +error[E0308]: mismatched types + --> $DIR/issue-103587.rs:7:8 + | +LL | if Some(_) = x {} + | ^^^^^^^^^^^ expected `bool`, found `()` + | +help: consider adding `let` + | +LL | if let Some(_) = x {} + | +++ + +error[E0308]: mismatched types + --> $DIR/issue-103587.rs:10:8 + | +LL | if None = x { } + | ^^^^^^^^ expected `bool`, found `()` + | +help: you might have meant to use pattern matching + | +LL | if let None = x { } + | +++ +help: you might have meant to compare for equality + | +LL | if None == x { } + | + + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/inference/issue-104649.rs b/src/test/ui/inference/issue-104649.rs new file mode 100644 index 000000000..4637b884d --- /dev/null +++ b/src/test/ui/inference/issue-104649.rs @@ -0,0 +1,32 @@ +type Result = ::std::result::Result; +struct Error; + +trait ForEach { + type Input; + fn for_each(self, f: F) + where + F: FnOnce(Self::Input) -> U; +} + +impl ForEach for A { + type Input = T; + fn for_each(self, f: F) + where + F: FnOnce(Self::Input) -> U, + { + todo!() + } +} + +struct A(T); + +fn main() { + let a = A(Result::Ok(Result::Ok(()))); //~ ERROR type annotations needed + a.for_each(|a: Result<_>| { + let f = || match a { + Ok(Ok(a)) => {} + Ok(Err(a)) => {} + Err(a) => {} + }; + }); +} diff --git a/src/test/ui/inference/issue-104649.stderr b/src/test/ui/inference/issue-104649.stderr new file mode 100644 index 000000000..4962b21f9 --- /dev/null +++ b/src/test/ui/inference/issue-104649.stderr @@ -0,0 +1,14 @@ +error[E0282]: type annotations needed for `A, Error>>` + --> $DIR/issue-104649.rs:24:9 + | +LL | let a = A(Result::Ok(Result::Ok(()))); + | ^ + | +help: consider giving `a` an explicit type, where the type for type parameter `E` is specified + | +LL | let a: A, Error>> = A(Result::Ok(Result::Ok(()))); + | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/src/test/ui/inference/issue-71732.rs b/src/test/ui/inference/issue-71732.rs index 30063a095..8a9d2b235 100644 --- a/src/test/ui/inference/issue-71732.rs +++ b/src/test/ui/inference/issue-71732.rs @@ -15,7 +15,8 @@ use std::collections::hash_map::HashMap; fn foo(parameters: &HashMap) -> bool { parameters - .get(&"key".into()) //~ ERROR: type annotations needed + .get(&"key".into()) + //~^ ERROR type annotations needed .and_then(|found: &String| Some(false)) .unwrap_or(false) } diff --git a/src/test/ui/inference/issue-72616.rs b/src/test/ui/inference/issue-72616.rs index 5e5a3babf..69ade1a75 100644 --- a/src/test/ui/inference/issue-72616.rs +++ b/src/test/ui/inference/issue-72616.rs @@ -1,3 +1,5 @@ +// ignore-wasm32 FIXME: ignoring wasm as it suggests slightly different impls + // Regression test for #72616, it used to emit incorrect diagnostics, like: // error[E0283]: type annotations needed for `String` // --> src/main.rs:8:30 @@ -18,7 +20,8 @@ pub fn main() { } { if String::from("a") == "a".try_into().unwrap() {} - //~^ ERROR: type annotations needed + //~^ ERROR type annotations needed + //~| ERROR type annotations needed } { let _: String = match "_".try_into() { diff --git a/src/test/ui/inference/issue-72616.stderr b/src/test/ui/inference/issue-72616.stderr index a71ce9a8e..6ee0626ca 100644 --- a/src/test/ui/inference/issue-72616.stderr +++ b/src/test/ui/inference/issue-72616.stderr @@ -1,5 +1,5 @@ error[E0283]: type annotations needed - --> $DIR/issue-72616.rs:20:37 + --> $DIR/issue-72616.rs:22:37 | LL | if String::from("a") == "a".try_into().unwrap() {} | -- ^^^^^^^^ @@ -16,6 +16,22 @@ help: try using a fully qualified path to specify the expected types LL | if String::from("a") == <&str as TryInto>::try_into("a").unwrap() {} | +++++++++++++++++++++++++++++++ ~ -error: aborting due to previous error +error[E0283]: type annotations needed + --> $DIR/issue-72616.rs:22:37 + | +LL | if String::from("a") == "a".try_into().unwrap() {} + | ^^^^^^^^ + | + = note: multiple `impl`s satisfying `_: TryFrom<&str>` found in the following crates: `core`, `std`: + - impl<> TryFrom<&str> for std::sys_common::net::LookupHost; + - impl TryFrom for T + where U: Into; + = note: required for `&str` to implement `TryInto<_>` +help: try using a fully qualified path to specify the expected types + | +LL | if String::from("a") == <&str as TryInto>::try_into("a").unwrap() {} + | +++++++++++++++++++++++++++++++ ~ + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0283`. diff --git a/src/test/ui/inference/question-mark-type-infer.rs b/src/test/ui/inference/question-mark-type-infer.rs index 64333a293..10560f85e 100644 --- a/src/test/ui/inference/question-mark-type-infer.rs +++ b/src/test/ui/inference/question-mark-type-infer.rs @@ -7,7 +7,8 @@ fn f(x: &i32) -> Result { fn g() -> Result, ()> { let l = [1, 2, 3, 4]; - l.iter().map(f).collect()? //~ ERROR type annotations needed + l.iter().map(f).collect()? + //~^ ERROR type annotations needed } fn main() { -- cgit v1.2.3