Skip to content

Commit 6eec4a3

Browse files
committed
remove unecessary code
and narrow search span when const/static items are in a mod block
1 parent 7721567 commit 6eec4a3

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

clippy_lints/src/undocumented_unsafe_blocks.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -618,29 +618,23 @@ fn get_body_search_span(cx: &LateContext<'_>) -> Option<Span> {
618618
let mut maybe_global_var = false;
619619
for (_, node) in map.parent_iter(body.hir_id) {
620620
match node {
621-
Node::Expr(e) => {
622-
span = e.span;
623-
// Note: setting this to `false` is to making sure a "in-function defined"
624-
// const/static variable not mistakenly processed as global variable,
625-
// since global var doesn't have an `Expr` parent as its parent???
626-
maybe_global_var = false;
627-
}
628-
Node::Block(_)
629-
| Node::Arm(_)
630-
| Node::Stmt(_)
631-
| Node::Local(_) => (),
632-
Node::Item(hir::Item { kind, span: item_span, .. }) => {
633-
if matches!(kind, hir::ItemKind::Const(..) | ItemKind::Static(..)) {
634-
maybe_global_var = true;
635-
} else if maybe_global_var && let hir::ItemKind::Mod(_) = kind {
636-
span = *item_span;
637-
} else {
638-
break;
639-
}
640-
}
621+
Node::Expr(e) => span = e.span,
622+
Node::Block(_) | Node::Arm(_) | Node::Stmt(_) | Node::Local(_) => (),
623+
Node::Item(hir::Item {
624+
kind: hir::ItemKind::Const(..) | ItemKind::Static(..),
625+
..
626+
}) => maybe_global_var = true,
627+
Node::Item(hir::Item {
628+
kind: hir::ItemKind::Mod(_),
629+
span: item_span,
630+
..
631+
}) => {
632+
span = *item_span;
633+
break;
634+
},
641635
Node::Crate(mod_) if maybe_global_var => {
642636
span = mod_.spans.inner_span;
643-
}
637+
},
644638
_ => break,
645639
}
646640
}

0 commit comments

Comments
 (0)