@@ -11,11 +11,11 @@ use rustc_hir::{self as hir, LangItem};
11
11
use rustc_index:: bit_set:: BitSet ;
12
12
use rustc_infer:: infer:: TyCtxtInferExt ;
13
13
use rustc_infer:: traits:: ObligationCause ;
14
- use rustc_middle:: mir:: visit:: { MutatingUseContext , NonMutatingUseContext , PlaceContext , Visitor } ;
14
+ use rustc_middle:: mir:: visit:: Visitor ;
15
15
use rustc_middle:: mir:: * ;
16
16
use rustc_middle:: span_bug;
17
17
use rustc_middle:: ty:: adjustment:: PointerCoercion ;
18
- use rustc_middle:: ty:: { self , Instance , InstanceKind , Ty , TyCtxt , TypeVisitableExt } ;
18
+ use rustc_middle:: ty:: { self , Instance , InstanceKind , Ty , TypeVisitableExt } ;
19
19
use rustc_mir_dataflow:: impls:: MaybeStorageLive ;
20
20
use rustc_mir_dataflow:: storage:: always_storage_live_locals;
21
21
use rustc_mir_dataflow:: Analysis ;
@@ -373,47 +373,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
373
373
fn visit_rvalue ( & mut self , rvalue : & Rvalue < ' tcx > , location : Location ) {
374
374
trace ! ( "visit_rvalue: rvalue={:?} location={:?}" , rvalue, location) ;
375
375
376
- // Special-case reborrows to be more like a copy of a reference.
377
- // FIXME: this does not actually handle all reborrows. It only detects cases where `*` is the outermost
378
- // projection of the borrowed place, it skips deref'ing raw pointers and it skips `static`.
379
- // All those cases are handled below with shared/mutable borrows.
380
- // Once `const_mut_refs` is stable, we should be able to entirely remove this special case.
381
- // (`const_refs_to_cell` is not needed, we already allow all borrows of indirect places anyway.)
382
- match * rvalue {
383
- Rvalue :: Ref ( _, kind, place) => {
384
- if let Some ( reborrowed_place_ref) = place_as_reborrow ( self . tcx , self . body , place) {
385
- let ctx = match kind {
386
- BorrowKind :: Shared => {
387
- PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: SharedBorrow )
388
- }
389
- BorrowKind :: Fake ( _) => {
390
- PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: FakeBorrow )
391
- }
392
- BorrowKind :: Mut { .. } => {
393
- PlaceContext :: MutatingUse ( MutatingUseContext :: Borrow )
394
- }
395
- } ;
396
- self . visit_local ( reborrowed_place_ref. local , ctx, location) ;
397
- self . visit_projection ( reborrowed_place_ref, ctx, location) ;
398
- return ;
399
- }
400
- }
401
- Rvalue :: RawPtr ( mutbl, place) => {
402
- if let Some ( reborrowed_place_ref) = place_as_reborrow ( self . tcx , self . body , place) {
403
- let ctx = match mutbl {
404
- Mutability :: Not => {
405
- PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: RawBorrow )
406
- }
407
- Mutability :: Mut => PlaceContext :: MutatingUse ( MutatingUseContext :: RawBorrow ) ,
408
- } ;
409
- self . visit_local ( reborrowed_place_ref. local , ctx, location) ;
410
- self . visit_projection ( reborrowed_place_ref, ctx, location) ;
411
- return ;
412
- }
413
- }
414
- _ => { }
415
- }
416
-
417
376
self . super_rvalue ( rvalue, location) ;
418
377
419
378
match rvalue {
@@ -885,40 +844,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
885
844
}
886
845
}
887
846
888
- fn place_as_reborrow < ' tcx > (
889
- tcx : TyCtxt < ' tcx > ,
890
- body : & Body < ' tcx > ,
891
- place : Place < ' tcx > ,
892
- ) -> Option < PlaceRef < ' tcx > > {
893
- match place. as_ref ( ) . last_projection ( ) {
894
- Some ( ( place_base, ProjectionElem :: Deref ) ) => {
895
- // FIXME: why do statics and raw pointers get excluded here? This makes
896
- // some code involving mutable pointers unstable, but it is unclear
897
- // why that code is treated differently from mutable references.
898
- // Once TransientMutBorrow and TransientCellBorrow are stable,
899
- // this can probably be cleaned up without any behavioral changes.
900
-
901
- // A borrow of a `static` also looks like `&(*_1)` in the MIR, but `_1` is a `const`
902
- // that points to the allocation for the static. Don't treat these as reborrows.
903
- if body. local_decls [ place_base. local ] . is_ref_to_static ( ) {
904
- None
905
- } else {
906
- // Ensure the type being derefed is a reference and not a raw pointer.
907
- // This is sufficient to prevent an access to a `static mut` from being marked as a
908
- // reborrow, even if the check above were to disappear.
909
- let inner_ty = place_base. ty ( body, tcx) . ty ;
910
-
911
- if let ty:: Ref ( ..) = inner_ty. kind ( ) {
912
- return Some ( place_base) ;
913
- } else {
914
- return None ;
915
- }
916
- }
917
- }
918
- _ => None ,
919
- }
920
- }
921
-
922
847
fn is_int_bool_float_or_char ( ty : Ty < ' _ > ) -> bool {
923
848
ty. is_bool ( ) || ty. is_integral ( ) || ty. is_char ( ) || ty. is_floating_point ( )
924
849
}
0 commit comments