1
1
use rustc_data_structures:: fx:: FxHashSet ;
2
- use rustc_index:: vec:: IndexVec ;
3
- use rustc_data_structures:: sync:: Lrc ;
4
2
5
3
use rustc:: ty:: query:: Providers ;
6
4
use rustc:: ty:: { self , TyCtxt } ;
@@ -24,7 +22,6 @@ pub struct UnsafetyChecker<'a, 'tcx> {
24
22
body : & ' a Body < ' tcx > ,
25
23
const_context : bool ,
26
24
min_const_fn : bool ,
27
- source_scope_local_data : & ' a IndexVec < SourceScope , SourceScopeLocalData > ,
28
25
violations : Vec < UnsafetyViolation > ,
29
26
source_info : SourceInfo ,
30
27
tcx : TyCtxt < ' tcx > ,
@@ -39,7 +36,6 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
39
36
const_context : bool ,
40
37
min_const_fn : bool ,
41
38
body : & ' a Body < ' tcx > ,
42
- source_scope_local_data : & ' a IndexVec < SourceScope , SourceScopeLocalData > ,
43
39
tcx : TyCtxt < ' tcx > ,
44
40
param_env : ty:: ParamEnv < ' tcx > ,
45
41
) -> Self {
@@ -51,7 +47,6 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
51
47
body,
52
48
const_context,
53
49
min_const_fn,
54
- source_scope_local_data,
55
50
violations : vec ! [ ] ,
56
51
source_info : SourceInfo {
57
52
span : body. span ,
@@ -219,8 +214,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
219
214
if context. is_borrow ( ) {
220
215
if util:: is_disaligned ( self . tcx , self . body , self . param_env , place) {
221
216
let source_info = self . source_info ;
222
- let lint_root =
223
- self . source_scope_local_data [ source_info. scope ] . lint_root ;
217
+ let lint_root = self . body . source_scope_local_data [ source_info. scope ]
218
+ . as_ref ( )
219
+ . assert_crate_local ( )
220
+ . lint_root ;
224
221
self . register_violations ( & [ UnsafetyViolation {
225
222
source_info,
226
223
description : Symbol :: intern ( "borrow of packed field" ) ,
@@ -346,7 +343,10 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
346
343
fn register_violations ( & mut self ,
347
344
violations : & [ UnsafetyViolation ] ,
348
345
unsafe_blocks : & [ ( hir:: HirId , bool ) ] ) {
349
- let safety = self . source_scope_local_data [ self . source_info . scope ] . safety ;
346
+ let safety = self . body . source_scope_local_data [ self . source_info . scope ]
347
+ . as_ref ( )
348
+ . assert_crate_local ( )
349
+ . safety ;
350
350
let within_unsafe = match safety {
351
351
// `unsafe` blocks are required in safe code
352
352
Safety :: Safe => {
@@ -516,17 +516,6 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: DefId) -> UnsafetyCheckResult
516
516
// `mir_built` force this.
517
517
let body = & tcx. mir_built ( def_id) . borrow ( ) ;
518
518
519
- let source_scope_local_data = match body. source_scope_local_data {
520
- ClearCrossCrate :: Set ( ref data) => data,
521
- ClearCrossCrate :: Clear => {
522
- debug ! ( "unsafety_violations: {:?} - remote, skipping" , def_id) ;
523
- return UnsafetyCheckResult {
524
- violations : Lrc :: new ( [ ] ) ,
525
- unsafe_blocks : Lrc :: new ( [ ] )
526
- }
527
- }
528
- } ;
529
-
530
519
let param_env = tcx. param_env ( def_id) ;
531
520
532
521
let id = tcx. hir ( ) . as_local_hir_id ( def_id) . unwrap ( ) ;
@@ -536,9 +525,7 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: DefId) -> UnsafetyCheckResult
536
525
hir:: BodyOwnerKind :: Const |
537
526
hir:: BodyOwnerKind :: Static ( _) => ( true , false ) ,
538
527
} ;
539
- let mut checker = UnsafetyChecker :: new (
540
- const_context, min_const_fn,
541
- body, source_scope_local_data, tcx, param_env) ;
528
+ let mut checker = UnsafetyChecker :: new ( const_context, min_const_fn, body, tcx, param_env) ;
542
529
checker. visit_body ( body) ;
543
530
544
531
check_unused_unsafe ( tcx, def_id, & checker. used_unsafe , & mut checker. inherited_blocks ) ;
0 commit comments