rust-book icon indicating copy to clipboard operation
rust-book copied to clipboard

4.8 最後一個範例沒有出現錯誤

Open pieceofr opened this issue 4 years ago • 0 comments

4.8 節的範例沒有文中出現的 borrow Error.
也找不到可以參考的原始檔. 因為書中原始檔 github 連結已經失效

let y: &i32;
let x = 5;
y = &x;

println!("{}", y);

以上在rustc 可以正確 compile, 但書中說應該出現

error: x does not live long enough y = &x; ^ note: reference must be valid for the block suffix following statement 0 at 2:16... let y: &i32; let x = 5; y = &x;

println!("{}", y);

}

note: ...but borrowed value is only valid for the block suffix following statement 1 at 3:14 let x = 5; y = &x;

println!("{}", y);

}

pieceofr avatar Jun 25 '21 14:06 pieceofr