about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2020-01-14 14:49:30 -0800
committerEsteban Küber <esteban@kuber.com.ar>2020-01-16 09:49:13 -0800
commit509cb33dbcdb631625288f72c359a35dde6524b7 (patch)
tree82c81cd4edecc5d44b4db29839f884f04b642ec1 /src
parent5b36c187dcbb8a4b6555fe046194f2b6deb74230 (diff)
downloadrust-509cb33dbcdb631625288f72c359a35dde6524b7.tar.gz
rust-509cb33dbcdb631625288f72c359a35dde6524b7.zip
review comments
Diffstat (limited to 'src')
-rw-r--r--src/librustc/traits/error_reporting/suggestions.rs9
-rw-r--r--src/librustc_typeck/check/coercion.rs1
-rw-r--r--src/test/ui/impl-trait/equality.stderr1
-rw-r--r--src/test/ui/point-to-type-err-cause-on-impl-trait-return.stderr6
4 files changed, 11 insertions, 6 deletions
diff --git a/src/librustc/traits/error_reporting/suggestions.rs b/src/librustc/traits/error_reporting/suggestions.rs
index 0a9747b631e..c2f562b4bc7 100644
--- a/src/librustc/traits/error_reporting/suggestions.rs
+++ b/src/librustc/traits/error_reporting/suggestions.rs
@@ -624,12 +624,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
             } else {
                 // We still want to verify whether all the return types conform to each other.
                 for expr in &visitor.0 {
-                    if let Some(returned_ty) = tables.node_type_opt(expr.hir_id) {
-                        if let Some(ty) = last_ty {
-                            all_returns_have_same_type &= ty == returned_ty;
-                        }
-                        last_ty = Some(returned_ty);
-                    }
+                    let returned_ty = tables.node_type_opt(expr.hir_id);
+                    all_returns_have_same_type &= last_ty == returned_ty || last_ty.is_none();
+                    last_ty = returned_ty;
                 }
             }
 
diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs
index 66499b1753f..8aa2cb50342 100644
--- a/src/librustc_typeck/check/coercion.rs
+++ b/src/librustc_typeck/check/coercion.rs
@@ -1372,6 +1372,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
                     &snippet[5..]
                 ));
             }
+            err.help("alternatively, create a new `enum` with a variant for each returned type");
             let impl_trait_msg = "for information on `impl Trait`, see \
                 <https://doc.rust-lang.org/book/ch10-02-traits.html\
                 #returning-types-that-implement-traits>";
diff --git a/src/test/ui/impl-trait/equality.stderr b/src/test/ui/impl-trait/equality.stderr
index be8653d1689..ceb32dd4cd3 100644
--- a/src/test/ui/impl-trait/equality.stderr
+++ b/src/test/ui/impl-trait/equality.stderr
@@ -12,6 +12,7 @@ LL |     0_u32
    |
    = note: to return `impl Trait`, all returned values must be of the same type
    = help: you can instead return a trait object using `Box<dyn Foo>`
+   = help: alternatively, create a new `enum` with a variant for each returned type
    = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
    = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
 
diff --git a/src/test/ui/point-to-type-err-cause-on-impl-trait-return.stderr b/src/test/ui/point-to-type-err-cause-on-impl-trait-return.stderr
index 2c0425e718a..87daab5ca7a 100644
--- a/src/test/ui/point-to-type-err-cause-on-impl-trait-return.stderr
+++ b/src/test/ui/point-to-type-err-cause-on-impl-trait-return.stderr
@@ -12,6 +12,7 @@ LL |     1u32
    |
    = note: to return `impl Trait`, all returned values must be of the same type
    = help: you can instead return a trait object using `Box<dyn std::fmt::Display>`
+   = help: alternatively, create a new `enum` with a variant for each returned type
    = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
    = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
 
@@ -29,6 +30,7 @@ LL |         return 1u32;
    |
    = note: to return `impl Trait`, all returned values must be of the same type
    = help: you can instead return a trait object using `Box<dyn std::fmt::Display>`
+   = help: alternatively, create a new `enum` with a variant for each returned type
    = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
    = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
 
@@ -46,6 +48,7 @@ LL |         1u32
    |
    = note: to return `impl Trait`, all returned values must be of the same type
    = help: you can instead return a trait object using `Box<dyn std::fmt::Display>`
+   = help: alternatively, create a new `enum` with a variant for each returned type
    = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
    = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
 
@@ -75,6 +78,7 @@ LL |         _ => 1u32,
    |
    = note: to return `impl Trait`, all returned values must be of the same type
    = help: you can instead return a trait object using `Box<dyn std::fmt::Display>`
+   = help: alternatively, create a new `enum` with a variant for each returned type
    = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
    = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
 
@@ -94,6 +98,7 @@ LL | |     }
    |
    = note: to return `impl Trait`, all returned values must be of the same type
    = help: you can instead return a trait object using `Box<dyn std::fmt::Display>`
+   = help: alternatively, create a new `enum` with a variant for each returned type
    = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
    = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>
 
@@ -111,6 +116,7 @@ LL |             1u32
    |
    = note: to return `impl Trait`, all returned values must be of the same type
    = help: you can instead return a trait object using `Box<dyn std::fmt::Display>`
+   = help: alternatively, create a new `enum` with a variant for each returned type
    = note: for information on `impl Trait`, see <https://doc.rust-lang.org/book/ch10-02-traits.html#returning-types-that-implement-traits>
    = note: for information on trait objects, see <https://doc.rust-lang.org/book/ch17-02-trait-objects.html#using-trait-objects-that-allow-for-values-of-different-types>