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
  • 388,571
  • 95
  • 1,107
  • 1,366
Sooner
  • 101
  • 4

0 Answers0