Skip to content

Commit

Permalink
Fix SAFETY comment tag casing in undocumented_unsafe_blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
wooster0 committed Dec 17, 2021
1 parent a3bf9d1 commit eba4413
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
6 changes: 3 additions & 3 deletions clippy_lints/src/undocumented_unsafe_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::borrow::Cow;

declare_clippy_lint! {
/// ### What it does
/// Checks for `unsafe` blocks without a `// Safety: ` comment
/// Checks for `unsafe` blocks without a `// SAFETY: ` comment
/// explaining why the unsafe operations performed inside
/// the block are safe.
///
Expand All @@ -36,7 +36,7 @@ declare_clippy_lint! {
/// use std::ptr::NonNull;
/// let a = &mut 42;
///
/// // Safety: references are guaranteed to be non-null.
/// // SAFETY: references are guaranteed to be non-null.
/// let ptr = unsafe { NonNull::new_unchecked(a) };
/// ```
#[clippy::version = "1.58.0"]
Expand Down Expand Up @@ -213,7 +213,7 @@ impl UndocumentedUnsafeBlocks {
);
} else {
let block_indent = indent_of(cx, span);
let suggestion = format!("// Safety: ...\n{}", snippet(cx, span, ".."));
let suggestion = format!("// SAFETY: ...\n{}", snippet(cx, span, ".."));

span_lint_and_sugg(
cx,
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/crashes/ice-7868.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | unsafe { 0 };
= note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings`
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL ~ unsafe { 0 };
|

Expand Down
38 changes: 19 additions & 19 deletions tests/ui/undocumented_unsafe_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
fn nested_local() {
let _ = {
let _ = {
// Safety:
// SAFETY:
let _ = unsafe {};
};
};
Expand All @@ -14,7 +14,7 @@ fn nested_local() {
fn deep_nest() {
let _ = {
let _ = {
// Safety:
// SAFETY:
let _ = unsafe {};

// Safety:
Expand All @@ -28,7 +28,7 @@ fn deep_nest() {
// Safety:
let _ = unsafe {};

// Safety:
// SAFETY:
unsafe {};
};
};
Expand All @@ -44,7 +44,7 @@ fn deep_nest() {
unsafe {};
};

// Safety:
// SAFETY:
unsafe {};
}

Expand All @@ -59,7 +59,7 @@ fn line_comment() {
}

fn line_comment_newlines() {
// Safety:
// SAFETY:

unsafe {}
}
Expand All @@ -84,7 +84,7 @@ fn block_comment() {
}

fn block_comment_newlines() {
/* Safety: */
/* SAFETY: */

unsafe {}
}
Expand All @@ -96,7 +96,7 @@ fn inline_block_comment() {

fn block_comment_with_extras() {
/* This is a description
* Safety:
* SAFETY:
*/
unsafe {}
}
Expand All @@ -122,7 +122,7 @@ fn buried_safety() {
}

fn safety_with_prepended_text() {
// This is a test. Safety:
// This is a test. safety:
unsafe {}
}

Expand All @@ -132,7 +132,7 @@ fn local_line_comment() {
}

fn local_block_comment() {
/* Safety: */
/* SAFETY: */
let _ = unsafe {};
}

Expand All @@ -142,18 +142,18 @@ fn comment_array() {
}

fn comment_tuple() {
// Safety:
// sAFETY:
let _ = (42, unsafe {}, "test", unsafe {});
}

fn comment_unary() {
// Safety:
// SAFETY:
let _ = *unsafe { &42 };
}

#[allow(clippy::match_single_binding)]
fn comment_match() {
// Safety:
// SAFETY:
let _ = match unsafe {} {
_ => {},
};
Expand All @@ -177,7 +177,7 @@ fn comment_macro_call() {
}

t!(
// Safety:
// SAFETY:
unsafe {}
);
}
Expand All @@ -194,18 +194,18 @@ fn comment_macro_def() {
}

fn non_ascii_comment() {
// ॐ᧻໒ Safety: ௵∰
// ॐ᧻໒ SaFeTy: ௵∰
unsafe {};
}

fn local_commented_block() {
let _ =
// Safety:
// safety:
unsafe {};
}

fn local_nest() {
// Safety:
// safety:
let _ = [(42, unsafe {}, unsafe {}), (52, unsafe {}, unsafe {})];
}

Expand Down Expand Up @@ -267,17 +267,17 @@ fn no_comment_macro_def() {
}

fn trailing_comment() {
unsafe {} // Safety:
unsafe {} // SAFETY:
}

fn internal_comment() {
unsafe {
// Safety:
// SAFETY:
}
}

fn interference() {
// Safety
// SAFETY

let _ = 42;

Expand Down
30 changes: 15 additions & 15 deletions tests/ui/undocumented_unsafe_blocks.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | unsafe {}
= note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings`
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL + unsafe {}
|

Expand All @@ -19,7 +19,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
|
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL + let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
|

Expand All @@ -31,7 +31,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {});
|
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL + let _ = (42, unsafe {}, "test", unsafe {});
|

Expand All @@ -43,7 +43,7 @@ LL | let _ = *unsafe { &42 };
|
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL + let _ = *unsafe { &42 };
|

Expand All @@ -55,7 +55,7 @@ LL | let _ = match unsafe {} {
|
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL + let _ = match unsafe {} {
|

Expand All @@ -67,7 +67,7 @@ LL | let _ = &unsafe {};
|
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL + let _ = &unsafe {};
|

Expand All @@ -79,7 +79,7 @@ LL | let _ = [unsafe {}; 5];
|
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL + let _ = [unsafe {}; 5];
|

Expand All @@ -91,7 +91,7 @@ LL | let _ = unsafe {};
|
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL + let _ = unsafe {};
|

Expand All @@ -103,7 +103,7 @@ LL | t!(unsafe {});
|
help: consider adding a safety comment
|
LL ~ t!(// Safety: ...
LL ~ t!(// SAFETY: ...
LL ~ unsafe {});
|

Expand All @@ -122,13 +122,13 @@ LL | t!();
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:270:5
|
LL | unsafe {} // Safety:
LL | unsafe {} // SAFETY:
| ^^^^^^^^^
|
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ unsafe {} // Safety:
LL ~ // SAFETY: ...
LL ~ unsafe {} // SAFETY:
|

error: unsafe block missing a safety comment
Expand All @@ -139,7 +139,7 @@ LL | unsafe {
|
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL + unsafe {
|

Expand All @@ -151,7 +151,7 @@ LL | unsafe {};
|
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ // SAFETY: ...
LL ~ unsafe {};
|

Expand All @@ -163,7 +163,7 @@ LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) });
|
help: consider adding a safety comment
|
LL ~ println!("{}", // Safety: ...
LL ~ println!("{}", // SAFETY: ...
LL ~ unsafe { String::from_utf8_unchecked(vec![]) });
|

Expand Down

0 comments on commit eba4413

Please sign in to comment.