-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Identical arguments on assert macro family #6167
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
32fdb8f
Lint on identical variable used as args in `assert_eq!` macro call
ThibsG a3e0446
Extend to the `assert` macro family
ThibsG 121a047
Move linting of `assert` macros from early to late pass
ThibsG 71c29b5
Add iterator test case for `eq_op` lint
ThibsG 5a13217
Assert macro args extractor as a common function in higher
ThibsG 16b5f37
Split `eq_op` ui tests to avoid file limit error in CI
ThibsG File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#![warn(clippy::eq_op)] | ||
|
||
// lint also in macro definition | ||
macro_rules! assert_in_macro_def { | ||
() => { | ||
let a = 42; | ||
assert_eq!(a, a); | ||
assert_ne!(a, a); | ||
debug_assert_eq!(a, a); | ||
debug_assert_ne!(a, a); | ||
}; | ||
} | ||
|
||
// lint identical args in assert-like macro invocations (see #3574) | ||
fn main() { | ||
assert_in_macro_def!(); | ||
|
||
let a = 1; | ||
let b = 2; | ||
|
||
// lint identical args in `assert_eq!` | ||
assert_eq!(a, a); | ||
assert_eq!(a + 1, a + 1); | ||
// ok | ||
assert_eq!(a, b); | ||
assert_eq!(a, a + 1); | ||
assert_eq!(a + 1, b + 1); | ||
|
||
// lint identical args in `assert_ne!` | ||
assert_ne!(a, a); | ||
assert_ne!(a + 1, a + 1); | ||
// ok | ||
assert_ne!(a, b); | ||
assert_ne!(a, a + 1); | ||
assert_ne!(a + 1, b + 1); | ||
|
||
// lint identical args in `debug_assert_eq!` | ||
debug_assert_eq!(a, a); | ||
debug_assert_eq!(a + 1, a + 1); | ||
// ok | ||
debug_assert_eq!(a, b); | ||
debug_assert_eq!(a, a + 1); | ||
debug_assert_eq!(a + 1, b + 1); | ||
|
||
// lint identical args in `debug_assert_ne!` | ||
debug_assert_ne!(a, a); | ||
debug_assert_ne!(a + 1, a + 1); | ||
// ok | ||
debug_assert_ne!(a, b); | ||
debug_assert_ne!(a, a + 1); | ||
debug_assert_ne!(a + 1, b + 1); | ||
|
||
let my_vec = vec![1; 5]; | ||
let mut my_iter = my_vec.iter(); | ||
assert_ne!(my_iter.next(), my_iter.next()); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
error: identical args used in this `assert_eq!` macro call | ||
--> $DIR/eq_op_macros.rs:7:20 | ||
| | ||
LL | assert_eq!(a, a); | ||
| ^^^^ | ||
... | ||
LL | assert_in_macro_def!(); | ||
| ----------------------- in this macro invocation | ||
| | ||
= note: `-D clippy::eq-op` implied by `-D warnings` | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: identical args used in this `assert_ne!` macro call | ||
--> $DIR/eq_op_macros.rs:8:20 | ||
| | ||
LL | assert_ne!(a, a); | ||
| ^^^^ | ||
... | ||
LL | assert_in_macro_def!(); | ||
| ----------------------- in this macro invocation | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: identical args used in this `assert_eq!` macro call | ||
--> $DIR/eq_op_macros.rs:22:16 | ||
| | ||
LL | assert_eq!(a, a); | ||
| ^^^^ | ||
|
||
error: identical args used in this `assert_eq!` macro call | ||
--> $DIR/eq_op_macros.rs:23:16 | ||
| | ||
LL | assert_eq!(a + 1, a + 1); | ||
| ^^^^^^^^^^^^ | ||
|
||
error: identical args used in this `assert_ne!` macro call | ||
--> $DIR/eq_op_macros.rs:30:16 | ||
| | ||
LL | assert_ne!(a, a); | ||
| ^^^^ | ||
|
||
error: identical args used in this `assert_ne!` macro call | ||
--> $DIR/eq_op_macros.rs:31:16 | ||
| | ||
LL | assert_ne!(a + 1, a + 1); | ||
| ^^^^^^^^^^^^ | ||
|
||
error: identical args used in this `debug_assert_eq!` macro call | ||
--> $DIR/eq_op_macros.rs:9:26 | ||
| | ||
LL | debug_assert_eq!(a, a); | ||
| ^^^^ | ||
... | ||
LL | assert_in_macro_def!(); | ||
| ----------------------- in this macro invocation | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: identical args used in this `debug_assert_ne!` macro call | ||
--> $DIR/eq_op_macros.rs:10:26 | ||
| | ||
LL | debug_assert_ne!(a, a); | ||
| ^^^^ | ||
... | ||
LL | assert_in_macro_def!(); | ||
| ----------------------- in this macro invocation | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: identical args used in this `debug_assert_eq!` macro call | ||
--> $DIR/eq_op_macros.rs:38:22 | ||
| | ||
LL | debug_assert_eq!(a, a); | ||
| ^^^^ | ||
|
||
error: identical args used in this `debug_assert_eq!` macro call | ||
--> $DIR/eq_op_macros.rs:39:22 | ||
| | ||
LL | debug_assert_eq!(a + 1, a + 1); | ||
| ^^^^^^^^^^^^ | ||
|
||
error: identical args used in this `debug_assert_ne!` macro call | ||
--> $DIR/eq_op_macros.rs:46:22 | ||
| | ||
LL | debug_assert_ne!(a, a); | ||
| ^^^^ | ||
|
||
error: identical args used in this `debug_assert_ne!` macro call | ||
--> $DIR/eq_op_macros.rs:47:22 | ||
| | ||
LL | debug_assert_ne!(a + 1, a + 1); | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to 12 previous errors | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.