3

Shouldn't test vanish after going out of the scope? Why can println! still print the value of test?

fn skip<'a>(line: &'a str, _prefix: &'a str) -> &'a str {
    line
}

fn main() {
    let line = "aaa";
    let q;
    {
        let test = "bbb";
        q = skip(test, line);
    }
    println!("{}", q);
}
Shepmaster
  • 326,504
  • 69
  • 892
  • 1,159
Sooner
  • 91
  • 3

0 Answers0