You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The borrow checker currently does not track whether variables are initialized or have been moved. This means programs that use uninitialized variables or use variables after they've been moved are accepted when they should be rejected.
For example, this should be an error but currently passes:
fn foo() -> u32 {
let x: u32;
return x; // x was never initialized
}
And this should also be an error:
fn foo() -> u32 {
let x: u32 = 0_u32;
let y: u32 = x; // x moved here
let z: u32 = x; // use of moved value
return z;
}
Ignored tests (#[ignore] in src/test/borrowck.rs):
use_of_uninitialized_variable — read from a never-initialized variable
use_of_moved_variable — read from a variable after it was moved
conditional_init_one_branch — variable initialized in only one if-branch, used after
assign_field_of_uninitialized — assign to a field of an uninitialized struct (rustc rejects this)
partial_move_use_whole — use whole struct after one field was moved
move_same_field_twice — move the same field twice
move_whole_then_access_field — access a field after the whole struct was moved
move_parent_then_access_child — access x.foo.bar after x.foo was moved
move_in_loop — move inside a loop body (visible on second iteration)
Updates #254. Related to #209.
The borrow checker currently does not track whether variables are initialized or have been moved. This means programs that use uninitialized variables or use variables after they've been moved are accepted when they should be rejected.
For example, this should be an error but currently passes:
And this should also be an error:
Ignored tests (
#[ignore]insrc/test/borrowck.rs):use_of_uninitialized_variable— read from a never-initialized variableuse_of_moved_variable— read from a variable after it was movedconditional_init_one_branch— variable initialized in only one if-branch, used afterassign_field_of_uninitialized— assign to a field of an uninitialized struct (rustc rejects this)partial_move_use_whole— use whole struct after one field was movedmove_same_field_twice— move the same field twicemove_whole_then_access_field— access a field after the whole struct was movedmove_parent_then_access_child— accessx.foo.barafterx.foowas movedmove_in_loop— move inside a loop body (visible on second iteration)uninitialized_return— return an uninitialized value (Extend type/borrow-check to guarantee values are returned #209)Passing tests (happy paths that should continue to pass):
reinit_after_move— assignment after move re-initializesconditional_init_both_branches— both if-branches initializepartial_move_use_sibling— sibling field still accessible after partial move