-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Recognize common prefixes when checking for items with module name su…
…ffix Fixes #12544. - don't report an item name if it consists only of a prefix from `allowed-prefixes` list and a module name (e.g. `AsFoo` in module `foo`). - configured by `allowed-prefixes` config entry - prefixes allowed by default: [`to`, `from`, `into`, `as`, `try_into`, `try_from`] - update docs
- Loading branch information
Showing
13 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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 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
1 change: 1 addition & 0 deletions
1
tests/ui-toml/item_name_repetitions/allowed_prefixes/clippy.toml
This file contains 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 @@ | ||
allowed-prefixes = ["bar"] |
15 changes: 15 additions & 0 deletions
15
tests/ui-toml/item_name_repetitions/allowed_prefixes/item_name_repetitions.rs
This file contains 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,15 @@ | ||
#![warn(clippy::module_name_repetitions)] | ||
#![allow(dead_code)] | ||
|
||
mod foo { | ||
// #12544 - shouldn't warn if item name consists only of an allowed prefix and a module name. | ||
// In this test, allowed prefixes are configured to be ["bar"]. | ||
|
||
// this line should produce a warning: | ||
pub fn to_foo() {} | ||
|
||
// but this line shouldn't | ||
pub fn bar_foo() {} | ||
} | ||
|
||
fn main() {} |
11 changes: 11 additions & 0 deletions
11
tests/ui-toml/item_name_repetitions/allowed_prefixes/item_name_repetitions.stderr
This file contains 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,11 @@ | ||
error: item name ends with its containing module's name | ||
--> tests/ui-toml/item_name_repetitions/allowed_prefixes/item_name_repetitions.rs:9:12 | ||
| | ||
LL | pub fn to_foo() {} | ||
| ^^^^^^ | ||
| | ||
= note: `-D clippy::module-name-repetitions` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::module_name_repetitions)]` | ||
|
||
error: aborting due to 1 previous error | ||
|
1 change: 1 addition & 0 deletions
1
tests/ui-toml/item_name_repetitions/allowed_prefixes_extend/clippy.toml
This file contains 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 @@ | ||
allowed-prefixes = ["..", "bar"] |
21 changes: 21 additions & 0 deletions
21
tests/ui-toml/item_name_repetitions/allowed_prefixes_extend/item_name_repetitions.rs
This file contains 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,21 @@ | ||
#![warn(clippy::module_name_repetitions)] | ||
#![allow(dead_code)] | ||
|
||
mod foo { | ||
// #12544 - shouldn't warn if item name consists only of an allowed prefix and a module name. | ||
// In this test, allowed prefixes are configured to be all of the default prefixes and ["bar"]. | ||
|
||
// this line should produce a warning: | ||
pub fn something_foo() {} | ||
|
||
// but none of the following should: | ||
pub fn bar_foo() {} | ||
pub fn to_foo() {} | ||
pub fn as_foo() {} | ||
pub fn into_foo() {} | ||
pub fn from_foo() {} | ||
pub fn try_into_foo() {} | ||
pub fn try_from_foo() {} | ||
} | ||
|
||
fn main() {} |
11 changes: 11 additions & 0 deletions
11
tests/ui-toml/item_name_repetitions/allowed_prefixes_extend/item_name_repetitions.stderr
This file contains 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,11 @@ | ||
error: item name ends with its containing module's name | ||
--> tests/ui-toml/item_name_repetitions/allowed_prefixes_extend/item_name_repetitions.rs:9:12 | ||
| | ||
LL | pub fn something_foo() {} | ||
| ^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::module-name-repetitions` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::module_name_repetitions)]` | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains 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 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