Skip to content

Commit 322323a

Browse files
committed
Use inner span in undocumented_unsafe_blocks
1 parent 78e2f90 commit 322323a

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

clippy_lints/src/undocumented_unsafe_blocks.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,15 +606,33 @@ fn span_from_macro_expansion_has_safety_comment(cx: &LateContext<'_>, span: Span
606606

607607
fn get_body_search_span(cx: &LateContext<'_>) -> Option<Span> {
608608
let body = cx.enclosing_body?;
609-
for (_, parent_node) in cx.tcx.hir().parent_iter(body.hir_id) {
609+
let map = cx.tcx.hir();
610+
let mut maybe_mod_item = None;
611+
612+
for (_, parent_node) in map.parent_iter(body.hir_id) {
610613
match parent_node {
611614
Node::Crate(mod_) => return Some(mod_.spans.inner_span),
615+
Node::Item(hir::Item {
616+
kind: ItemKind::Mod(mod_),
617+
span,
618+
..
619+
}) => {
620+
return maybe_mod_item
621+
.and_then(|item| comment_start_before_item_in_mod(cx, mod_, *span, &item))
622+
.map(|comment_start| mod_.spans.inner_span.with_lo(comment_start))
623+
.or(Some(*span));
624+
},
612625
node if let Some((span, _)) = span_and_hid_of_item_alike_node(&node)
613626
&& !is_const_or_static(&node) =>
614627
{
615628
return Some(span);
616629
},
617-
_ => {},
630+
Node::Item(item) => {
631+
maybe_mod_item = Some(*item);
632+
},
633+
_ => {
634+
maybe_mod_item = None;
635+
},
618636
}
619637
}
620638
None

0 commit comments

Comments
 (0)