about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZack M. Davis <code@zackmdavis.net>2018-11-23 12:57:03 -0800
committerZack M. Davis <code@zackmdavis.net>2018-12-22 19:04:29 -0800
commit64ad3e2c423f701b856a6780380a0dbb03f90c22 (patch)
treeafeae1ade1aa0a5edfc1b7b731117e73cd591f2a
parent3986c964481a048100565c8d30b1937ec2eb516d (diff)
downloadrust-64ad3e2c423f701b856a6780380a0dbb03f90c22.tar.gz
rust-64ad3e2c423f701b856a6780380a0dbb03f90c22.zip
adjust enum type instead of variant suggestions for prelude enums
The present author regrets not thinking of a more eloquent way to do
this.
-rw-r--r--src/librustc_resolve/lib.rs12
-rw-r--r--src/librustc_typeck/check/demand.rs1
-rw-r--r--src/test/ui/did_you_mean/issue-56028-there-is-an-enum-variant.rs2
-rw-r--r--src/test/ui/issues/issue-35675.stderr22
4 files changed, 22 insertions, 15 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index 8f329283b1a..e543677ef06 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -3237,7 +3237,17 @@ impl<'a> Resolver<'a> {
                     err.span_suggestions_with_applicability(
                         span,
                         &msg,
-                        enum_candidates.into_iter().map(|(_variant, enum_ty)| enum_ty),
+                        enum_candidates.into_iter()
+                            .map(|(_variant_path, enum_ty_path)| enum_ty_path)
+                            // variants reƫxported in prelude doesn't mean `prelude::v1` is the
+                            // type name! FIXME: is there a more principled way to do this that
+                            // would work for other reƫxports?
+                            .filter(|enum_ty_path| enum_ty_path != "std::prelude::v1")
+                            // also say `Option` rather than `std::prelude::v1::Option`
+                            .map(|enum_ty_path| {
+                                // FIXME #56861: DRYer prelude filtering
+                                enum_ty_path.trim_start_matches("std::prelude::v1::").to_owned()
+                            }),
                         Applicability::MachineApplicable,
                     );
                 }
diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs
index db4b68611c5..996b57f558c 100644
--- a/src/librustc_typeck/check/demand.rs
+++ b/src/librustc_typeck/check/demand.rs
@@ -123,6 +123,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
                         let sole_field_ty = sole_field.ty(self.tcx, substs);
                         if self.can_coerce(expr_ty, sole_field_ty) {
                             let variant_path = self.tcx.item_path_str(variant.did);
+                            // FIXME #56861: DRYer prelude filtering
                             Some(variant_path.trim_start_matches("std::prelude::v1::").to_string())
                         } else {
                             None
diff --git a/src/test/ui/did_you_mean/issue-56028-there-is-an-enum-variant.rs b/src/test/ui/did_you_mean/issue-56028-there-is-an-enum-variant.rs
index ec41c411416..264cfa44994 100644
--- a/src/test/ui/did_you_mean/issue-56028-there-is-an-enum-variant.rs
+++ b/src/test/ui/did_you_mean/issue-56028-there-is-an-enum-variant.rs
@@ -7,6 +7,8 @@ enum Solidify { Set }
 enum UnorderedCollection { Set }
 
 fn setup() -> Set { Set }
+//~^ ERROR cannot find type `Set` in this scope
+//~| ERROR cannot find value `Set` in this scope
 
 fn main() {
     setup();
diff --git a/src/test/ui/issues/issue-35675.stderr b/src/test/ui/issues/issue-35675.stderr
index 2f07ee7124d..652e1695a85 100644
--- a/src/test/ui/issues/issue-35675.stderr
+++ b/src/test/ui/issues/issue-35675.stderr
@@ -41,13 +41,10 @@ error[E0573]: expected type, found variant `Ok`
   --> $DIR/issue-35675.rs:29:13
    |
 LL | fn foo() -> Ok {
-   |             ^^ not a type
-help: try using the variant's enum
-   |
-LL | fn foo() -> std::prelude::v1 {
-   |             ^^^^^^^^^^^^^^^^
-LL | fn foo() -> std::result::Result {
-   |             ^^^^^^^^^^^^^^^^^^^
+   |             ^^
+   |             |
+   |             not a type
+   |             help: try using the variant's enum: `std::result::Result`
 
 error[E0412]: cannot find type `Variant3` in this scope
   --> $DIR/issue-35675.rs:34:13
@@ -63,13 +60,10 @@ error[E0573]: expected type, found variant `Some`
   --> $DIR/issue-35675.rs:38:13
    |
 LL | fn qux() -> Some {
-   |             ^^^^ not a type
-help: try using the variant's enum
-   |
-LL | fn qux() -> std::prelude::v1::Option {
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^
-LL | fn qux() -> std::prelude::v1 {
-   |             ^^^^^^^^^^^^^^^^
+   |             ^^^^
+   |             |
+   |             not a type
+   |             help: try using the variant's enum: `Option`
 
 error: aborting due to 7 previous errors