You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fn main() {
let split = [~1, ~2];
match split {
[] => die!(),
[_head, ..tail] => tail
};
}
I'm not 100% sure if this should be legal, but the error message it gives is baffling:
$ rustc split2.rs
split2.rs:4:10: 4:15 error: moving out of immutable local variable prohibited due to outstanding loan
split2.rs:4 match split {
^~~~~
split2.rs:4:10: 4:15 note: loan of immutable local variable granted here
split2.rs:4 match split {
^~~~~
error: aborting due to previous error
Note that the error only occurs if you create a head binding. Replacing _head with _ causes this error to go away.
The text was updated successfully, but these errors were encountered:
Actually this is legit. The error message should be improved, but there's an issue on that already: #4715
The problem is that the head binding induces a move, but the ..tail is effectively a borrow, which means that this pattern is both moving out of vec[0] and then borrowing vec[1...]. Since the borrow checker doesn't consider indicates, this results in an error.
I'm not 100% sure if this should be legal, but the error message it gives is baffling:
Note that the error only occurs if you create a
head
binding. Replacing_head
with_
causes this error to go away.The text was updated successfully, but these errors were encountered: