@@ -64,7 +64,7 @@ impl Qualifs<'a, 'mir, 'tcx> {
6464 /// Returns `true` if `local` is `NeedsDrop` at the given `Location`.
6565 ///
6666 /// Only updates the cursor if absolutely necessary
67- fn needs_drop_lazy_seek ( & mut self , local : Local , location : Location ) -> bool {
67+ fn needs_drop ( & mut self , local : Local , location : Location ) -> bool {
6868 if !self . needs_drop . in_any_value_of_ty . contains ( local) {
6969 return false ;
7070 }
@@ -76,7 +76,7 @@ impl Qualifs<'a, 'mir, 'tcx> {
7676 /// Returns `true` if `local` is `HasMutInterior` at the given `Location`.
7777 ///
7878 /// Only updates the cursor if absolutely necessary.
79- fn has_mut_interior_lazy_seek ( & mut self , local : Local , location : Location ) -> bool {
79+ fn has_mut_interior ( & mut self , local : Local , location : Location ) -> bool {
8080 if !self . has_mut_interior . in_any_value_of_ty . contains ( local) {
8181 return false ;
8282 }
@@ -86,17 +86,6 @@ impl Qualifs<'a, 'mir, 'tcx> {
8686 || self . indirectly_mutable ( local, location)
8787 }
8888
89- /// Returns `true` if `local` is `HasMutInterior`, but requires the `has_mut_interior` and
90- /// `indirectly_mutable` cursors to be updated beforehand.
91- fn has_mut_interior_eager_seek ( & self , local : Local ) -> bool {
92- if !self . has_mut_interior . in_any_value_of_ty . contains ( local) {
93- return false ;
94- }
95-
96- self . has_mut_interior . cursor . get ( ) . contains ( local)
97- || self . indirectly_mutable . get ( ) . contains ( local)
98- }
99-
10089 fn in_return_place ( & mut self , item : & Item < ' _ , ' tcx > ) -> ConstQualifs {
10190 // Find the `Return` terminator if one exists.
10291 //
@@ -120,8 +109,8 @@ impl Qualifs<'a, 'mir, 'tcx> {
120109 let return_loc = item. body . terminator_loc ( return_block) ;
121110
122111 ConstQualifs {
123- needs_drop : self . needs_drop_lazy_seek ( RETURN_PLACE , return_loc) ,
124- has_mut_interior : self . has_mut_interior_lazy_seek ( RETURN_PLACE , return_loc) ,
112+ needs_drop : self . needs_drop ( RETURN_PLACE , return_loc) ,
113+ has_mut_interior : self . has_mut_interior ( RETURN_PLACE , return_loc) ,
125114 }
126115 }
127116}
@@ -244,23 +233,6 @@ impl Validator<'a, 'mir, 'tcx> {
244233 self . check_op_spanned ( ops:: StaticAccess , span)
245234 }
246235 }
247-
248- fn check_immutable_borrow_like ( & mut self , location : Location , place : & Place < ' tcx > ) {
249- // FIXME: Change the `in_*` methods to take a `FnMut` so we don't have to manually
250- // seek the cursors beforehand.
251- self . qualifs . has_mut_interior . cursor . seek_before ( location) ;
252- self . qualifs . indirectly_mutable . seek ( location) ;
253-
254- let borrowed_place_has_mut_interior = HasMutInterior :: in_place (
255- & self . item ,
256- & |local| self . qualifs . has_mut_interior_eager_seek ( local) ,
257- place. as_ref ( ) ,
258- ) ;
259-
260- if borrowed_place_has_mut_interior {
261- self . check_op ( ops:: CellBorrow ) ;
262- }
263- }
264236}
265237
266238impl Visitor < ' tcx > for Validator < ' _ , ' mir , ' tcx > {
@@ -366,12 +338,17 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
366338 Rvalue :: AddressOf ( Mutability :: Mut , _) => self . check_op ( ops:: MutAddressOf ) ,
367339
368340 Rvalue :: Ref ( _, BorrowKind :: Shared , ref place)
369- | Rvalue :: Ref ( _, BorrowKind :: Shallow , ref place) => {
370- self . check_immutable_borrow_like ( location, place)
371- }
372-
373- Rvalue :: AddressOf ( Mutability :: Not , ref place) => {
374- self . check_immutable_borrow_like ( location, place)
341+ | Rvalue :: Ref ( _, BorrowKind :: Shallow , ref place)
342+ | Rvalue :: AddressOf ( Mutability :: Not , ref place) => {
343+ let borrowed_place_has_mut_interior = HasMutInterior :: in_place (
344+ & self . item ,
345+ & mut |local| self . qualifs . has_mut_interior ( local, location) ,
346+ place. as_ref ( ) ,
347+ ) ;
348+
349+ if borrowed_place_has_mut_interior {
350+ self . check_op ( ops:: CellBorrow ) ;
351+ }
375352 }
376353
377354 Rvalue :: Cast ( CastKind :: Misc , ref operand, cast_ty) => {
@@ -571,7 +548,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
571548 let needs_drop = if let Some ( local) = dropped_place. as_local ( ) {
572549 // Use the span where the local was declared as the span of the drop error.
573550 err_span = self . body . local_decls [ local] . source_info . span ;
574- self . qualifs . needs_drop_lazy_seek ( local, location)
551+ self . qualifs . needs_drop ( local, location)
575552 } else {
576553 true
577554 } ;
0 commit comments