-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Change check_loans to use ExprUseVisitor #14318
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d123188
Clean up check_loans.
0339b27
Fix mem_categorization to treat an AutoObject adjustment as an rvalue.
f63fad5
Add an Init mode to MutateMode.
5ccb764
Add a move reason to the Move ConsumeMode.
40e3fb4
Use the MoveReason to determine a more precise MoveKind in gather_moves.
78934b0
Add a kind_of_move_of_path method to FlowedMoveData.
c53d296
Change check_loans to use ExprUseVisitor.
74eb4b4
Add new tests for borrowck field-sensitivity.
f1542a6
Add a test for borrowck errors with multiple closure captures.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
struct A { a: int, b: Box<int> } | ||
|
||
fn borrow<T>(_: &T) { } | ||
|
||
fn use_after_move() { | ||
let x = A { a: 1, b: box 2 }; | ||
drop(x.b); | ||
drop(*x.b); //~ ERROR use of partially moved value: `*x.b` | ||
} | ||
|
||
fn use_after_fu_move() { | ||
let x = A { a: 1, b: box 2 }; | ||
let y = A { a: 3, .. x }; | ||
drop(*x.b); //~ ERROR use of partially moved value: `*x.b` | ||
} | ||
|
||
fn borrow_after_move() { | ||
let x = A { a: 1, b: box 2 }; | ||
drop(x.b); | ||
borrow(&x.b); //~ ERROR use of moved value: `x.b` | ||
} | ||
|
||
fn borrow_after_fu_move() { | ||
let x = A { a: 1, b: box 2 }; | ||
let _y = A { a: 3, .. x }; | ||
borrow(&x.b); //~ ERROR use of moved value: `x.b` | ||
} | ||
|
||
fn move_after_borrow() { | ||
let x = A { a: 1, b: box 2 }; | ||
let y = &x.b; | ||
drop(x.b); //~ ERROR cannot move out of `x.b` because it is borrowed | ||
borrow(&*y); | ||
} | ||
|
||
fn fu_move_after_borrow() { | ||
let x = A { a: 1, b: box 2 }; | ||
let y = &x.b; | ||
let _z = A { a: 3, .. x }; //~ ERROR cannot move out of `x.b` because it is borrowed | ||
borrow(&*y); | ||
} | ||
|
||
fn mut_borrow_after_mut_borrow() { | ||
let mut x = A { a: 1, b: box 2 }; | ||
let y = &mut x.a; | ||
let z = &mut x.a; //~ ERROR cannot borrow `x.a` as mutable more than once at a time | ||
drop(*y); | ||
drop(*z); | ||
} | ||
|
||
fn move_after_move() { | ||
let x = A { a: 1, b: box 2 }; | ||
drop(x.b); | ||
drop(x.b); //~ ERROR use of moved value: `x.b` | ||
} | ||
|
||
fn move_after_fu_move() { | ||
let x = A { a: 1, b: box 2 }; | ||
let _y = A { a: 3, .. x }; | ||
drop(x.b); //~ ERROR use of moved value: `x.b` | ||
} | ||
|
||
fn fu_move_after_move() { | ||
let x = A { a: 1, b: box 2 }; | ||
drop(x.b); | ||
let _z = A { a: 3, .. x }; //~ ERROR use of moved value: `x.b` | ||
} | ||
|
||
fn fu_move_after_fu_move() { | ||
let x = A { a: 1, b: box 2 }; | ||
let _y = A { a: 3, .. x }; | ||
let _z = A { a: 4, .. x }; //~ ERROR use of moved value: `x.b` | ||
} | ||
|
||
// The following functions aren't yet accepted, but they should be. | ||
|
||
fn use_after_field_assign_after_uninit() { | ||
let mut x: A; | ||
x.a = 1; | ||
drop(x.a); //~ ERROR use of possibly uninitialized variable: `x.a` | ||
} | ||
|
||
fn borrow_after_field_assign_after_uninit() { | ||
let mut x: A; | ||
x.a = 1; | ||
borrow(&x.a); //~ ERROR use of possibly uninitialized variable: `x.a` | ||
} | ||
|
||
fn move_after_field_assign_after_uninit() { | ||
let mut x: A; | ||
x.b = box 1; | ||
drop(x.b); //~ ERROR use of possibly uninitialized variable: `x.b` | ||
} | ||
|
||
fn main() { | ||
use_after_move(); | ||
use_after_fu_move(); | ||
|
||
borrow_after_move(); | ||
borrow_after_fu_move(); | ||
move_after_borrow(); | ||
fu_move_after_borrow(); | ||
mut_borrow_after_mut_borrow(); | ||
|
||
move_after_move(); | ||
move_after_fu_move(); | ||
fu_move_after_move(); | ||
fu_move_after_fu_move(); | ||
|
||
use_after_field_assign_after_uninit(); | ||
borrow_after_field_assign_after_uninit(); | ||
move_after_field_assign_after_uninit(); | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use std::task; | ||
|
||
fn borrow<T>(_: &T) { } | ||
|
||
fn different_vars_after_borrows() { | ||
let x1 = box 1; | ||
let p1 = &x1; | ||
let x2 = box 2; | ||
let p2 = &x2; | ||
task::spawn(proc() { | ||
drop(x1); //~ ERROR cannot move `x1` into closure because it is borrowed | ||
drop(x2); //~ ERROR cannot move `x2` into closure because it is borrowed | ||
}); | ||
borrow(&*p1); | ||
borrow(&*p2); | ||
} | ||
|
||
fn different_vars_after_moves() { | ||
let x1 = box 1; | ||
drop(x1); | ||
let x2 = box 2; | ||
drop(x2); | ||
task::spawn(proc() { | ||
drop(x1); //~ ERROR capture of moved value: `x1` | ||
drop(x2); //~ ERROR capture of moved value: `x2` | ||
}); | ||
} | ||
|
||
fn same_var_after_borrow() { | ||
let x = box 1; | ||
let p = &x; | ||
task::spawn(proc() { | ||
drop(x); //~ ERROR cannot move `x` into closure because it is borrowed | ||
drop(x); //~ ERROR use of moved value: `x` | ||
}); | ||
borrow(&*p); | ||
} | ||
|
||
fn same_var_after_move() { | ||
let x = box 1; | ||
drop(x); | ||
task::spawn(proc() { | ||
drop(x); //~ ERROR capture of moved value: `x` | ||
drop(x); //~ ERROR use of moved value: `x` | ||
}); | ||
} | ||
|
||
fn main() { | ||
different_vars_after_borrows(); | ||
different_vars_after_moves(); | ||
same_var_after_borrow(); | ||
same_var_after_move(); | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am surprised that we can drop
*y
and*z
, as that is borrowed content. Is this simply an artifact of us not reporting an error for some other reason?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine because
*y
and*z
are integers, and they seem to get copied rather than moved. This code compiles fine:but if I use the
x.b
field, which is aBox<int>
, like this:then I get an error:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Wed, May 28, 2014 at 12:46:04PM -0700, Cameron Zwarich wrote:
Indeed. I overlooked that.