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

Do not spawn blacklisted_name lint in test context #7379

Merged
merged 1 commit into from
Jun 25, 2021

Conversation

popzxc
Copy link
Contributor

@popzxc popzxc commented Jun 19, 2021


fixed #7305

Please write a short comment explaining your change (or "none" for internal only changes)

changelog: blacklisted_name lint is not spawned in the test context anymore.

@rust-highfive
Copy link

r? @phansch

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jun 19, 2021
@flip1995
Copy link
Member

r? @flip1995 (reassigning since @phansch is taking a break)

@rust-highfive rust-highfive assigned flip1995 and unassigned phansch Jun 22, 2021
Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have some lints, that shouldn't trigger in test code. This is how we usually handle those situations:

When going into a test context, save this information in the lint struct:

fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
if is_test_module_or_function(item) {
self.test_modules_deep = self.test_modules_deep.saturating_add(1);
}

When leaving the test context:

fn check_item_post(&mut self, _: &LateContext<'_>, item: &Item<'_>) {
if is_test_module_or_function(item) {
self.test_modules_deep = self.test_modules_deep.saturating_sub(1);
}
}

clippy_lints/src/blacklisted_name.rs Outdated Show resolved Hide resolved
clippy_lints/src/blacklisted_name.rs Outdated Show resolved Hide resolved
@flip1995 flip1995 added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jun 22, 2021
clippy_utils/src/lib.rs Outdated Show resolved Hide resolved
tests/ui/blacklisted_name.rs Outdated Show resolved Hide resolved
Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM overall. One small thing left. Please squash the commits after fixing that.

tests/compile-test.rs Outdated Show resolved Hide resolved
Fix detecting of the 'test' attribute

Update UI test to actually check that warning is not triggered in the test code

Fix approach for detecting the test module

Add nested test case

Remove code duplication by extracting 'is_test_module_or_function' into 'clippy_utils'

Cleanup the code
@flip1995
Copy link
Member

@bors r+

Thanks!

@bors
Copy link
Contributor

bors commented Jun 25, 2021

📌 Commit 28d3873 has been approved by flip1995

@bors
Copy link
Contributor

bors commented Jun 25, 2021

⌛ Testing commit 28d3873 with merge 8d427b6...

@bors
Copy link
Contributor

bors commented Jun 25, 2021

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: flip1995
Pushing 8d427b6 to master...

@bors bors merged commit 8d427b6 into rust-lang:master Jun 25, 2021
@popzxc popzxc deleted the issue-7305 branch June 25, 2021 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

blacklisted_name lint should not run inside the test code
6 participants