@@ -4,7 +4,7 @@ use std::ops::Bound;
4
4
5
5
use rustc_errors:: DiagArgValue ;
6
6
use rustc_hir:: def:: DefKind ;
7
- use rustc_hir:: { self as hir, BindingMode , ByRef , HirId , Mutability , Safety } ;
7
+ use rustc_hir:: { self as hir, BindingMode , ByRef , HirId , Mutability } ;
8
8
use rustc_middle:: middle:: codegen_fn_attrs:: TargetFeature ;
9
9
use rustc_middle:: mir:: BorrowKind ;
10
10
use rustc_middle:: span_bug;
@@ -342,7 +342,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
342
342
PatKind :: Leaf { subpatterns, .. } => {
343
343
if let ty:: Adt ( adt_def, ..) = pat. ty . kind ( ) {
344
344
for pat in subpatterns {
345
- if adt_def. non_enum_variant ( ) . fields [ pat. field ] . safety == Safety :: Unsafe {
345
+ if adt_def. non_enum_variant ( ) . fields [ pat. field ] . safety . is_unsafe ( ) {
346
346
self . requires_unsafe ( pat. pattern . span , UseOfUnsafeField ) ;
347
347
}
348
348
}
@@ -367,7 +367,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
367
367
PatKind :: Variant { adt_def, args : _, variant_index, subpatterns } => {
368
368
for pat in subpatterns {
369
369
let field = & pat. field ;
370
- if adt_def. variant ( * variant_index) . fields [ * field] . safety == Safety :: Unsafe {
370
+ if adt_def. variant ( * variant_index) . fields [ * field] . safety . is_unsafe ( ) {
371
371
self . requires_unsafe ( pat. pattern . span , UseOfUnsafeField ) ;
372
372
}
373
373
}
@@ -479,7 +479,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
479
479
return ; // don't visit the whole expression
480
480
}
481
481
ExprKind :: Call { fun, ty : _, args : _, from_hir_call : _, fn_span : _ } => {
482
- if self . thir [ fun] . ty . fn_sig ( self . tcx ) . safety ( ) == hir :: Safety :: Unsafe {
482
+ if self . thir [ fun] . ty . fn_sig ( self . tcx ) . safety ( ) . is_unsafe ( ) {
483
483
let func_id = if let ty:: FnDef ( func_id, _) = self . thir [ fun] . ty . kind ( ) {
484
484
Some ( * func_id)
485
485
} else {
@@ -623,7 +623,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
623
623
ExprKind :: Field { lhs, variant_index, name } => {
624
624
let lhs = & self . thir [ lhs] ;
625
625
if let ty:: Adt ( adt_def, _) = lhs. ty . kind ( ) {
626
- if adt_def. variant ( variant_index) . fields [ name] . safety == Safety :: Unsafe {
626
+ if adt_def. variant ( variant_index) . fields [ name] . safety . is_unsafe ( ) {
627
627
self . requires_unsafe ( expr. span , UseOfUnsafeField ) ;
628
628
} else if adt_def. is_union ( ) {
629
629
if let Some ( assigned_ty) = self . assignment_info {
@@ -1112,11 +1112,7 @@ pub(crate) fn check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) {
1112
1112
1113
1113
let hir_id = tcx. local_def_id_to_hir_id ( def) ;
1114
1114
let safety_context = tcx. hir ( ) . fn_sig_by_hir_id ( hir_id) . map_or ( SafetyContext :: Safe , |fn_sig| {
1115
- if fn_sig. header . safety == hir:: Safety :: Unsafe {
1116
- SafetyContext :: UnsafeFn
1117
- } else {
1118
- SafetyContext :: Safe
1119
- }
1115
+ if fn_sig. header . safety . is_unsafe ( ) { SafetyContext :: UnsafeFn } else { SafetyContext :: Safe }
1120
1116
} ) ;
1121
1117
let body_target_features = & tcx. body_codegen_attrs ( def. to_def_id ( ) ) . target_features ;
1122
1118
let mut warnings = Vec :: new ( ) ;
0 commit comments