about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorWilliam Bain <bain.william.a@gmail.com>2020-12-29 00:10:13 -0500
committerWilliam Bain <bain.william.a@gmail.com>2021-01-10 19:47:57 -0500
commit0496fdee4fa65b38f540b5a7aa7ea86eb5ca890e (patch)
treee2901044d22af6f689d998a9d362429bb0e9d7b3 /src/test
parentc97f11af7bc4a6d3578f6a953be04ab2449a5728 (diff)
downloadrust-0496fdee4fa65b38f540b5a7aa7ea86eb5ca890e.tar.gz
rust-0496fdee4fa65b38f540b5a7aa7ea86eb5ca890e.zip
Note inference failures using `?` conversion
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/inference/cannot-infer-async-enabled-impl-trait-bindings.stderr4
-rw-r--r--src/test/ui/inference/cannot-infer-async.stderr4
-rw-r--r--src/test/ui/inference/cannot-infer-closure-circular.rs14
-rw-r--r--src/test/ui/inference/cannot-infer-closure-circular.stderr9
-rw-r--r--src/test/ui/inference/cannot-infer-closure.stderr3
-rw-r--r--src/test/ui/inference/cannot-infer-partial-try-return.rs22
-rw-r--r--src/test/ui/inference/cannot-infer-partial-try-return.stderr15
7 files changed, 68 insertions, 3 deletions
diff --git a/src/test/ui/inference/cannot-infer-async-enabled-impl-trait-bindings.stderr b/src/test/ui/inference/cannot-infer-async-enabled-impl-trait-bindings.stderr
index 2f630c2c9ad..de15d472d05 100644
--- a/src/test/ui/inference/cannot-infer-async-enabled-impl-trait-bindings.stderr
+++ b/src/test/ui/inference/cannot-infer-async-enabled-impl-trait-bindings.stderr
@@ -13,7 +13,9 @@ error[E0282]: type annotations needed for `impl Future`
 LL |     let fut = async {
    |         --- consider giving `fut` the explicit type `impl Future`, with the type parameters specified
 LL |         make_unit()?;
-   |                    ^ cannot infer type
+   |                    ^ cannot infer type of `?` error
+   |
+   = note: the `?` operation implicitly converts the error value into a type implementing `From<std::io::Error>`
 
 error: aborting due to previous error; 1 warning emitted
 
diff --git a/src/test/ui/inference/cannot-infer-async.stderr b/src/test/ui/inference/cannot-infer-async.stderr
index 92a9045f6db..d5cccc7a948 100644
--- a/src/test/ui/inference/cannot-infer-async.stderr
+++ b/src/test/ui/inference/cannot-infer-async.stderr
@@ -4,7 +4,9 @@ error[E0282]: type annotations needed
 LL |     let fut = async {
    |         --- consider giving `fut` a type
 LL |         make_unit()?;
-   |                    ^ cannot infer type
+   |                    ^ cannot infer type of `?` error
+   |
+   = note: the `?` operation implicitly converts the error value into a type implementing `From<std::io::Error>`
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/inference/cannot-infer-closure-circular.rs b/src/test/ui/inference/cannot-infer-closure-circular.rs
new file mode 100644
index 00000000000..a3b957179b1
--- /dev/null
+++ b/src/test/ui/inference/cannot-infer-closure-circular.rs
@@ -0,0 +1,14 @@
+fn main() {
+    // Below we call the closure with its own return as the argument, unifying
+    // its inferred input and return types. We want to make sure that the generated
+    // error handles this gracefully, and in particular doesn't generate an extra
+    // note about the `?` operator in the closure body, which isn't relevant to
+    // the inference.
+    let x = |r| {
+        //~^ ERROR type annotations needed
+        let v = r?;
+        Ok(v)
+    };
+
+    let _ = x(x(Ok(())));
+}
diff --git a/src/test/ui/inference/cannot-infer-closure-circular.stderr b/src/test/ui/inference/cannot-infer-closure-circular.stderr
new file mode 100644
index 00000000000..5efb400a4c7
--- /dev/null
+++ b/src/test/ui/inference/cannot-infer-closure-circular.stderr
@@ -0,0 +1,9 @@
+error[E0282]: type annotations needed for `std::result::Result<(), E>`
+  --> $DIR/cannot-infer-closure-circular.rs:7:14
+   |
+LL |     let x = |r| {
+   |              ^ consider giving this closure parameter the explicit type `std::result::Result<(), E>`, with the type parameters specified
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0282`.
diff --git a/src/test/ui/inference/cannot-infer-closure.stderr b/src/test/ui/inference/cannot-infer-closure.stderr
index d5366e422db..c083f2b686e 100644
--- a/src/test/ui/inference/cannot-infer-closure.stderr
+++ b/src/test/ui/inference/cannot-infer-closure.stderr
@@ -2,8 +2,9 @@ error[E0282]: type annotations needed for the closure `fn((), ()) -> std::result
   --> $DIR/cannot-infer-closure.rs:3:15
    |
 LL |         Err(a)?;
-   |               ^ cannot infer type
+   |               ^ cannot infer type of `?` error
    |
+   = note: the `?` operation implicitly converts the error value into a type implementing `From<()>`
 help: give this closure an explicit return type without `_` placeholders
    |
 LL |     let x = |a: (), b: ()| -> std::result::Result<(), _> {
diff --git a/src/test/ui/inference/cannot-infer-partial-try-return.rs b/src/test/ui/inference/cannot-infer-partial-try-return.rs
new file mode 100644
index 00000000000..e1058e96cef
--- /dev/null
+++ b/src/test/ui/inference/cannot-infer-partial-try-return.rs
@@ -0,0 +1,22 @@
+struct QualifiedError<E>(E);
+
+impl<E, T> From<E> for QualifiedError<T>
+where
+    E: std::error::Error,
+    T: From<E>,
+{
+    fn from(e: E) -> QualifiedError<T> {
+        QualifiedError(e.into())
+    }
+}
+
+fn infallible() -> Result<(), std::convert::Infallible> {
+    Ok(())
+}
+
+fn main() {
+    let x = || -> Result<_, QualifiedError<_>> {
+        infallible()?; //~ERROR type annotations needed
+        Ok(())
+    };
+}
diff --git a/src/test/ui/inference/cannot-infer-partial-try-return.stderr b/src/test/ui/inference/cannot-infer-partial-try-return.stderr
new file mode 100644
index 00000000000..d4223bfc155
--- /dev/null
+++ b/src/test/ui/inference/cannot-infer-partial-try-return.stderr
@@ -0,0 +1,15 @@
+error[E0282]: type annotations needed for the closure `fn() -> std::result::Result<(), QualifiedError<_>>`
+  --> $DIR/cannot-infer-partial-try-return.rs:19:9
+   |
+LL |         infallible()?;
+   |         ^^^^^^^^^^^^^ cannot infer type of `?` error
+   |
+   = note: the `?` operation implicitly converts the error value into `QualifiedError<_>` using its implementation of `From<Infallible>`
+help: give this closure an explicit return type without `_` placeholders
+   |
+LL |     let x = || -> std::result::Result<(), QualifiedError<_>> {
+   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0282`.