@@ -143,7 +143,8 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
143
143
if let Some ( tail) = block. expr
144
144
&& !is_lint_allowed ( cx, UNNECESSARY_SAFETY_COMMENT , tail. hir_id )
145
145
&& !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 )
147
148
&& let Some ( help_span) = expr_has_unnecessary_safety_comment ( cx, tail, pos)
148
149
{
149
150
span_lint_and_then (
@@ -167,7 +168,8 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
167
168
} ;
168
169
if !is_lint_allowed ( cx, UNNECESSARY_SAFETY_COMMENT , stmt. hir_id )
169
170
&& !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 )
171
173
&& let Some ( help_span) = expr_has_unnecessary_safety_comment ( cx, expr, pos)
172
174
{
173
175
span_lint_and_then (
@@ -534,7 +536,12 @@ fn item_has_safety_comment(cx: &LateContext<'_>, item: &hir::Item<'_>) -> HasSaf
534
536
535
537
/// Checks if the lines immediately preceding the item contain a safety comment.
536
538
#[ 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 {
538
545
match span_from_macro_expansion_has_safety_comment ( cx, span) {
539
546
HasSafetyComment :: Maybe => ( ) ,
540
547
has_safety_comment => return has_safety_comment,
@@ -549,6 +556,13 @@ fn stmt_has_safety_comment(cx: &LateContext<'_>, span: Span, hir_id: HirId) -> H
549
556
_ => return HasSafetyComment :: Maybe ,
550
557
} ;
551
558
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
+
552
566
let source_map = cx. sess ( ) . source_map ( ) ;
553
567
if let Some ( comment_start) = comment_start
554
568
&& let Ok ( unsafe_line) = source_map. lookup_line ( span. lo ( ) )
0 commit comments