Skip to content

Modifying a Option<String> via pattern matching results in inconsistent behavior #15571

Closed
@ghost

Description

The following code worked as of 0.11.0 but no longer produces an expected result on master.

fn main() {
    let mut foo = Some("Kitten".to_string());
    match foo {
        None => {},
        Some(x) => {
            foo = Some(x);
        }
    };
    println!("'{:s}'", foo.unwrap());
}

on 0.11.0:

'Kitten'

on master:

''

Another example

fn main() {
    let mut foo = Some(box 5i);
    match foo {
        None => {},
        Some(x) => {
            foo = Some(x);
        }
    };
    println!("'{}'", foo.unwrap());
}

on 0.11.0:

'5'

on master:

task '<main>' failed at 'called `Option::unwrap()` on a `None` value', /build/rust-git/src/rust/src/libcore/option.rs:265

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions