Skip to content

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

@pieceofr

Description

@pieceofr

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

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions