@@ -28,6 +28,57 @@ use util::ppaux::Repr;
28
28
29
29
use std:: rc:: Rc ;
30
30
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
+
31
82
struct CheckLoanCtxt < ' a > {
32
83
bccx : & ' a BorrowckCtxt < ' a > ,
33
84
dfcx_loans : & ' a LoanDataFlow < ' a > ,
0 commit comments