Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improving an error message: "cannot bind by-move into a pattern guard" #4649

Closed
catamorphism opened this issue Jan 26, 2013 · 5 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints O-windows Operating system: Windows

Comments

@catamorphism
Copy link
Contributor

Based on an IRC conversation just now, I can think of two ways to improve this error message:

  1. Because pattern guards use the "if" keyword, someone may have written one by accident. Then, if they see this error message, they're going to ask "what's a pattern guard"? The error could explain this (it's a little hard to figure out right now since the entire pattern gets underlined, not the guard).
  2. Probably more importantly, the error should suggest what to do to fix it.

The error in question is in rustc::middle::check_match.

@emberian
Copy link
Member

Triage bump

@thestinger
Copy link
Contributor

Still an issue.

@flaper87
Copy link
Contributor

visiting for triage

@dhardy
Copy link
Contributor

dhardy commented Jun 3, 2014

Re: 2 — how to solve this problem?

Matching on a reference (match &obj {...}) works until you want to move the object, which was presumably the point of making it movable in the first case.

Can match substitute variables bound by the pattern (p in this case) with a reference while evaluating the guard and release the reference again before the block? Example of problem:

for entry in try!(fs::readdir(some_path)).move_iter(){
    match &entry {
        p if /* p a borrowing reference here */ p.is_file() => {
             /* p owned, reference released here */ ...
        }, ...
    }
}

The best solution I have for now is to use a temporary control variable and match twice.

@steveklabnik
Copy link
Member

I'm pulling a massive triage effort to get us ready for 1.0. As part of this, I'm moving stuff that's wishlist-like to the RFCs repo, as that's where major new things should get discussed/prioritized.

This issue has been moved to the RFCs repo: rust-lang/rfcs#684

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints O-windows Operating system: Windows
Projects
None yet
Development

No branches or pull requests

6 participants