Skip to content

if clauses following an if let are compiled to match guards #41272

Closed
@nox

Description

@nox

https://is.gd/2ZnMND

is this code:

struct Foo;

impl Foo {
    fn bar(&mut self) -> bool { true }
}

fn error(foo: &mut Foo) {
    if let Some(_) = Some(true) {
    } else if foo.bar() {}
}

fn ok(foo: &mut Foo) {
    if let Some(_) = Some(true) {
    } else {
        if foo.bar() {}
    }
}

fn main() {}

yielding:

rustc 1.16.0 (30cf806ef 2017-03-10)
error[E0301]: cannot mutably borrow in a pattern guard
 --> <anon>:9:15
  |
9 |     } else if foo.bar() {}
  |               ^^^ borrowed mutably in pattern guard

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions