@@ -15,7 +15,7 @@ use rustc::ty::maps::Providers;
15
15
use rustc:: ty:: { self , TyCtxt } ;
16
16
use rustc:: hir;
17
17
use rustc:: hir:: def_id:: DefId ;
18
- use rustc:: lint:: builtin:: { SAFE_EXTERN_STATICS , UNUSED_UNSAFE } ;
18
+ use rustc:: lint:: builtin:: { SAFE_EXTERN_STATICS , SAFE_PACKED_BORROWS , UNUSED_UNSAFE } ;
19
19
use rustc:: mir:: * ;
20
20
use rustc:: mir:: visit:: { LvalueContext , Visitor } ;
21
21
@@ -140,7 +140,14 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
140
140
location : Location ) {
141
141
if let LvalueContext :: Borrow { .. } = context {
142
142
if util:: is_disaligned ( self . tcx , self . mir , self . param_env , lvalue) {
143
- self . require_unsafe ( "borrow of packed field" )
143
+ let source_info = self . source_info ;
144
+ let lint_root =
145
+ self . visibility_scope_info [ source_info. scope ] . lint_root ;
146
+ self . register_violations ( & [ UnsafetyViolation {
147
+ source_info,
148
+ description : "borrow of packed field" ,
149
+ kind : UnsafetyViolationKind :: BorrowPacked ( lint_root)
150
+ } ] , & [ ] ) ;
144
151
}
145
152
}
146
153
@@ -203,7 +210,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
203
210
self . register_violations ( & [ UnsafetyViolation {
204
211
source_info,
205
212
description : "use of extern static" ,
206
- lint_node_id : Some ( lint_root)
213
+ kind : UnsafetyViolationKind :: ExternStatic ( lint_root)
207
214
} ] , & [ ] ) ;
208
215
}
209
216
}
@@ -218,7 +225,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
218
225
{
219
226
let source_info = self . source_info ;
220
227
self . register_violations ( & [ UnsafetyViolation {
221
- source_info, description, lint_node_id : None
228
+ source_info, description, kind : UnsafetyViolationKind :: General
222
229
} ] , & [ ] ) ;
223
230
}
224
231
@@ -380,21 +387,31 @@ pub fn check_unsafety<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
380
387
} = tcx. unsafety_check_result ( def_id) ;
381
388
382
389
for & UnsafetyViolation {
383
- source_info, description, lint_node_id
390
+ source_info, description, kind
384
391
} in violations. iter ( ) {
385
392
// Report an error.
386
- if let Some ( lint_node_id) = lint_node_id {
387
- tcx. lint_node ( SAFE_EXTERN_STATICS ,
388
- lint_node_id,
389
- source_info. span ,
390
- & format ! ( "{} requires unsafe function or \
391
- block (error E0133)", description) ) ;
392
- } else {
393
- struct_span_err ! (
394
- tcx. sess, source_info. span, E0133 ,
395
- "{} requires unsafe function or block" , description)
396
- . span_label ( source_info. span , description)
397
- . emit ( ) ;
393
+ match kind {
394
+ UnsafetyViolationKind :: General => {
395
+ struct_span_err ! (
396
+ tcx. sess, source_info. span, E0133 ,
397
+ "{} requires unsafe function or block" , description)
398
+ . span_label ( source_info. span , description)
399
+ . emit ( ) ;
400
+ }
401
+ UnsafetyViolationKind :: ExternStatic ( lint_node_id) => {
402
+ tcx. lint_node ( SAFE_EXTERN_STATICS ,
403
+ lint_node_id,
404
+ source_info. span ,
405
+ & format ! ( "{} requires unsafe function or \
406
+ block (error E0133)", description) ) ;
407
+ }
408
+ UnsafetyViolationKind :: BorrowPacked ( lint_node_id) => {
409
+ tcx. lint_node ( SAFE_PACKED_BORROWS ,
410
+ lint_node_id,
411
+ source_info. span ,
412
+ & format ! ( "{} requires unsafe function or \
413
+ block (error E0133)", description) ) ;
414
+ }
398
415
}
399
416
}
400
417
0 commit comments