11use rustc_data_structures:: fx:: FxHashSet ;
2- use rustc_index:: vec:: IndexVec ;
3- use rustc_data_structures:: sync:: Lrc ;
42
53use rustc:: ty:: query:: Providers ;
64use rustc:: ty:: { self , TyCtxt } ;
@@ -24,7 +22,6 @@ pub struct UnsafetyChecker<'a, 'tcx> {
2422 body : & ' a Body < ' tcx > ,
2523 const_context : bool ,
2624 min_const_fn : bool ,
27- source_scope_local_data : & ' a IndexVec < SourceScope , SourceScopeLocalData > ,
2825 violations : Vec < UnsafetyViolation > ,
2926 source_info : SourceInfo ,
3027 tcx : TyCtxt < ' tcx > ,
@@ -39,7 +36,6 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
3936 const_context : bool ,
4037 min_const_fn : bool ,
4138 body : & ' a Body < ' tcx > ,
42- source_scope_local_data : & ' a IndexVec < SourceScope , SourceScopeLocalData > ,
4339 tcx : TyCtxt < ' tcx > ,
4440 param_env : ty:: ParamEnv < ' tcx > ,
4541 ) -> Self {
@@ -51,7 +47,6 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
5147 body,
5248 const_context,
5349 min_const_fn,
54- source_scope_local_data,
5550 violations : vec ! [ ] ,
5651 source_info : SourceInfo {
5752 span : body. span ,
@@ -219,8 +214,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
219214 if context. is_borrow ( ) {
220215 if util:: is_disaligned ( self . tcx , self . body , self . param_env , place) {
221216 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 ;
224221 self . register_violations ( & [ UnsafetyViolation {
225222 source_info,
226223 description : Symbol :: intern ( "borrow of packed field" ) ,
@@ -346,7 +343,10 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
346343 fn register_violations ( & mut self ,
347344 violations : & [ UnsafetyViolation ] ,
348345 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 ;
350350 let within_unsafe = match safety {
351351 // `unsafe` blocks are required in safe code
352352 Safety :: Safe => {
@@ -516,17 +516,6 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: DefId) -> UnsafetyCheckResult
516516 // `mir_built` force this.
517517 let body = & tcx. mir_built ( def_id) . borrow ( ) ;
518518
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-
530519 let param_env = tcx. param_env ( def_id) ;
531520
532521 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
536525 hir:: BodyOwnerKind :: Const |
537526 hir:: BodyOwnerKind :: Static ( _) => ( true , false ) ,
538527 } ;
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) ;
542529 checker. visit_body ( body) ;
543530
544531 check_unused_unsafe ( tcx, def_id, & checker. used_unsafe , & mut checker. inherited_blocks ) ;
0 commit comments