Skip to content

Commit e2e6a02

Browse files
committed
Addressing reviewer comments
1 parent 520228b commit e2e6a02

File tree

6 files changed

+52
-5
lines changed

6 files changed

+52
-5
lines changed

book/src/lint_configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ Minimum chars an ident can have, anything below or equal to this will be linted.
696696

697697

698698
## `accept-comment-above-statement`
699-
Whether to accept a safety comment to be placed above the statement containing the `usafe` block
699+
Whether to accept a safety comment to be placed above the statement containing the `unsafe` block
700700

701701
**Default Value:** `false` (`bool`)
702702

clippy_lints/src/undocumented_unsafe_blocks.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,14 @@ fn get_body_search_span(cx: &LateContext<'_>) -> Option<Span> {
580580
for (_, node) in map.parent_iter(body.hir_id) {
581581
match node {
582582
Node::Expr(e) => span = e.span,
583-
Node::Block(_) | Node::Arm(_) | Node::Stmt(_) | Node::Local(_) => (),
583+
Node::Block(_)
584+
| Node::Arm(_)
585+
| Node::Stmt(_)
586+
| Node::Local(_)
587+
| Node::Item(hir::Item {
588+
kind: hir::ItemKind::Const(..) | ItemKind::Static(..),
589+
..
590+
}) => (),
584591
_ => break,
585592
}
586593
}

clippy_lints/src/utils/conf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ define_Conf! {
540540
(min_ident_chars_threshold: u64 = 1),
541541
/// Lint: UNDOCUMENTED_UNSAFE_BLOCKS.
542542
///
543-
/// Whether to accept a safety comment to be placed above the statement containing the `usafe` block
543+
/// Whether to accept a safety comment to be placed above the statement containing the `unsafe` block
544544
(accept_comment_above_statement: bool = false),
545545
}
546546

tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,20 @@ fn main() {
55
// Safety: A safety comment
66
let _some_variable_with_a_very_long_name_to_break_the_line =
77
unsafe { a_function_with_a_very_long_name_to_break_the_line() };
8+
9+
// Safety: Another safety comment
10+
const _SOME_CONST_WITH_A_VERY_LONG_NAME_TO_BREAK_THE_LINE: u32 =
11+
unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
12+
13+
// Safety: Yet another safety comment
14+
static _SOME_STATIC_WITH_A_VERY_LONG_NAME_TO_BREAK_THE_LINE: u32 =
15+
unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
816
}
917

1018
pub unsafe fn a_function_with_a_very_long_name_to_break_the_line() -> u32 {
1119
1
1220
}
21+
22+
pub const unsafe fn a_const_function_with_a_very_long_name_to_break_the_line() -> u32 {
23+
2
24+
}

tests/ui/undocumented_unsafe_blocks.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,10 +513,22 @@ pub unsafe fn a_function_with_a_very_long_name_to_break_the_line() -> u32 {
513513
1
514514
}
515515

516+
pub const unsafe fn a_const_function_with_a_very_long_name_to_break_the_line() -> u32 {
517+
2
518+
}
519+
516520
fn issue_10832() {
517521
// Safety: A safety comment. But it will warn anyways
518522
let _some_variable_with_a_very_long_name_to_break_the_line =
519523
unsafe { a_function_with_a_very_long_name_to_break_the_line() };
524+
525+
// Safety: Another safety comment. But it will warn anyways
526+
const _SOME_CONST_WITH_A_VERY_LONG_NAME_TO_BREAK_THE_LINE: u32 =
527+
unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
528+
529+
// Safety: Yet another safety comment. But it will warn anyways
530+
static _SOME_STATIC_WITH_A_VERY_LONG_NAME_TO_BREAK_THE_LINE: u32 =
531+
unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
520532
}
521533

522534
fn main() {}

tests/ui/undocumented_unsafe_blocks.stderr

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,28 @@ LL | let bar = unsafe {};
319319
= help: consider adding a safety comment on the preceding line
320320

321321
error: unsafe block missing a safety comment
322-
--> $DIR/undocumented_unsafe_blocks.rs:519:9
322+
--> $DIR/undocumented_unsafe_blocks.rs:523:9
323323
|
324324
LL | unsafe { a_function_with_a_very_long_name_to_break_the_line() };
325325
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
326326
|
327327
= help: consider adding a safety comment on the preceding line
328328

329-
error: aborting due to 37 previous errors
329+
error: unsafe block missing a safety comment
330+
--> $DIR/undocumented_unsafe_blocks.rs:527:9
331+
|
332+
LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
333+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
334+
|
335+
= help: consider adding a safety comment on the preceding line
336+
337+
error: unsafe block missing a safety comment
338+
--> $DIR/undocumented_unsafe_blocks.rs:531:9
339+
|
340+
LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
341+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
342+
|
343+
= help: consider adding a safety comment on the preceding line
344+
345+
error: aborting due to 39 previous errors
330346

0 commit comments

Comments
 (0)