@@ -94,7 +94,7 @@ fn check_stmt_semantics(
9494 }
9595
9696 if let Some ( value) = & stmt. value {
97- check_take_of_handle_field ( analyzer, value, state) ;
97+ check_take_of_handle_field ( analyzer, local_analysis , value, state) ;
9898 }
9999 Flow :: Fallthrough
100100 }
@@ -103,7 +103,7 @@ fn check_stmt_semantics(
103103 if function. returns_fresh {
104104 check_fresh_return ( analyzer, function, value, state) ;
105105 }
106- check_take_of_handle_field ( analyzer, value, state) ;
106+ check_take_of_handle_field ( analyzer, local_analysis , value, state) ;
107107 }
108108 Flow :: Return
109109 }
@@ -112,7 +112,7 @@ fn check_stmt_semantics(
112112 check_block ( analyzer, local_analysis, function, & stmt. body , state)
113113 }
114114 Stmt :: If ( stmt) => {
115- check_take_of_handle_field ( analyzer, & stmt. condition , state) ;
115+ check_take_of_handle_field ( analyzer, local_analysis , & stmt. condition , state) ;
116116 apply_expr_effects ( local_analysis, & stmt. condition , state) ;
117117
118118 let base_state = state. clone ( ) ;
@@ -141,7 +141,7 @@ fn check_stmt_semantics(
141141 }
142142 Stmt :: Loop ( stmt) => {
143143 if let Some ( condition) = & stmt. condition {
144- check_take_of_handle_field ( analyzer, condition, state) ;
144+ check_take_of_handle_field ( analyzer, local_analysis , condition, state) ;
145145 apply_expr_effects ( local_analysis, condition, state) ;
146146 }
147147
@@ -164,7 +164,7 @@ fn check_stmt_semantics(
164164 )
165165 }
166166 Stmt :: Expr ( expr) => {
167- check_take_of_handle_field ( analyzer, expr, state) ;
167+ check_take_of_handle_field ( analyzer, local_analysis , expr, state) ;
168168 Flow :: Fallthrough
169169 }
170170 Stmt :: Break ( _) => Flow :: Break ,
@@ -295,7 +295,12 @@ fn check_managed_closure_captures(analyzer: &mut Analyzer<'_>, body: &Block, sta
295295 }
296296}
297297
298- fn check_take_of_handle_field ( analyzer : & mut Analyzer < ' _ > , expr : & Expr , state : & BodyState ) {
298+ fn check_take_of_handle_field (
299+ analyzer : & mut Analyzer < ' _ > ,
300+ local_analysis : & LocalAnalysis ,
301+ expr : & Expr ,
302+ state : & BodyState ,
303+ ) {
299304 match expr {
300305 Expr :: Effect {
301306 effect : DataEffect :: Take ,
@@ -307,7 +312,7 @@ fn check_take_of_handle_field(analyzer: &mut Analyzer<'_>, expr: &Expr, state: &
307312 name,
308313 span : field_span,
309314 } = value. as_ref ( )
310- && is_handle_field ( analyzer, state, base, name, field_span)
315+ && is_handle_field ( analyzer, local_analysis , state, base, name, field_span)
311316 {
312317 analyzer. diagnostics . push (
313318 Diagnostic :: error (
@@ -319,63 +324,74 @@ fn check_take_of_handle_field(analyzer: &mut Analyzer<'_>, expr: &Expr, state: &
319324 . with_cause ( "Handle fields are managed references and cannot be consumed as local inline values." ) ,
320325 ) ;
321326 }
322- check_take_of_handle_field ( analyzer, value, state) ;
327+ check_take_of_handle_field ( analyzer, local_analysis, value, state) ;
328+ }
329+ Expr :: Effect { value, .. } => {
330+ check_take_of_handle_field ( analyzer, local_analysis, value, state) ;
331+ }
332+ Expr :: Manage { value, .. } => {
333+ check_take_of_handle_field ( analyzer, local_analysis, value, state) ;
323334 }
324- Expr :: Effect { value, .. } => check_take_of_handle_field ( analyzer, value, state) ,
325- Expr :: Manage { value, .. } => check_take_of_handle_field ( analyzer, value, state) ,
326335 Expr :: Call { args, .. } => {
327336 for arg in args {
328- check_take_of_handle_field ( analyzer, & arg. value , state) ;
337+ check_take_of_handle_field ( analyzer, local_analysis , & arg. value , state) ;
329338 }
330339 }
331- Expr :: Field { base, .. } => check_take_of_handle_field ( analyzer, base, state) ,
340+ Expr :: Field { base, .. } => {
341+ check_take_of_handle_field ( analyzer, local_analysis, base, state) ;
342+ }
332343 Expr :: Closure { body, .. } => {
333344 for statement in & body. statements {
334- check_take_of_handle_in_stmt ( analyzer, statement, state) ;
345+ check_take_of_handle_in_stmt ( analyzer, local_analysis , statement, state) ;
335346 }
336347 }
337348 Expr :: Ident ( _, _) | Expr :: Number ( _, _) | Expr :: String ( _, _) | Expr :: Unknown ( _) => { }
338349 }
339350}
340351
341- fn check_take_of_handle_in_stmt ( analyzer : & mut Analyzer < ' _ > , statement : & Stmt , state : & BodyState ) {
352+ fn check_take_of_handle_in_stmt (
353+ analyzer : & mut Analyzer < ' _ > ,
354+ local_analysis : & LocalAnalysis ,
355+ statement : & Stmt ,
356+ state : & BodyState ,
357+ ) {
342358 match statement {
343359 Stmt :: Let ( stmt) => {
344360 if let Some ( value) = & stmt. value {
345- check_take_of_handle_field ( analyzer, value, state) ;
361+ check_take_of_handle_field ( analyzer, local_analysis , value, state) ;
346362 }
347363 }
348364 Stmt :: Return ( stmt) => {
349365 if let Some ( value) = & stmt. value {
350- check_take_of_handle_field ( analyzer, value, state) ;
366+ check_take_of_handle_field ( analyzer, local_analysis , value, state) ;
351367 }
352368 }
353369 Stmt :: With ( stmt) => {
354- check_take_of_handle_field ( analyzer, & stmt. resource , state) ;
370+ check_take_of_handle_field ( analyzer, local_analysis , & stmt. resource , state) ;
355371 for statement in & stmt. body . statements {
356- check_take_of_handle_in_stmt ( analyzer, statement, state) ;
372+ check_take_of_handle_in_stmt ( analyzer, local_analysis , statement, state) ;
357373 }
358374 }
359375 Stmt :: If ( stmt) => {
360- check_take_of_handle_field ( analyzer, & stmt. condition , state) ;
376+ check_take_of_handle_field ( analyzer, local_analysis , & stmt. condition , state) ;
361377 for statement in & stmt. then_body . statements {
362- check_take_of_handle_in_stmt ( analyzer, statement, state) ;
378+ check_take_of_handle_in_stmt ( analyzer, local_analysis , statement, state) ;
363379 }
364380 if let Some ( else_body) = & stmt. else_body {
365381 for statement in & else_body. statements {
366- check_take_of_handle_in_stmt ( analyzer, statement, state) ;
382+ check_take_of_handle_in_stmt ( analyzer, local_analysis , statement, state) ;
367383 }
368384 }
369385 }
370386 Stmt :: Loop ( stmt) => {
371387 if let Some ( condition) = & stmt. condition {
372- check_take_of_handle_field ( analyzer, condition, state) ;
388+ check_take_of_handle_field ( analyzer, local_analysis , condition, state) ;
373389 }
374390 for statement in & stmt. body . statements {
375- check_take_of_handle_in_stmt ( analyzer, statement, state) ;
391+ check_take_of_handle_in_stmt ( analyzer, local_analysis , statement, state) ;
376392 }
377393 }
378- Stmt :: Expr ( expr) => check_take_of_handle_field ( analyzer, expr, state) ,
394+ Stmt :: Expr ( expr) => check_take_of_handle_field ( analyzer, local_analysis , expr, state) ,
379395 Stmt :: Break ( _) | Stmt :: Continue ( _) => { }
380396 Stmt :: Unknown ( _) => { }
381397 }
@@ -676,12 +692,13 @@ fn infer_call_type(
676692
677693fn is_handle_field (
678694 analyzer : & Analyzer < ' _ > ,
695+ local_analysis : & LocalAnalysis ,
679696 state : & BodyState ,
680697 base : & Expr ,
681698 field_name : & str ,
682699 field_span : & crate :: diagnostic:: Span ,
683700) -> bool {
684- if let Some ( field) = analyzer . hir . field_access ( field_span) {
701+ if let Some ( field) = local_analysis . field_access ( field_span) {
685702 return field. is_handle ;
686703 }
687704
0 commit comments