Skip to content

Matching strings in beta and nightly #35044

Closed
@hank-der-hafenarbeiter

Description

@hank-der-hafenarbeiter

when matching &str in nightly or beta the following code always returns the first match case:

#[derive(Debug, PartialEq)]
enum Reg {
    EAX,
    EBX,
    ECX,
    EDX,
    ESP,
    EBP,
    ISP,
}

fn string_to_reg(_s:&str) -> Reg {
    match _s.as_ref() {
        "EAX" => Reg::EAX,
        "EBX" => Reg::EBX,
        "ECX" => Reg::ECX,
        "EDX" => Reg::EDX,
        "EBP" => Reg::EBP,
        "ESP" => Reg::ESP,
        "ISP" => Reg::ISP,
        &_    => panic!("bla bla bla"),  //removing this "&" fixes it
    }
}

fn main() {
    let vec = vec!["EAX", "EBX", "ECX", "EDX", "ESP", "EBP", "ISP"];
    let mut iter = vec.iter();
    println!("{:?}", string_to_reg(""));
    println!("{:?}", string_to_reg(iter.next().unwrap()));
    println!("{:?}", string_to_reg(iter.next().unwrap()));
    println!("{:?}", string_to_reg(iter.next().unwrap()));
    println!("{:?}", string_to_reg(iter.next().unwrap()));
    println!("{:?}",  string_to_reg(iter.next().unwrap()));     
    println!("{:?}", string_to_reg(iter.next().unwrap()));
    println!("{:?}",  string_to_reg(iter.next().unwrap()));
}

Expected behaviour is returning the fitting case. This can be fixed by removing the "&" in front of the last case.

Meta

tested on my machine with: rustc 1.11.0-nightly (bb4a79b 2016-06-15)
tested on here with beta and nightly showing the bug and stable giving a runtime error.

Metadata

Metadata

Assignees

Labels

P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions