Skip to content

Mutating matched value in pattern guard causes segfault in safe code #14684

Closed
@zwarich

Description

@zwarich

The following example causes a segfault for me on OS X / x86_64:

enum Enum<'a> {
    A(&'a int),
    B(bool),
}

fn foo() -> int {
    let mut n = 42;
    let mut x = A(&mut n);
    match x {
        A(_) if { x = B(false); false } => 1,
        A(p) => *p,
        B(_) => 2,
    }
}

fn main() {
    foo();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions