-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot match on reference in slice pattern #55175
Comments
For anyone looking around for help on this case in particular, the appropriate code would be either
or
which is now suggested:
|
If this is just a fix for the error message, did you mean to close #55174? |
I have a PR out to fix #55174 (do not suggest I misunderstood anything, feel free to reopen. |
I guess my intuition is that since the match ergonomics feature makes the element struct Foo(i32);
fn main() {
let foo = Foo(5);
match &foo {
// To dereference and copy bar, match on the reference
Foo(&bar) => {
let _: i32 = bar;
},
}
} Gives you:
So I think you are understanding the problem and your fix for the error message is probably sufficient. As long as we're being consistent I'm okay with this. |
Here's a minimal reproduction: (Rust Playground)
Since the type of
&x[..]
is&[i32]
, I expect its contents to be&i32
(or else we would move unexpectedly). However, trying to match on that reference to force a copy here does not work because the error message indicates that the type ofv
inside the pattern is in facti32
, not&i32
.This is further complicated by the fact that if you remove the
&
fromv
(since it's type isi32
right??), it still doesn't work because the type ofv
is actually&i32
like I originally expected.Both the type of
v
in the pattern and the type ofv
on that is returned intovalue
should probably be the same.Could this be a weird interaction with the match ergonomics features added recently?
The text was updated successfully, but these errors were encountered: