Skip to content

Commit 0ed8bdd

Browse files
committed
Use inner span in undocumented_unsafe_blocks
1 parent 710d697 commit 0ed8bdd

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
@@ -607,15 +607,33 @@ fn span_from_macro_expansion_has_safety_comment(cx: &LateContext<'_>, span: Span
607607

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

0 commit comments

Comments
 (0)