Skip to content

Cloning &strs doesn't trigger borrow checker #19704

Closed
@Manishearth

Description

@Manishearth

MWE:

fn get() -> Option<String> {
 Some("hi".to_string())
}

fn main() {
 let y = match get() {
  Some(x) => x.as_slice().clone(),
  None => "hello"
 };
 let mut z = "something".to_string();
 for i in range(1,1000u) {
   z = format!("{}", i);
   println!("{}", z)
 }
 println!("{}", y)
}

The last thing it prints out should be "hi". Instead it prints out "99" -- it it looks like the String x is deallocated in the match, but the pointer to the freed memory lives on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions