@@ -2,7 +2,7 @@ use crate::borrow_check::ArtificialField;
2
2
use crate :: borrow_check:: Overlap ;
3
3
use crate :: borrow_check:: { Deep , Shallow , AccessDepth } ;
4
4
use rustc:: hir;
5
- use rustc:: mir:: { BorrowKind , Mir , Place , PlaceBase , Projection , ProjectionElem , Static , StaticKind } ;
5
+ use rustc:: mir:: { BorrowKind , Mir , Place , PlaceBase , Projection , ProjectionElem , StaticKind } ;
6
6
use rustc:: ty:: { self , TyCtxt } ;
7
7
use std:: cmp:: max;
8
8
@@ -370,71 +370,47 @@ fn place_element_conflict<'a, 'gcx: 'tcx, 'tcx>(
370
370
Overlap :: Disjoint
371
371
}
372
372
}
373
- (
374
- Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Static ( def_id_1) , .. } ) ) ,
375
- Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Static ( def_id_2) , .. } ) ) ,
376
- ) => {
377
- if * def_id_1 != * def_id_2 {
378
- debug ! ( "place_element_conflict: DISJOINT-STATIC" ) ;
379
- Overlap :: Disjoint
380
- } else if tcx. is_static ( * def_id_1) == Some ( hir:: Mutability :: MutMutable ) {
381
- // We ignore mutable statics - they can only be unsafe code.
382
- debug ! ( "place_element_conflict: IGNORE-STATIC-MUT" ) ;
383
- Overlap :: Disjoint
384
- } else {
385
- debug ! ( "place_element_conflict: DISJOINT-OR-EQ-STATIC" ) ;
386
- Overlap :: EqualOrDisjoint
387
- }
388
- }
389
- (
390
- Place :: Base (
391
- PlaceBase :: Static ( box Static { kind : StaticKind :: Promoted ( promoted_1) , ty } )
392
- ) ,
393
- Place :: Base (
394
- PlaceBase :: Static ( box Static { kind : StaticKind :: Promoted ( promoted_2) , .. } )
395
- ) ,
396
- ) => {
397
- if * promoted_1 == * promoted_2 {
398
- if let ty:: Array ( _, size) = ty. sty {
399
- if size. unwrap_usize ( tcx) == 0 {
400
- // Ignore conflicts with promoted [T; 0].
401
- debug ! ( "place_element_conflict: IGNORE-LEN-0-PROMOTED" ) ;
402
- return Overlap :: Disjoint ;
373
+ ( Place :: Base ( PlaceBase :: Static ( s1) ) , Place :: Base ( PlaceBase :: Static ( s2) ) ) => {
374
+ match ( & s1. kind , & s2. kind ) {
375
+ ( StaticKind :: Static ( def_id_1) , StaticKind :: Static ( def_id_2) ) => {
376
+ if def_id_1 != def_id_2 {
377
+ debug ! ( "place_element_conflict: DISJOINT-STATIC" ) ;
378
+ Overlap :: Disjoint
379
+ } else if tcx. is_static ( * def_id_1) == Some ( hir:: Mutability :: MutMutable ) {
380
+ // We ignore mutable statics - they can only be unsafe code.
381
+ debug ! ( "place_element_conflict: IGNORE-STATIC-MUT" ) ;
382
+ Overlap :: Disjoint
383
+ } else {
384
+ debug ! ( "place_element_conflict: DISJOINT-OR-EQ-STATIC" ) ;
385
+ Overlap :: EqualOrDisjoint
403
386
}
387
+ } ,
388
+ ( StaticKind :: Promoted ( promoted_1) , StaticKind :: Promoted ( promoted_2) ) => {
389
+ if promoted_1 == promoted_2 {
390
+ if let ty:: Array ( _, size) = s1. ty . sty {
391
+ if size. unwrap_usize ( tcx) == 0 {
392
+ // Ignore conflicts with promoted [T; 0].
393
+ debug ! ( "place_element_conflict: IGNORE-LEN-0-PROMOTED" ) ;
394
+ return Overlap :: Disjoint ;
395
+ }
396
+ }
397
+ // the same promoted - base case, equal
398
+ debug ! ( "place_element_conflict: DISJOINT-OR-EQ-PROMOTED" ) ;
399
+ Overlap :: EqualOrDisjoint
400
+ } else {
401
+ // different promoteds - base case, disjoint
402
+ debug ! ( "place_element_conflict: DISJOINT-PROMOTED" ) ;
403
+ Overlap :: Disjoint
404
+ }
405
+ } ,
406
+ ( _, _) => {
407
+ debug ! ( "place_element_conflict: DISJOINT-STATIC-PROMOTED" ) ;
408
+ Overlap :: Disjoint
404
409
}
405
- // the same promoted - base case, equal
406
- debug ! ( "place_element_conflict: DISJOINT-OR-EQ-PROMOTED" ) ;
407
- Overlap :: EqualOrDisjoint
408
- } else {
409
- // different promoteds - base case, disjoint
410
- debug ! ( "place_element_conflict: DISJOINT-PROMOTED" ) ;
411
- Overlap :: Disjoint
412
410
}
413
411
}
414
- (
415
- Place :: Base ( PlaceBase :: Local ( _) ) ,
416
- Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Promoted ( _) , .. } ) )
417
- ) |
418
- (
419
- Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Promoted ( _) , .. } ) ) ,
420
- Place :: Base ( PlaceBase :: Local ( _) )
421
- ) |
422
- (
423
- Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Promoted ( _) , .. } ) ) ,
424
- Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Static ( _) , .. } ) )
425
- ) |
426
- (
427
- Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Static ( _) , .. } ) ) ,
428
- Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Promoted ( _) , .. } ) )
429
- ) |
430
- (
431
- Place :: Base ( PlaceBase :: Local ( _) ) ,
432
- Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Static ( _) , .. } ) )
433
- ) |
434
- (
435
- Place :: Base ( PlaceBase :: Static ( box Static { kind : StaticKind :: Static ( _) , .. } ) ) ,
436
- Place :: Base ( PlaceBase :: Local ( _) )
437
- ) => {
412
+ ( Place :: Base ( PlaceBase :: Local ( _) ) , Place :: Base ( PlaceBase :: Static ( _) ) ) |
413
+ ( Place :: Base ( PlaceBase :: Static ( _) ) , Place :: Base ( PlaceBase :: Local ( _) ) ) => {
438
414
debug ! ( "place_element_conflict: DISJOINT-STATIC-LOCAL-PROMOTED" ) ;
439
415
Overlap :: Disjoint
440
416
}
0 commit comments