Skip to content

Commit 6eda192

Browse files
author
Cameron Zwarich
committed
---
yaml --- r: 126177 b: refs/heads/auto c: 8c4dbf3 h: refs/heads/master i: 126175: 0eb757a v: v3
1 parent de54843 commit 6eda192

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 8da03d9771bc827eae713d16bca7bec4c5fe6a10
16+
refs/heads/auto: 8c4dbf3d4750feb47aec09b3f2df848e8f7b5469
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/librustc/middle/borrowck/check_loans.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,57 @@ use util::ppaux::Repr;
2828

2929
use std::rc::Rc;
3030

31+
// FIXME (#16118): These functions are intended to allow the borrow checker to
32+
// be less precise in its handling of Box while still allowing moves out of a
33+
// Box. They should be removed when OwnedPtr is removed from LoanPath.
34+
35+
fn owned_ptr_base_path<'a>(loan_path: &'a LoanPath) -> &'a LoanPath {
36+
//! Returns the base of the leftmost dereference of an OwnedPtr in
37+
//! `loan_path`. If there is no dereference of an OwnedPtr in `loan_path`,
38+
//! then it just returns `loan_path` itself.
39+
40+
return match owned_ptr_base_path_helper(loan_path) {
41+
Some(new_loan_path) => new_loan_path,
42+
None => loan_path.clone()
43+
};
44+
45+
fn owned_ptr_base_path_helper<'a>(loan_path: &'a LoanPath) -> Option<&'a LoanPath> {
46+
match *loan_path {
47+
LpVar(_) | LpUpvar(_) => None,
48+
LpExtend(ref lp_base, _, LpDeref(mc::OwnedPtr)) => {
49+
match owned_ptr_base_path_helper(&**lp_base) {
50+
v @ Some(_) => v,
51+
None => Some(&**lp_base)
52+
}
53+
}
54+
LpExtend(ref lp_base, _, _) => owned_ptr_base_path_helper(&**lp_base)
55+
}
56+
}
57+
}
58+
59+
fn owned_ptr_base_path_rc(loan_path: &Rc<LoanPath>) -> Rc<LoanPath> {
60+
//! The equivalent of `owned_ptr_base_path` for an &Rc<LoanPath> rather than
61+
//! a &LoanPath.
62+
63+
return match owned_ptr_base_path_helper(loan_path) {
64+
Some(new_loan_path) => new_loan_path,
65+
None => loan_path.clone()
66+
};
67+
68+
fn owned_ptr_base_path_helper(loan_path: &Rc<LoanPath>) -> Option<Rc<LoanPath>> {
69+
match **loan_path {
70+
LpVar(_) | LpUpvar(_) => None,
71+
LpExtend(ref lp_base, _, LpDeref(mc::OwnedPtr)) => {
72+
match owned_ptr_base_path_helper(lp_base) {
73+
v @ Some(_) => v,
74+
None => Some(lp_base.clone())
75+
}
76+
}
77+
LpExtend(ref lp_base, _, _) => owned_ptr_base_path_helper(lp_base)
78+
}
79+
}
80+
}
81+
3182
struct CheckLoanCtxt<'a> {
3283
bccx: &'a BorrowckCtxt<'a>,
3384
dfcx_loans: &'a LoanDataFlow<'a>,

0 commit comments

Comments
 (0)