Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pieceofr opened this issue Jun 25, 2021 · 0 comments
Open

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

pieceofr opened this issue Jun 25, 2021 · 0 comments

Comments

@pieceofr
Copy link

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);

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant