Skip to content

Commit 3879429

Browse files
committed
fix undocumented_unsafe_blocks FP in long assignment
1 parent a274d9b commit 3879429

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

clippy_lints/src/undocumented_unsafe_blocks.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,11 @@ fn block_parents_have_safety_comment(
350350
let (span, hir_id) = match cx.tcx.parent_hir_node(id) {
351351
Node::Expr(expr) => match cx.tcx.parent_hir_node(expr.hir_id) {
352352
Node::LetStmt(hir::LetStmt { span, hir_id, .. }) => (*span, *hir_id),
353-
353+
Node::Expr(hir::Expr {
354+
hir_id,
355+
kind: hir::ExprKind::Assign(_, _, span),
356+
..
357+
}) => (*span, *hir_id),
354358
node if let Some((span, hir_id)) = span_and_hid_of_item_alike_node(&node)
355359
&& is_const_or_static(&node) =>
356360
{
@@ -606,10 +610,9 @@ fn span_from_macro_expansion_has_safety_comment(cx: &LateContext<'_>, span: Span
606610

607611
fn get_body_search_span(cx: &LateContext<'_>) -> Option<Span> {
608612
let body = cx.enclosing_body?;
609-
let map = cx.tcx.hir();
610613
let mut maybe_mod_item = None;
611614

612-
for (_, parent_node) in map.parent_iter(body.hir_id) {
615+
for (_, parent_node) in cx.tcx.hir().parent_iter(body.hir_id) {
613616
match parent_node {
614617
Node::Crate(mod_) => return Some(mod_.spans.inner_span),
615618
Node::Item(hir::Item {

tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.default.stderr

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,5 @@ LL | const NO_SAFETY_IN_IMPL: i32 = unsafe { 1 };
342342
|
343343
= help: consider adding a safety comment on the preceding line
344344

345-
error: unsafe block missing a safety comment
346-
--> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:673:9
347-
|
348-
LL | unsafe { here_is_another_variable_with_long_name };
349-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
350-
|
351-
= help: consider adding a safety comment on the preceding line
352-
353-
error: aborting due to 40 previous errors
345+
error: aborting due to 39 previous errors
354346

tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,10 @@ fn issue_13024() {
668668
let mut just_a_simple_variable_with_a_very_long_name_that_has_seventy_eight_characters = 0;
669669
let here_is_another_variable_with_long_name = 100;
670670

671-
// SAFETY: good
671+
// SAFETY: fail ONLY if `accept-comment-above-statement = false`
672672
just_a_simple_variable_with_a_very_long_name_that_has_seventy_eight_characters =
673673
unsafe { here_is_another_variable_with_long_name };
674-
//~^ undocumented_unsafe_blocks
674+
//~[disabled]^ undocumented_unsafe_blocks
675675
}
676676

677677
fn main() {}

0 commit comments

Comments
 (0)