Skip to content

Conversation

@JoshMcguigan
Copy link
Contributor

fixes #3974

@JoshMcguigan
Copy link
Contributor Author

I think the solution in this PR should work, but cx.infer.variant_resolution_for_expr(cx.match_expr) returns None in the following case:

enum Never {}

fn test_fn(never: Never) {
	match never {}
}

I think this is an inference issue related to the match expression coming from a function argument. Any thoughts on this @flodiebold? Places I should start looking?

Note that in the IDE I do see Never as the type when I hover over the match expression, so perhaps this is some issue which only affects variant_resolution_for_expr?

@JoshMcguigan JoshMcguigan force-pushed the missing-match-arm-enum-never-false-positive branch from d33be45 to 19c3c0e Compare April 15, 2020 13:19
@JoshMcguigan JoshMcguigan marked this pull request as ready for review April 15, 2020 13:20
@JoshMcguigan JoshMcguigan marked this pull request as draft April 15, 2020 13:23
@JoshMcguigan
Copy link
Contributor Author

JoshMcguigan commented Apr 15, 2020

Sorry for the noise here. Converting back to draft because I have not yet covered the reference case (i.e. &Never).

This seems a bit tricky, since TypeCtor::Ref seems to not contain any information about the type of the underlying thing being referenced.

@flodiebold
Copy link
Member

This seems a bit tricky, since TypeCtor::Ref seems to not contain any information about the type of the underlying thing being referenced.

The referenced type is a type parameter (&'x T is basically no different from Ref<'x, T>). There's actually ty.as_reference() for this purpose already.

@JoshMcguigan JoshMcguigan force-pushed the missing-match-arm-enum-never-false-positive branch from 19c3c0e to 1e65bc6 Compare April 15, 2020 20:09
@JoshMcguigan
Copy link
Contributor Author

JoshMcguigan commented Apr 15, 2020

I've added a deref method on Ty, which recursively derences types until it gets a non-reference. This makes the test pass which was matching on a reference to the Never enum.

Let me know if there is a more appropriate name for this method. Or if it should go somewhere else. I thought about putting it in an impl block on ApplicationTy, but in that case I wasn't sure what the return type should be, since parameters.as_single() would still return a Ty and I wasn't sure if it was safe to assume that Ty would be an ApplicationTy in all cases.

@JoshMcguigan JoshMcguigan marked this pull request as ready for review April 15, 2020 20:18
@JoshMcguigan JoshMcguigan force-pushed the missing-match-arm-enum-never-false-positive branch from 1e65bc6 to 360bdf6 Compare April 16, 2020 12:37
@flodiebold
Copy link
Member

bors r+

@bors
Copy link
Contributor

bors bot commented Apr 16, 2020

Build succeeded:

@bors bors bot merged commit 0390d62 into rust-lang:master Apr 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrectly shows an error for matching an enum without variants

2 participants