超出范围后,为什么字符串文字不消失?

时间:2018-08-16 07:22:08

标签: rust

test超出范围后不应该消失吗?为什么println!仍可以打印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);
}

0 个答案:

没有答案