Skip to content

Commit 491a30c

Browse files
committed
move lint to EarlyAttributes, change applicability, add cfg test
1 parent 87a6270 commit 491a30c

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

clippy_lints/src/attrs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ declare_clippy_lint! {
430430

431431
declare_lint_pass!(Attributes => [
432432
ALLOW_ATTRIBUTES_WITHOUT_REASON,
433-
SHOULD_PANIC_WITHOUT_REASON,
434433
INLINE_ALWAYS,
435434
DEPRECATED_SEMVER,
436435
USELESS_ATTRIBUTE,
@@ -744,6 +743,7 @@ impl_lint_pass!(EarlyAttributes => [
744743
EMPTY_LINE_AFTER_DOC_COMMENTS,
745744
NON_MINIMAL_CFG,
746745
MAYBE_MISUSED_CFG,
746+
SHOULD_PANIC_WITHOUT_REASON,
747747
]);
748748

749749
impl EarlyLintPass for EarlyAttributes {
@@ -821,7 +821,7 @@ fn check_should_panic_reason<'cx>(cx: &EarlyContext<'cx>, attr: &'cx Attribute)
821821

822822
if let AttrArgs::Delimited(args) = &normal_attr.item.args
823823
&& let mut tt_iter = args.tokens.trees()
824-
&& let Some(TokenTree::Token(Token { kind: TokenKind::Ident(sym::expected, _),.. }, _)) = tt_iter.next()
824+
&& let Some(TokenTree::Token(Token { kind: TokenKind::Ident(sym::expected, _), .. }, _)) = tt_iter.next()
825825
&& let Some(TokenTree::Token(Token { kind: TokenKind::Eq, .. }, _)) = tt_iter.next()
826826
&& let Some(TokenTree::Token(Token { kind: TokenKind::Literal(_), .. }, _)) = tt_iter.next()
827827
{
@@ -835,8 +835,8 @@ fn check_should_panic_reason<'cx>(cx: &EarlyContext<'cx>, attr: &'cx Attribute)
835835
attr.span,
836836
"#[should_panic] attribute without a reason",
837837
"consider specifying the expected panic",
838-
r#"#[should_panic(expected="<panic message>")]"#.into(),
839-
Applicability::Unspecified
838+
r#"#[should_panic(expected = /* panic message */)]"#.into(),
839+
Applicability::HasPlaceholders
840840
);
841841
}
842842
}

tests/ui/should_panic_without_reason.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ fn no_message() {}
1010
#[should_panic()]
1111
fn no_message2() {}
1212

13+
#[cfg(test)]
14+
#[test]
15+
#[should_panic]
16+
fn no_message_cfg_false() {}
17+
1318
#[should_panic = "message"]
1419
fn metastr() {}
1520

tests/ui/should_panic_without_reason.stderr

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: #[should_panic] attribute without a reason
22
--> $DIR/should_panic_without_reason.rs:7:1
33
|
44
LL | #[should_panic]
5-
| ^^^^^^^^^^^^^^^ help: consider specifying the expected panic: `#[should_panic(expected="<panic message>")]`
5+
| ^^^^^^^^^^^^^^^ help: consider specifying the expected panic: `#[should_panic(expected = /* panic message */)]`
66
|
77
note: the lint level is defined here
88
--> $DIR/should_panic_without_reason.rs:2:9
@@ -14,7 +14,13 @@ error: #[should_panic] attribute without a reason
1414
--> $DIR/should_panic_without_reason.rs:10:1
1515
|
1616
LL | #[should_panic()]
17-
| ^^^^^^^^^^^^^^^^^ help: consider specifying the expected panic: `#[should_panic(expected="<panic message>")]`
17+
| ^^^^^^^^^^^^^^^^^ help: consider specifying the expected panic: `#[should_panic(expected = /* panic message */)]`
1818

19-
error: aborting due to 2 previous errors
19+
error: #[should_panic] attribute without a reason
20+
--> $DIR/should_panic_without_reason.rs:15:1
21+
|
22+
LL | #[should_panic]
23+
| ^^^^^^^^^^^^^^^ help: consider specifying the expected panic: `#[should_panic(expected = /* panic message */)]`
24+
25+
error: aborting due to 3 previous errors
2026

0 commit comments

Comments
 (0)