diff options
| author | J-ZhengLi <lizheng135@huawei.com> | 2023-08-25 15:01:31 +0800 |
|---|---|---|
| committer | J-ZhengLi <lizheng135@huawei.com> | 2023-08-25 15:01:31 +0800 |
| commit | 6eec4a3720de954edb18985e6bdcb4a734dbeb0c (patch) | |
| tree | 58361f84b0573e9113f371e33a4f25d2ef4ff220 | |
| parent | 77215672e9c29ad32eadcd65509738e21b714e86 (diff) | |
| download | rust-6eec4a3720de954edb18985e6bdcb4a734dbeb0c.tar.gz rust-6eec4a3720de954edb18985e6bdcb4a734dbeb0c.zip | |
remove unecessary code
and narrow search span when const/static items are in a mod block
| -rw-r--r-- | clippy_lints/src/undocumented_unsafe_blocks.rs | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index 4ee817c0676..7649ce7fafb 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -618,29 +618,23 @@ fn get_body_search_span(cx: &LateContext<'_>) -> Option<Span> { let mut maybe_global_var = false; for (_, node) in map.parent_iter(body.hir_id) { match node { - Node::Expr(e) => { - span = e.span; - // Note: setting this to `false` is to making sure a "in-function defined" - // const/static variable not mistakenly processed as global variable, - // since global var doesn't have an `Expr` parent as its parent??? - maybe_global_var = false; - } - Node::Block(_) - | Node::Arm(_) - | Node::Stmt(_) - | Node::Local(_) => (), - Node::Item(hir::Item { kind, span: item_span, .. }) => { - if matches!(kind, hir::ItemKind::Const(..) | ItemKind::Static(..)) { - maybe_global_var = true; - } else if maybe_global_var && let hir::ItemKind::Mod(_) = kind { - span = *item_span; - } else { - break; - } - } + Node::Expr(e) => span = e.span, + Node::Block(_) | Node::Arm(_) | Node::Stmt(_) | Node::Local(_) => (), + Node::Item(hir::Item { + kind: hir::ItemKind::Const(..) | ItemKind::Static(..), + .. + }) => maybe_global_var = true, + Node::Item(hir::Item { + kind: hir::ItemKind::Mod(_), + span: item_span, + .. + }) => { + span = *item_span; + break; + }, Node::Crate(mod_) if maybe_global_var => { span = mod_.spans.inner_span; - } + }, _ => break, } } |
