@@ -5,9 +5,9 @@ use rustc_hir::def_id::{DefId, LocalDefId};
55use rustc_hir:: hir_id:: HirId ;
66use rustc_hir:: intravisit;
77use rustc_middle:: mir:: visit:: { MutatingUseContext , PlaceContext , Visitor } ;
8+ use rustc_middle:: mir:: * ;
89use rustc_middle:: ty:: query:: Providers ;
910use rustc_middle:: ty:: { self , TyCtxt } ;
10- use rustc_middle:: { lint, mir:: * } ;
1111use rustc_session:: lint:: builtin:: { UNSAFE_OP_IN_UNSAFE_FN , UNUSED_UNSAFE } ;
1212use rustc_session:: lint:: Level ;
1313
@@ -259,7 +259,7 @@ impl<'tcx> UnsafetyChecker<'_, 'tcx> {
259259 violations : impl IntoIterator < Item = & ' a UnsafetyViolation > ,
260260 new_used_unsafe_blocks : impl IntoIterator < Item = ( HirId , UsedUnsafeBlockData ) > ,
261261 ) {
262- use UsedUnsafeBlockData :: { AllAllowedInUnsafeFn , SomeDisallowedInUnsafeFn } ;
262+ use UsedUnsafeBlockData :: * ;
263263
264264 let update_entry = |this : & mut Self , hir_id, new_usage| {
265265 match this. used_unsafe_blocks . entry ( hir_id) {
@@ -299,15 +299,11 @@ impl<'tcx> UnsafetyChecker<'_, 'tcx> {
299299 }
300300 } ) ,
301301 Safety :: BuiltinUnsafe => { }
302- Safety :: ExplicitUnsafe ( hir_id) => violations. into_iter ( ) . for_each ( |violation | {
302+ Safety :: ExplicitUnsafe ( hir_id) => violations. into_iter ( ) . for_each ( |_violation | {
303303 update_entry (
304304 self ,
305305 hir_id,
306- match self . tcx . lint_level_at_node ( UNSAFE_OP_IN_UNSAFE_FN , violation. lint_root ) . 0
307- {
308- Level :: Allow => AllAllowedInUnsafeFn ( violation. lint_root ) ,
309- _ => SomeDisallowedInUnsafeFn ,
310- } ,
306+ SomeDisallowedInUnsafeFn ,
311307 )
312308 } ) ,
313309 } ;
@@ -522,6 +518,11 @@ fn unsafety_check_result<'tcx>(
522518}
523519
524520fn report_unused_unsafe ( tcx : TyCtxt < ' _ > , kind : UnusedUnsafe , id : HirId ) {
521+ if matches ! ( kind, UnusedUnsafe :: InUnsafeFn ( ..) ) {
522+ // We do *not* warn here, these unsafe blocks are actually required when
523+ // `unsafe_op_in_unsafe_fn` is warn or higher.
524+ return ;
525+ }
525526 let span = tcx. sess . source_map ( ) . guess_head_span ( tcx. hir ( ) . span ( id) ) ;
526527 tcx. struct_span_lint_hir ( UNUSED_UNSAFE , id, span, |lint| {
527528 let msg = "unnecessary `unsafe` block" ;
@@ -535,25 +536,7 @@ fn report_unused_unsafe(tcx: TyCtxt<'_>, kind: UnusedUnsafe, id: HirId) {
535536 "because it's nested under this `unsafe` block" ,
536537 ) ;
537538 }
538- UnusedUnsafe :: InUnsafeFn ( id, usage_lint_root) => {
539- db. span_label (
540- tcx. sess . source_map ( ) . guess_head_span ( tcx. hir ( ) . span ( id) ) ,
541- "because it's nested under this `unsafe` fn" ,
542- )
543- . note (
544- "this `unsafe` block does contain unsafe operations, \
545- but those are already allowed in an `unsafe fn`",
546- ) ;
547- let ( level, source) =
548- tcx. lint_level_at_node ( UNSAFE_OP_IN_UNSAFE_FN , usage_lint_root) ;
549- assert_eq ! ( level, Level :: Allow ) ;
550- lint:: explain_lint_level_source (
551- UNSAFE_OP_IN_UNSAFE_FN ,
552- Level :: Allow ,
553- source,
554- & mut db,
555- ) ;
556- }
539+ UnusedUnsafe :: InUnsafeFn ( _id, _usage_lint_root) => unreachable ! ( ) ,
557540 }
558541
559542 db. emit ( ) ;
0 commit comments