Skip to content

Commit 7905130

Browse files
committed
Auto merge of #8138 - r00ster91:safety, r=giraffate
Fix `SAFETY` comment tag casing in undocumented_unsafe_blocks This changes the lint introduced in #7748 to suggest adding a `SAFETY` comment instead of a `Safety` comment. Searching for `// Safety:` in rust-lang/rust yields 67 results while `// SAFETY:` yields 1072. I think it's safe to say that this comment tag is written in upper case, just like `TODO`, `FIXME` and so on are. As such I would expect this lint to follow the official convention as well. Note that I intentionally introduced some casing diversity in `tests/ui/undocumented_unsafe_blocks.rs` to test more cases than just `Safety:`. changelog: Capitalize `SAFETY` comment in [`undocumented_unsafe_blocks`]
2 parents 1962ce0 + eba4413 commit 7905130

File tree

4 files changed

+38
-38
lines changed

4 files changed

+38
-38
lines changed

clippy_lints/src/undocumented_unsafe_blocks.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::borrow::Cow;
1515

1616
declare_clippy_lint! {
1717
/// ### What it does
18-
/// Checks for `unsafe` blocks without a `// Safety: ` comment
18+
/// Checks for `unsafe` blocks without a `// SAFETY: ` comment
1919
/// explaining why the unsafe operations performed inside
2020
/// the block are safe.
2121
///
@@ -36,7 +36,7 @@ declare_clippy_lint! {
3636
/// use std::ptr::NonNull;
3737
/// let a = &mut 42;
3838
///
39-
/// // Safety: references are guaranteed to be non-null.
39+
/// // SAFETY: references are guaranteed to be non-null.
4040
/// let ptr = unsafe { NonNull::new_unchecked(a) };
4141
/// ```
4242
#[clippy::version = "1.58.0"]
@@ -213,7 +213,7 @@ impl UndocumentedUnsafeBlocks {
213213
);
214214
} else {
215215
let block_indent = indent_of(cx, span);
216-
let suggestion = format!("// Safety: ...\n{}", snippet(cx, span, ".."));
216+
let suggestion = format!("// SAFETY: ...\n{}", snippet(cx, span, ".."));
217217

218218
span_lint_and_sugg(
219219
cx,

tests/ui/crashes/ice-7868.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | unsafe { 0 };
77
= note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings`
88
help: consider adding a safety comment
99
|
10-
LL ~ // Safety: ...
10+
LL ~ // SAFETY: ...
1111
LL ~ unsafe { 0 };
1212
|
1313

tests/ui/undocumented_unsafe_blocks.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
fn nested_local() {
66
let _ = {
77
let _ = {
8-
// Safety:
8+
// SAFETY:
99
let _ = unsafe {};
1010
};
1111
};
@@ -14,7 +14,7 @@ fn nested_local() {
1414
fn deep_nest() {
1515
let _ = {
1616
let _ = {
17-
// Safety:
17+
// SAFETY:
1818
let _ = unsafe {};
1919

2020
// Safety:
@@ -28,7 +28,7 @@ fn deep_nest() {
2828
// Safety:
2929
let _ = unsafe {};
3030

31-
// Safety:
31+
// SAFETY:
3232
unsafe {};
3333
};
3434
};
@@ -44,7 +44,7 @@ fn deep_nest() {
4444
unsafe {};
4545
};
4646

47-
// Safety:
47+
// SAFETY:
4848
unsafe {};
4949
}
5050

@@ -59,7 +59,7 @@ fn line_comment() {
5959
}
6060

6161
fn line_comment_newlines() {
62-
// Safety:
62+
// SAFETY:
6363

6464
unsafe {}
6565
}
@@ -84,7 +84,7 @@ fn block_comment() {
8484
}
8585

8686
fn block_comment_newlines() {
87-
/* Safety: */
87+
/* SAFETY: */
8888

8989
unsafe {}
9090
}
@@ -96,7 +96,7 @@ fn inline_block_comment() {
9696

9797
fn block_comment_with_extras() {
9898
/* This is a description
99-
* Safety:
99+
* SAFETY:
100100
*/
101101
unsafe {}
102102
}
@@ -122,7 +122,7 @@ fn buried_safety() {
122122
}
123123

124124
fn safety_with_prepended_text() {
125-
// This is a test. Safety:
125+
// This is a test. safety:
126126
unsafe {}
127127
}
128128

@@ -132,7 +132,7 @@ fn local_line_comment() {
132132
}
133133

134134
fn local_block_comment() {
135-
/* Safety: */
135+
/* SAFETY: */
136136
let _ = unsafe {};
137137
}
138138

@@ -142,18 +142,18 @@ fn comment_array() {
142142
}
143143

144144
fn comment_tuple() {
145-
// Safety:
145+
// sAFETY:
146146
let _ = (42, unsafe {}, "test", unsafe {});
147147
}
148148

149149
fn comment_unary() {
150-
// Safety:
150+
// SAFETY:
151151
let _ = *unsafe { &42 };
152152
}
153153

154154
#[allow(clippy::match_single_binding)]
155155
fn comment_match() {
156-
// Safety:
156+
// SAFETY:
157157
let _ = match unsafe {} {
158158
_ => {},
159159
};
@@ -177,7 +177,7 @@ fn comment_macro_call() {
177177
}
178178

179179
t!(
180-
// Safety:
180+
// SAFETY:
181181
unsafe {}
182182
);
183183
}
@@ -194,18 +194,18 @@ fn comment_macro_def() {
194194
}
195195

196196
fn non_ascii_comment() {
197-
// ॐ᧻໒ Safety: ௵∰
197+
// ॐ᧻໒ SaFeTy: ௵∰
198198
unsafe {};
199199
}
200200

201201
fn local_commented_block() {
202202
let _ =
203-
// Safety:
203+
// safety:
204204
unsafe {};
205205
}
206206

207207
fn local_nest() {
208-
// Safety:
208+
// safety:
209209
let _ = [(42, unsafe {}, unsafe {}), (52, unsafe {}, unsafe {})];
210210
}
211211

@@ -267,17 +267,17 @@ fn no_comment_macro_def() {
267267
}
268268

269269
fn trailing_comment() {
270-
unsafe {} // Safety:
270+
unsafe {} // SAFETY:
271271
}
272272

273273
fn internal_comment() {
274274
unsafe {
275-
// Safety:
275+
// SAFETY:
276276
}
277277
}
278278

279279
fn interference() {
280-
// Safety
280+
// SAFETY
281281

282282
let _ = 42;
283283

tests/ui/undocumented_unsafe_blocks.stderr

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | unsafe {}
77
= note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings`
88
help: consider adding a safety comment
99
|
10-
LL ~ // Safety: ...
10+
LL ~ // SAFETY: ...
1111
LL + unsafe {}
1212
|
1313

@@ -19,7 +19,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
1919
|
2020
help: consider adding a safety comment
2121
|
22-
LL ~ // Safety: ...
22+
LL ~ // SAFETY: ...
2323
LL + let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
2424
|
2525

@@ -31,7 +31,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {});
3131
|
3232
help: consider adding a safety comment
3333
|
34-
LL ~ // Safety: ...
34+
LL ~ // SAFETY: ...
3535
LL + let _ = (42, unsafe {}, "test", unsafe {});
3636
|
3737

@@ -43,7 +43,7 @@ LL | let _ = *unsafe { &42 };
4343
|
4444
help: consider adding a safety comment
4545
|
46-
LL ~ // Safety: ...
46+
LL ~ // SAFETY: ...
4747
LL + let _ = *unsafe { &42 };
4848
|
4949

@@ -55,7 +55,7 @@ LL | let _ = match unsafe {} {
5555
|
5656
help: consider adding a safety comment
5757
|
58-
LL ~ // Safety: ...
58+
LL ~ // SAFETY: ...
5959
LL + let _ = match unsafe {} {
6060
|
6161

@@ -67,7 +67,7 @@ LL | let _ = &unsafe {};
6767
|
6868
help: consider adding a safety comment
6969
|
70-
LL ~ // Safety: ...
70+
LL ~ // SAFETY: ...
7171
LL + let _ = &unsafe {};
7272
|
7373

@@ -79,7 +79,7 @@ LL | let _ = [unsafe {}; 5];
7979
|
8080
help: consider adding a safety comment
8181
|
82-
LL ~ // Safety: ...
82+
LL ~ // SAFETY: ...
8383
LL + let _ = [unsafe {}; 5];
8484
|
8585

@@ -91,7 +91,7 @@ LL | let _ = unsafe {};
9191
|
9292
help: consider adding a safety comment
9393
|
94-
LL ~ // Safety: ...
94+
LL ~ // SAFETY: ...
9595
LL + let _ = unsafe {};
9696
|
9797

@@ -103,7 +103,7 @@ LL | t!(unsafe {});
103103
|
104104
help: consider adding a safety comment
105105
|
106-
LL ~ t!(// Safety: ...
106+
LL ~ t!(// SAFETY: ...
107107
LL ~ unsafe {});
108108
|
109109

@@ -122,13 +122,13 @@ LL | t!();
122122
error: unsafe block missing a safety comment
123123
--> $DIR/undocumented_unsafe_blocks.rs:270:5
124124
|
125-
LL | unsafe {} // Safety:
125+
LL | unsafe {} // SAFETY:
126126
| ^^^^^^^^^
127127
|
128128
help: consider adding a safety comment
129129
|
130-
LL ~ // Safety: ...
131-
LL ~ unsafe {} // Safety:
130+
LL ~ // SAFETY: ...
131+
LL ~ unsafe {} // SAFETY:
132132
|
133133

134134
error: unsafe block missing a safety comment
@@ -139,7 +139,7 @@ LL | unsafe {
139139
|
140140
help: consider adding a safety comment
141141
|
142-
LL ~ // Safety: ...
142+
LL ~ // SAFETY: ...
143143
LL + unsafe {
144144
|
145145

@@ -151,7 +151,7 @@ LL | unsafe {};
151151
|
152152
help: consider adding a safety comment
153153
|
154-
LL ~ // Safety: ...
154+
LL ~ // SAFETY: ...
155155
LL ~ unsafe {};
156156
|
157157

@@ -163,7 +163,7 @@ LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) });
163163
|
164164
help: consider adding a safety comment
165165
|
166-
LL ~ println!("{}", // Safety: ...
166+
LL ~ println!("{}", // SAFETY: ...
167167
LL ~ unsafe { String::from_utf8_unchecked(vec![]) });
168168
|
169169

0 commit comments

Comments
 (0)