Skip to content

Remove bar from blacklisted names #5712

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 3 commits into from
Jun 23, 2020
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
4 changes: 2 additions & 2 deletions clippy_lints/src/utils/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ macro_rules! define_Conf {

pub use self::helpers::Conf;
define_Conf! {
Copy link
Member

Choose a reason for hiding this comment

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

I would explain in the documentation why "bar" isn't in that list, as it's a well-known list and I wouldn't be surprised if someone raised the issue or opened a PR to readd it "because we forgot about it".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, I'll try reinforcing the situation in the comments. Thanks!

/// Lint: BLACKLISTED_NAME. The list of blacklisted names to lint about
(blacklisted_names, "blacklisted_names": Vec<String>, ["foo", "bar", "baz", "quux"].iter().map(ToString::to_string).collect()),
/// Lint: BLACKLISTED_NAME. The list of blacklisted names to lint about. NB: `bar` is not here since it has legitimate uses
(blacklisted_names, "blacklisted_names": Vec<String>, ["foo", "baz", "quux"].iter().map(ToString::to_string).collect()),
/// Lint: COGNITIVE_COMPLEXITY. The maximum cognitive complexity a function can have
(cognitive_complexity_threshold, "cognitive_complexity_threshold": u64, 25),
/// DEPRECATED LINT: CYCLOMATIC_COMPLEXITY. Use the Cognitive Complexity lint instead.
Expand Down
25 changes: 15 additions & 10 deletions tests/ui/blacklisted_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,34 @@ fn test(foo: ()) {}

fn main() {
let foo = 42;
let bar = 42;
let baz = 42;
let quux = 42;
// Unlike these others, `bar` is actually considered an acceptable name.
// Among many other legitimate uses, bar commonly refers to a period of time in music.
// See https://github.com/rust-lang/rust-clippy/issues/5225.
let bar = 42;

let barb = 42;
let barbaric = 42;
let food = 42;
let foodstuffs = 42;
let bazaar = 42;

match (42, Some(1337), Some(0)) {
(foo, Some(bar), baz @ Some(_)) => (),
(foo, Some(baz), quux @ Some(_)) => (),
_ => (),
}
}

fn issue_1647(mut foo: u8) {
let mut bar = 0;
if let Some(mut baz) = Some(42) {}
let mut baz = 0;
if let Some(mut quux) = Some(42) {}
}

fn issue_1647_ref() {
let ref bar = 0;
if let Some(ref baz) = Some(42) {}
let ref baz = 0;
if let Some(ref quux) = Some(42) {}
}

fn issue_1647_ref_mut() {
let ref mut bar = 0;
if let Some(ref mut baz) = Some(42) {}
let ref mut baz = 0;
if let Some(ref mut quux) = Some(42) {}
}
72 changes: 36 additions & 36 deletions tests/ui/blacklisted_name.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,77 +12,77 @@ error: use of a blacklisted/placeholder name `foo`
LL | let foo = 42;
| ^^^

error: use of a blacklisted/placeholder name `bar`
error: use of a blacklisted/placeholder name `baz`
--> $DIR/blacklisted_name.rs:15:9
|
LL | let bar = 42;
LL | let baz = 42;
| ^^^

error: use of a blacklisted/placeholder name `baz`
error: use of a blacklisted/placeholder name `quux`
--> $DIR/blacklisted_name.rs:16:9
|
LL | let baz = 42;
| ^^^
LL | let quux = 42;
| ^^^^

error: use of a blacklisted/placeholder name `foo`
--> $DIR/blacklisted_name.rs:22:10
--> $DIR/blacklisted_name.rs:27:10
|
LL | (foo, Some(bar), baz @ Some(_)) => (),
LL | (foo, Some(baz), quux @ Some(_)) => (),
| ^^^

error: use of a blacklisted/placeholder name `bar`
--> $DIR/blacklisted_name.rs:22:20
error: use of a blacklisted/placeholder name `baz`
--> $DIR/blacklisted_name.rs:27:20
|
LL | (foo, Some(bar), baz @ Some(_)) => (),
LL | (foo, Some(baz), quux @ Some(_)) => (),
| ^^^

error: use of a blacklisted/placeholder name `baz`
--> $DIR/blacklisted_name.rs:22:26
error: use of a blacklisted/placeholder name `quux`
--> $DIR/blacklisted_name.rs:27:26
|
LL | (foo, Some(bar), baz @ Some(_)) => (),
| ^^^
LL | (foo, Some(baz), quux @ Some(_)) => (),
| ^^^^

error: use of a blacklisted/placeholder name `foo`
--> $DIR/blacklisted_name.rs:27:19
--> $DIR/blacklisted_name.rs:32:19
|
LL | fn issue_1647(mut foo: u8) {
| ^^^

error: use of a blacklisted/placeholder name `bar`
--> $DIR/blacklisted_name.rs:28:13
error: use of a blacklisted/placeholder name `baz`
--> $DIR/blacklisted_name.rs:33:13
|
LL | let mut bar = 0;
LL | let mut baz = 0;
| ^^^

error: use of a blacklisted/placeholder name `baz`
--> $DIR/blacklisted_name.rs:29:21
error: use of a blacklisted/placeholder name `quux`
--> $DIR/blacklisted_name.rs:34:21
|
LL | if let Some(mut baz) = Some(42) {}
| ^^^
LL | if let Some(mut quux) = Some(42) {}
| ^^^^

error: use of a blacklisted/placeholder name `bar`
--> $DIR/blacklisted_name.rs:33:13
error: use of a blacklisted/placeholder name `baz`
--> $DIR/blacklisted_name.rs:38:13
|
LL | let ref bar = 0;
LL | let ref baz = 0;
| ^^^

error: use of a blacklisted/placeholder name `baz`
--> $DIR/blacklisted_name.rs:34:21
error: use of a blacklisted/placeholder name `quux`
--> $DIR/blacklisted_name.rs:39:21
|
LL | if let Some(ref baz) = Some(42) {}
| ^^^
LL | if let Some(ref quux) = Some(42) {}
| ^^^^

error: use of a blacklisted/placeholder name `bar`
--> $DIR/blacklisted_name.rs:38:17
error: use of a blacklisted/placeholder name `baz`
--> $DIR/blacklisted_name.rs:43:17
|
LL | let ref mut bar = 0;
LL | let ref mut baz = 0;
| ^^^

error: use of a blacklisted/placeholder name `baz`
--> $DIR/blacklisted_name.rs:39:25
error: use of a blacklisted/placeholder name `quux`
--> $DIR/blacklisted_name.rs:44:25
|
LL | if let Some(ref mut baz) = Some(42) {}
| ^^^
LL | if let Some(ref mut quux) = Some(42) {}
| ^^^^

error: aborting due to 14 previous errors