@@ -4,7 +4,7 @@ use std::ops::Bound;
44
55use rustc_errors:: DiagArgValue ;
66use 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 } ;
88use rustc_middle:: middle:: codegen_fn_attrs:: TargetFeature ;
99use rustc_middle:: mir:: BorrowKind ;
1010use rustc_middle:: span_bug;
@@ -342,7 +342,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
342342 PatKind :: Leaf { subpatterns, .. } => {
343343 if let ty:: Adt ( adt_def, ..) = pat. ty . kind ( ) {
344344 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 ( ) {
346346 self . requires_unsafe ( pat. pattern . span , UseOfUnsafeField ) ;
347347 }
348348 }
@@ -367,7 +367,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
367367 PatKind :: Variant { adt_def, args : _, variant_index, subpatterns } => {
368368 for pat in subpatterns {
369369 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 ( ) {
371371 self . requires_unsafe ( pat. pattern . span , UseOfUnsafeField ) ;
372372 }
373373 }
@@ -479,7 +479,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
479479 return ; // don't visit the whole expression
480480 }
481481 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 ( ) {
483483 let func_id = if let ty:: FnDef ( func_id, _) = self . thir [ fun] . ty . kind ( ) {
484484 Some ( * func_id)
485485 } else {
@@ -623,7 +623,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
623623 ExprKind :: Field { lhs, variant_index, name } => {
624624 let lhs = & self . thir [ lhs] ;
625625 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 ( ) {
627627 self . requires_unsafe ( expr. span , UseOfUnsafeField ) ;
628628 } else if adt_def. is_union ( ) {
629629 if let Some ( assigned_ty) = self . assignment_info {
@@ -1112,11 +1112,7 @@ pub(crate) fn check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) {
11121112
11131113 let hir_id = tcx. local_def_id_to_hir_id ( def) ;
11141114 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 }
11201116 } ) ;
11211117 let body_target_features = & tcx. body_codegen_attrs ( def. to_def_id ( ) ) . target_features ;
11221118 let mut warnings = Vec :: new ( ) ;
0 commit comments