@@ -143,7 +143,8 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
143143 if let Some ( tail) = block. expr
144144 && !is_lint_allowed ( cx, UNNECESSARY_SAFETY_COMMENT , tail. hir_id )
145145 && !tail. span . in_external_macro ( cx. tcx . sess . source_map ( ) )
146- && let HasSafetyComment :: Yes ( pos) = stmt_has_safety_comment ( cx, tail. span , tail. hir_id )
146+ && let HasSafetyComment :: Yes ( pos) =
147+ stmt_has_safety_comment ( cx, tail. span , tail. hir_id , self . accept_comment_above_attributes )
147148 && let Some ( help_span) = expr_has_unnecessary_safety_comment ( cx, tail, pos)
148149 {
149150 span_lint_and_then (
@@ -167,7 +168,8 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
167168 } ;
168169 if !is_lint_allowed ( cx, UNNECESSARY_SAFETY_COMMENT , stmt. hir_id )
169170 && !stmt. span . in_external_macro ( cx. tcx . sess . source_map ( ) )
170- && let HasSafetyComment :: Yes ( pos) = stmt_has_safety_comment ( cx, stmt. span , stmt. hir_id )
171+ && let HasSafetyComment :: Yes ( pos) =
172+ stmt_has_safety_comment ( cx, stmt. span , stmt. hir_id , self . accept_comment_above_attributes )
171173 && let Some ( help_span) = expr_has_unnecessary_safety_comment ( cx, expr, pos)
172174 {
173175 span_lint_and_then (
@@ -534,7 +536,12 @@ fn item_has_safety_comment(cx: &LateContext<'_>, item: &hir::Item<'_>) -> HasSaf
534536
535537/// Checks if the lines immediately preceding the item contain a safety comment.
536538#[ allow( clippy:: collapsible_match) ]
537- fn stmt_has_safety_comment ( cx : & LateContext < ' _ > , span : Span , hir_id : HirId ) -> HasSafetyComment {
539+ fn stmt_has_safety_comment (
540+ cx : & LateContext < ' _ > ,
541+ span : Span ,
542+ hir_id : HirId ,
543+ accept_comment_above_attributes : bool ,
544+ ) -> HasSafetyComment {
538545 match span_from_macro_expansion_has_safety_comment ( cx, span) {
539546 HasSafetyComment :: Maybe => ( ) ,
540547 has_safety_comment => return has_safety_comment,
@@ -549,6 +556,13 @@ fn stmt_has_safety_comment(cx: &LateContext<'_>, span: Span, hir_id: HirId) -> H
549556 _ => return HasSafetyComment :: Maybe ,
550557 } ;
551558
559+ // if span_with_attrs_has_safety_comment(cx, span, hir_id, accept_comment_above_attrib
560+ // }
561+ let mut span = span;
562+ if accept_comment_above_attributes {
563+ span = include_attrs_in_span ( cx, hir_id, span) ;
564+ }
565+
552566 let source_map = cx. sess ( ) . source_map ( ) ;
553567 if let Some ( comment_start) = comment_start
554568 && let Ok ( unsafe_line) = source_map. lookup_line ( span. lo ( ) )
0 commit comments