-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add items_after_test_module
lint
#10578
Conversation
r? @dswij (rustbot has picked a reviewer for you, use r? to override) |
☔ The latest upstream changes (presumably #10534) made this pull request unmergeable. Please resolve the merge conflicts. |
f9a006c
to
e7a6957
Compare
☔ The latest upstream changes (presumably #10543) made this pull request unmergeable. Please resolve the merge conflicts. |
e7a6957
to
38de6e6
Compare
tests/ui/items_after_test_modules/items_after_test_module.fixed
Outdated
Show resolved
Hide resolved
☔ The latest upstream changes (presumably #10601) made this pull request unmergeable. Please resolve the merge conflicts. |
Im thinking about removing suggestions. I could fix that case, but then if I put another item with an attribute over that one, it will break again. |
47c52dc
to
ad42ac9
Compare
☔ The latest upstream changes (presumably #10497) made this pull request unmergeable. Please resolve the merge conflicts. |
614e03e
to
4e91b2e
Compare
declare_lint_pass!(ItemsAfterTestModule => [ITEMS_AFTER_TEST_MODULE]); | ||
|
||
impl LateLintPass<'_> for ItemsAfterTestModule { | ||
fn check_mod(&mut self, cx: &LateContext<'_>, _: &Mod<'_>, _: HirId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some style nit/suggestion dump, feel free to ignore 😅
Maybe we can take out the if_chain
check, then do a skip_while
iterator on items
iter.
Yeah, that sounds a bit convoluted. I'd recommend leaving the suggestion for now, and maybe come back to it in the future |
4c0f747
to
0c6da4c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@blyxyas Sorry for the rather slow review.
Just a question, and should be good to merge afterwards :)
|
||
if_chain! { | ||
if was_test_mod_visited; | ||
if i == (items.len() - 3 /* Weird magic number (HIR-translation behaviour) */); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this ever cause a panic? i.e. will items.len()
< 3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use https://doc.rust-lang.org/std/primitive.usize.html#method.checked_sub if we can't guarantee that this won't cause an overflow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tested it with this code (The minimum amount of items that meats the requirements for the lint):
#[cfg(test)]
mod test {}
const U: usize = 0;
In an independent crate using this command: cargo dev lint ../<test dir>/ -- -- -W clippy::items_after_test_module --test
Even though the lint, well, lints. It doesn't overflow.
Thank you! @bors r+ |
💔 Test failed - checks-action_test |
@blyxyas Whoops, CI failed there. Can you help to take a look? |
I don't know how to fix this, it work on my machine and the normal Github CI test 'base'. Maybe retrying? |
@dswij Could you retry the bors tests? |
@bors retry |
💔 Test failed - checks-action_test |
??? It works on my machine, with a modern 64-bit Ubuntu-based OS, like the CI. I guess I'm going to ask on Zulip, because I can't replicate this CI |
0c6da4c
to
75363a6
Compare
76ed335
to
1ac8dc5
Compare
It's fixed now, the bug was caused because the test didn't change to the |
@bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Resolves task 3 of #10506, alongside 1 resolved at #10543 in an effort to help standarize a little bit more testing modules.
changelog:[
items_after_test_module
]: Added the lint.