Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clarify message for non-obvious precedence #14043

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clippy_lints/src/precedence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl EarlyLintPass for Precedence {
cx,
PRECEDENCE,
expr.span,
"operator precedence can trip the unwary",
"operator precedence might not be obvious",
"consider parenthesizing your expression",
sugg,
appl,
Expand Down
22 changes: 11 additions & 11 deletions tests/ui/precedence.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: operator precedence can trip the unwary
error: operator precedence might not be obvious
--> tests/ui/precedence.rs:16:5
|
LL | 1 << 2 + 3;
Expand All @@ -7,61 +7,61 @@ LL | 1 << 2 + 3;
= note: `-D clippy::precedence` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::precedence)]`

error: operator precedence can trip the unwary
error: operator precedence might not be obvious
--> tests/ui/precedence.rs:17:5
|
LL | 1 + 2 << 3;
| ^^^^^^^^^^ help: consider parenthesizing your expression: `(1 + 2) << 3`

error: operator precedence can trip the unwary
error: operator precedence might not be obvious
--> tests/ui/precedence.rs:18:5
|
LL | 4 >> 1 + 1;
| ^^^^^^^^^^ help: consider parenthesizing your expression: `4 >> (1 + 1)`

error: operator precedence can trip the unwary
error: operator precedence might not be obvious
--> tests/ui/precedence.rs:19:5
|
LL | 1 + 3 >> 2;
| ^^^^^^^^^^ help: consider parenthesizing your expression: `(1 + 3) >> 2`

error: operator precedence can trip the unwary
error: operator precedence might not be obvious
--> tests/ui/precedence.rs:20:5
|
LL | 1 ^ 1 - 1;
| ^^^^^^^^^ help: consider parenthesizing your expression: `1 ^ (1 - 1)`

error: operator precedence can trip the unwary
error: operator precedence might not be obvious
--> tests/ui/precedence.rs:21:5
|
LL | 3 | 2 - 1;
| ^^^^^^^^^ help: consider parenthesizing your expression: `3 | (2 - 1)`

error: operator precedence can trip the unwary
error: operator precedence might not be obvious
--> tests/ui/precedence.rs:22:5
|
LL | 3 & 5 - 2;
| ^^^^^^^^^ help: consider parenthesizing your expression: `3 & (5 - 2)`

error: operator precedence can trip the unwary
error: operator precedence might not be obvious
--> tests/ui/precedence.rs:23:5
|
LL | 0x0F00 & 0x00F0 << 4;
| ^^^^^^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `0x0F00 & (0x00F0 << 4)`

error: operator precedence can trip the unwary
error: operator precedence might not be obvious
--> tests/ui/precedence.rs:24:5
|
LL | 0x0F00 & 0xF000 >> 4;
| ^^^^^^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `0x0F00 & (0xF000 >> 4)`

error: operator precedence can trip the unwary
error: operator precedence might not be obvious
--> tests/ui/precedence.rs:25:5
|
LL | 0x0F00 << 1 ^ 3;
| ^^^^^^^^^^^^^^^ help: consider parenthesizing your expression: `(0x0F00 << 1) ^ 3`

error: operator precedence can trip the unwary
error: operator precedence might not be obvious
--> tests/ui/precedence.rs:26:5
|
LL | 0x0F00 << 1 | 2;
Expand Down
Loading