summaryrefslogtreecommitdiffstats
path: root/src/test/ui/inference
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:25 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:25 +0000
commit5363f350887b1e5b5dd21a86f88c8af9d7fea6da (patch)
tree35ca005eb6e0e9a1ba3bb5dbc033209ad445dc17 /src/test/ui/inference
parentAdding debian version 1.66.0+dfsg1-1. (diff)
downloadrustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.tar.xz
rustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.zip
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/inference')
-rw-r--r--src/test/ui/inference/cannot-infer-async.rs3
-rw-r--r--src/test/ui/inference/cannot-infer-closure.rs3
-rw-r--r--src/test/ui/inference/deref-suggestion.stderr12
-rw-r--r--src/test/ui/inference/issue-103587.rs12
-rw-r--r--src/test/ui/inference/issue-103587.stderr40
-rw-r--r--src/test/ui/inference/issue-104649.rs32
-rw-r--r--src/test/ui/inference/issue-104649.stderr14
-rw-r--r--src/test/ui/inference/issue-71732.rs3
-rw-r--r--src/test/ui/inference/issue-72616.rs5
-rw-r--r--src/test/ui/inference/issue-72616.stderr20
-rw-r--r--src/test/ui/inference/question-mark-type-infer.rs3
11 files changed, 134 insertions, 13 deletions
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<T, E = Error> = ::std::result::Result<T, E>;
+struct Error;
+
+trait ForEach {
+ type Input;
+ fn for_each<F, U>(self, f: F)
+ where
+ F: FnOnce(Self::Input) -> U;
+}
+
+impl<T> ForEach for A<T> {
+ type Input = T;
+ fn for_each<F, U>(self, f: F)
+ where
+ F: FnOnce(Self::Input) -> U,
+ {
+ todo!()
+ }
+}
+
+struct A<T>(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<std::result::Result<std::result::Result<(), E>, 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<std::result::Result<std::result::Result<(), E>, 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<String, String>) -> 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<T>>::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<T, U> TryFrom<U> for T
+ where U: Into<T>;
+ = 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<T>>::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<i32, ()> {
fn g() -> Result<Vec<i32>, ()> {
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() {