@@ -82,10 +82,12 @@ impl<'a> visit::Visitor<()> for GatherLoanCtxt<'a> {
8282 fn visit_block ( & mut self , b : & Block , _: ( ) ) {
8383 gather_loans_in_block ( self , b) ;
8484 }
85- fn visit_fn ( & mut self , fk : & FnKind , fd : & FnDecl , b : & Block ,
86- s : Span , n : NodeId , _: ( ) ) {
87- gather_loans_in_fn ( self , fk, fd, b, s, n) ;
88- }
85+
86+ /// Do not visit closures or fn items here, the outer loop in
87+ /// borrowck/mod will visit them for us in turn.
88+ fn visit_fn ( & mut self , _: & FnKind , _: & FnDecl , _: & Block ,
89+ _: Span , _: NodeId , _: ( ) ) { }
90+
8991 fn visit_stmt ( & mut self , s : & Stmt , _: ( ) ) {
9092 visit:: walk_stmt ( self , s, ( ) ) ;
9193 }
@@ -99,10 +101,20 @@ impl<'a> visit::Visitor<()> for GatherLoanCtxt<'a> {
99101 // #7740: Do not visit items here, not even fn items nor methods
100102 // of impl items; the outer loop in borrowck/mod will visit them
101103 // for us in turn. Thus override visit_item's walk with a no-op.
102- fn visit_item ( & mut self , _: & ast:: Item , _: ( ) ) { }
104+ fn visit_item ( & mut self , _: & ast:: Item , _: ( ) ) { }
103105}
104106
105- pub fn gather_loans ( bccx : & BorrowckCtxt , decl : & ast:: FnDecl , body : & ast:: Block )
107+ fn add_pat_to_id_range ( this : & mut GatherLoanCtxt ,
108+ p : & ast:: Pat ) {
109+ // NB: This visitor function just adds the pat ids into the id
110+ // range. We gather loans that occur in patterns using the
111+ // `gather_pat()` method below. Eventually these two should be
112+ // brought together.
113+ this. id_range . add ( p. id ) ;
114+ visit:: walk_pat ( this, p, ( ) ) ;
115+ }
116+
117+ pub fn gather_loans_in_fn ( bccx : & BorrowckCtxt , decl : & ast:: FnDecl , body : & ast:: Block )
106118 -> ( IdRange , Vec < Loan > , move_data:: MoveData ) {
107119 let mut glcx = GatherLoanCtxt {
108120 bccx : bccx,
@@ -119,27 +131,6 @@ pub fn gather_loans(bccx: &BorrowckCtxt, decl: &ast::FnDecl, body: &ast::Block)
119131 ( id_range, all_loans, move_data)
120132}
121133
122- fn add_pat_to_id_range ( this : & mut GatherLoanCtxt ,
123- p : & ast:: Pat ) {
124- // NB: This visitor function just adds the pat ids into the id
125- // range. We gather loans that occur in patterns using the
126- // `gather_pat()` method below. Eventually these two should be
127- // brought together.
128- this. id_range . add ( p. id ) ;
129- visit:: walk_pat ( this, p, ( ) ) ;
130- }
131-
132- fn gather_loans_in_fn ( _v : & mut GatherLoanCtxt ,
133- _fk : & FnKind ,
134- _decl : & ast:: FnDecl ,
135- _body : & ast:: Block ,
136- _sp : Span ,
137- _id : ast:: NodeId ) {
138- // Do not visit closures or fn items here, the outer loop in
139- // borrowck/mod will visit them for us in turn.
140- return ;
141- }
142-
143134fn gather_loans_in_block ( this : & mut GatherLoanCtxt ,
144135 blk : & ast:: Block ) {
145136 this. id_range . add ( blk. id ) ;
@@ -171,6 +162,28 @@ fn gather_loans_in_local(this: &mut GatherLoanCtxt,
171162 visit:: walk_local ( this, local, ( ) ) ;
172163}
173164
165+ pub fn gather_loans_in_static_initializer ( bccx : & mut BorrowckCtxt , expr : & ast:: Expr ) {
166+
167+ debug ! ( "gather_loans_in_item(expr={})" , expr. repr( bccx. tcx) ) ;
168+
169+ let mut glcx = GatherLoanCtxt {
170+ bccx : bccx,
171+ id_range : IdRange :: max ( ) ,
172+ all_loans : Vec :: new ( ) ,
173+ item_ub : expr. id ,
174+ repeating_ids : vec ! ( expr. id) ,
175+ move_data : MoveData :: new ( )
176+ } ;
177+
178+ match expr. node {
179+ // Just visit the expression if the
180+ // item is taking an address.
181+ ast:: ExprAddrOf ( ..) => {
182+ glcx. visit_expr ( expr, ( ) ) ;
183+ }
184+ _ => { }
185+ }
186+ }
174187
175188fn gather_loans_in_expr ( this : & mut GatherLoanCtxt ,
176189 ex : & ast:: Expr ) {
0 commit comments