about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-08-21 15:35:38 -0700
committerEsteban Küber <esteban@kuber.com.ar>2019-08-21 16:49:26 -0700
commita710c610b2ea1550014e9f6bd20e5e4aed8a716c (patch)
tree2fd7e838d08a97536d43a792d2add4592d39effe /src
parentba8e09415b00fdfcda8feeb1cf233f2f065ef6c6 (diff)
downloadrust-a710c610b2ea1550014e9f6bd20e5e4aed8a716c.tar.gz
rust-a710c610b2ea1550014e9f6bd20e5e4aed8a716c.zip
review comments: reword and add test
Diffstat (limited to 'src')
-rw-r--r--src/librustc/ty/error.rs4
-rw-r--r--src/test/ui/suggestions/opaque-type-error.rs24
-rw-r--r--src/test/ui/suggestions/opaque-type-error.stderr20
3 files changed, 46 insertions, 2 deletions
diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs
index c1593799286..c70006b68d6 100644
--- a/src/librustc/ty/error.rs
+++ b/src/librustc/ty/error.rs
@@ -269,8 +269,8 @@ impl<'tcx> TyCtxt<'tcx> {
                     let f_str = values.found.to_string();
                     if &e_str == &f_str && &e_str == "impl std::future::Future" {
                         // FIXME: use non-string based check.
-                        db.help("if both futures resolve to the same type, consider `await`ing \
-                                 on both of them");
+                        db.help("if both `Future`s have the same `Output` type, consider \
+                                 `.await`ing on both of them");
                     }
                 }
                 if let (ty::Infer(ty::IntVar(_)), ty::Float(_)) =
diff --git a/src/test/ui/suggestions/opaque-type-error.rs b/src/test/ui/suggestions/opaque-type-error.rs
new file mode 100644
index 00000000000..979bb60d48c
--- /dev/null
+++ b/src/test/ui/suggestions/opaque-type-error.rs
@@ -0,0 +1,24 @@
+// edition:2018
+use core::future::Future;
+
+async fn base_thing() -> Result<(), ()> {
+    Ok(())
+}
+
+fn thing_one() -> impl Future<Output = Result<(), ()>> {
+    base_thing()
+}
+
+fn thing_two() -> impl Future<Output = Result<(), ()>> {
+    base_thing()
+}
+
+async fn thing() -> Result<(), ()> {
+    if true {
+        thing_one()
+    } else {
+        thing_two() //~ ERROR if and else have incompatible types
+    }.await
+}
+
+fn main() {}
diff --git a/src/test/ui/suggestions/opaque-type-error.stderr b/src/test/ui/suggestions/opaque-type-error.stderr
new file mode 100644
index 00000000000..3c9ea05aece
--- /dev/null
+++ b/src/test/ui/suggestions/opaque-type-error.stderr
@@ -0,0 +1,20 @@
+error[E0308]: if and else have incompatible types
+  --> $DIR/opaque-type-error.rs:20:9
+   |
+LL | /     if true {
+LL | |         thing_one()
+   | |         ----------- expected because of this
+LL | |     } else {
+LL | |         thing_two()
+   | |         ^^^^^^^^^^^ expected opaque type, found a different opaque type
+LL | |     }.await
+   | |_____- if and else have incompatible types
+   |
+   = note: expected type `impl std::future::Future` (opaque type)
+              found type `impl std::future::Future` (opaque type)
+   = note: distinct uses of `impl Trait` result in different opaque types
+   = help: if both `Future`s have the same `Output` type, consider `.await`ing on both of them
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.