Skip to content

Commit

Permalink
adjust enum type instead of variant suggestions for prelude enums
Browse files Browse the repository at this point in the history
The present author regrets not thinking of a more eloquent way to do
this.
  • Loading branch information
zackmdavis committed Dec 23, 2018
1 parent 3986c96 commit 64ad3e2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
12 changes: 11 additions & 1 deletion src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_typeck/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
22 changes: 8 additions & 14 deletions src/test/ui/issues/issue-35675.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 64ad3e2

Please sign in to comment.