Skip to content
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

Possible E0301 false positive #59803

Closed
Nadrieril opened this issue Apr 8, 2019 · 1 comment
Closed

Possible E0301 false positive #59803

Nadrieril opened this issue Apr 8, 2019 · 1 comment
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Nadrieril
Copy link
Member

This code fails with error[E0301]: cannot mutably borrow in a pattern guard:

match Some(1) {
    x if x.iter().all(|x| *x == 1) => {}
    _ => {}
}
Error
error[E0301]: cannot mutably borrow in a pattern guard
   --> blah/src/lib.rs:230:14
    |
230 |         x if x.iter().all(|x| *x == 1) => {}
    |              ^^^^^^^^ borrowed mutably in pattern guard
    |
    = help: add #![feature(bind_by_move_pattern_guards)] to the crate attributes to enable

However the following works:

let is_all_1 = |x: &Option<usize>| x.iter().all(|x| *x == 1);
match Some(1) {
    x if is_all_1(&x) => {}
    _ => {}
}

Which is rather surprising and looks like a false positive to me. Could the compiler allow a match if the lifetime of the mutable borrow is limited to the match guard ?

Nadrieril added a commit to Nadrieril/dhall-rust that referenced this issue Apr 8, 2019
@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 8, 2019
@Nadrieril
Copy link
Member Author

Nadrieril commented Oct 22, 2020

This appears to be fixed (playground link)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants