Skip to content

Commit a0ed687

Browse files
committed
Auto merge of rust-lang#8974 - Metaswitch:remove-blacklist-terminology, r=Manishearth
Remove "blacklist" terminology Picking up where rust-lang/rust-clippy#5896 left off, this renames the `blacklisted_name` lint to `disallowed_names` (pluralised for compliance with naming conventions). The old name is still available though is deprecated (both in the lint name, and in the TOML configuration file). This has been proposed/requested a few times, most recently in rust-lang/rust-clippy#7582 where `@xFrednet` suggested pinging the Clippy team when a PR was created hence... cc: `@rust-lang/clippy` changelog: [`disallowed_names`] lint replaces `blacklisted_name`
2 parents 53a09d4 + 56c9cc4 commit a0ed687

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+290
-269
lines changed

CHANGELOG.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ Released 2021-09-09
965965
[#7407](https://github.com/rust-lang/rust-clippy/pull/7407)
966966
* [`redundant_allocation`]: Now additionally supports the `Arc<>` type
967967
[#7308](https://github.com/rust-lang/rust-clippy/pull/7308)
968-
* [`blacklisted_name`]: Now allows blacklisted names in test code
968+
* [`disallowed_names`]: Now allows disallowed names in test code
969969
[#7379](https://github.com/rust-lang/rust-clippy/pull/7379)
970970
* [`redundant_closure`]: Suggests `&mut` for `FnMut`
971971
[#7437](https://github.com/rust-lang/rust-clippy/pull/7437)
@@ -2066,7 +2066,7 @@ Released 2020-08-27
20662066
[#5692](https://github.com/rust-lang/rust-clippy/pull/5692)
20672067
* [`if_same_then_else`]: Don't assume multiplication is always commutative
20682068
[#5702](https://github.com/rust-lang/rust-clippy/pull/5702)
2069-
* [`blacklisted_name`]: Remove `bar` from the default configuration
2069+
* [`disallowed_names`]: Remove `bar` from the default configuration
20702070
[#5712](https://github.com/rust-lang/rust-clippy/pull/5712)
20712071
* [`redundant_pattern_matching`]: Avoid suggesting non-`const fn` calls in const contexts
20722072
[#5724](https://github.com/rust-lang/rust-clippy/pull/5724)
@@ -3522,6 +3522,7 @@ Released 2018-09-13
35223522
[`derive_partial_eq_without_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_partial_eq_without_eq
35233523
[`disallowed_method`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_method
35243524
[`disallowed_methods`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_methods
3525+
[`disallowed_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names
35253526
[`disallowed_script_idents`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_script_idents
35263527
[`disallowed_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_type
35273528
[`disallowed_types`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_types

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ value` mapping e.g.
144144

145145
```toml
146146
avoid-breaking-exported-api = false
147-
blacklisted-names = ["toto", "tata", "titi"]
147+
disallowed-names = ["toto", "tata", "titi"]
148148
cognitive-complexity-threshold = 30
149149
```
150150

book/src/configuration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ basic `variable = value` mapping eg.
77

88
```toml
99
avoid-breaking-exported-api = false
10-
blacklisted-names = ["toto", "tata", "titi"]
10+
disallowed-names = ["toto", "tata", "titi"]
1111
cognitive-complexity-threshold = 30
1212
```
1313

clippy_lints/src/blacklisted_name.rs clippy_lints/src/disallowed_names.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_session::{declare_tool_lint, impl_lint_pass};
66

77
declare_clippy_lint! {
88
/// ### What it does
9-
/// Checks for usage of blacklisted names for variables, such
9+
/// Checks for usage of disallowed names for variables, such
1010
/// as `foo`.
1111
///
1212
/// ### Why is this bad?
@@ -18,21 +18,21 @@ declare_clippy_lint! {
1818
/// let foo = 3.14;
1919
/// ```
2020
#[clippy::version = "pre 1.29.0"]
21-
pub BLACKLISTED_NAME,
21+
pub DISALLOWED_NAMES,
2222
style,
23-
"usage of a blacklisted/placeholder name"
23+
"usage of a disallowed/placeholder name"
2424
}
2525

2626
#[derive(Clone, Debug)]
27-
pub struct BlacklistedName {
28-
blacklist: FxHashSet<String>,
27+
pub struct DisallowedNames {
28+
disallow: FxHashSet<String>,
2929
test_modules_deep: u32,
3030
}
3131

32-
impl BlacklistedName {
33-
pub fn new(blacklist: FxHashSet<String>) -> Self {
32+
impl DisallowedNames {
33+
pub fn new(disallow: FxHashSet<String>) -> Self {
3434
Self {
35-
blacklist,
35+
disallow,
3636
test_modules_deep: 0,
3737
}
3838
}
@@ -42,9 +42,9 @@ impl BlacklistedName {
4242
}
4343
}
4444

45-
impl_lint_pass!(BlacklistedName => [BLACKLISTED_NAME]);
45+
impl_lint_pass!(DisallowedNames => [DISALLOWED_NAMES]);
4646

47-
impl<'tcx> LateLintPass<'tcx> for BlacklistedName {
47+
impl<'tcx> LateLintPass<'tcx> for DisallowedNames {
4848
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
4949
if is_test_module_or_function(cx.tcx, item) {
5050
self.test_modules_deep = self.test_modules_deep.saturating_add(1);
@@ -58,12 +58,12 @@ impl<'tcx> LateLintPass<'tcx> for BlacklistedName {
5858
}
5959

6060
if let PatKind::Binding(.., ident, _) = pat.kind {
61-
if self.blacklist.contains(&ident.name.to_string()) {
61+
if self.disallow.contains(&ident.name.to_string()) {
6262
span_lint(
6363
cx,
64-
BLACKLISTED_NAME,
64+
DISALLOWED_NAMES,
6565
ident.span,
66-
&format!("use of a blacklisted/placeholder name `{}`", ident.name),
66+
&format!("use of a disallowed/placeholder name `{}`", ident.name),
6767
);
6868
}
6969
}

clippy_lints/src/lib.register_all.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
1616
LintId::of(await_holding_invalid::AWAIT_HOLDING_INVALID_TYPE),
1717
LintId::of(await_holding_invalid::AWAIT_HOLDING_LOCK),
1818
LintId::of(await_holding_invalid::AWAIT_HOLDING_REFCELL_REF),
19-
LintId::of(blacklisted_name::BLACKLISTED_NAME),
2019
LintId::of(blocks_in_if_conditions::BLOCKS_IN_IF_CONDITIONS),
2120
LintId::of(bool_assert_comparison::BOOL_ASSERT_COMPARISON),
2221
LintId::of(booleans::LOGIC_BUG),
@@ -47,6 +46,7 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
4746
LintId::of(derive::DERIVE_ORD_XOR_PARTIAL_ORD),
4847
LintId::of(derive::DERIVE_PARTIAL_EQ_WITHOUT_EQ),
4948
LintId::of(disallowed_methods::DISALLOWED_METHODS),
49+
LintId::of(disallowed_names::DISALLOWED_NAMES),
5050
LintId::of(disallowed_types::DISALLOWED_TYPES),
5151
LintId::of(doc::MISSING_SAFETY_DOC),
5252
LintId::of(doc::NEEDLESS_DOCTEST_MAIN),

clippy_lints/src/lib.register_lints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ store.register_lints(&[
5555
await_holding_invalid::AWAIT_HOLDING_INVALID_TYPE,
5656
await_holding_invalid::AWAIT_HOLDING_LOCK,
5757
await_holding_invalid::AWAIT_HOLDING_REFCELL_REF,
58-
blacklisted_name::BLACKLISTED_NAME,
5958
blocks_in_if_conditions::BLOCKS_IN_IF_CONDITIONS,
6059
bool_assert_comparison::BOOL_ASSERT_COMPARISON,
6160
booleans::LOGIC_BUG,
@@ -116,6 +115,7 @@ store.register_lints(&[
116115
derive::EXPL_IMPL_CLONE_ON_COPY,
117116
derive::UNSAFE_DERIVE_DESERIALIZE,
118117
disallowed_methods::DISALLOWED_METHODS,
118+
disallowed_names::DISALLOWED_NAMES,
119119
disallowed_script_idents::DISALLOWED_SCRIPT_IDENTS,
120120
disallowed_types::DISALLOWED_TYPES,
121121
doc::DOC_MARKDOWN,

clippy_lints/src/lib.register_style.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
store.register_group(true, "clippy::style", Some("clippy_style"), vec![
66
LintId::of(assertions_on_constants::ASSERTIONS_ON_CONSTANTS),
77
LintId::of(assertions_on_result_states::ASSERTIONS_ON_RESULT_STATES),
8-
LintId::of(blacklisted_name::BLACKLISTED_NAME),
98
LintId::of(blocks_in_if_conditions::BLOCKS_IN_IF_CONDITIONS),
109
LintId::of(bool_assert_comparison::BOOL_ASSERT_COMPARISON),
1110
LintId::of(casts::FN_TO_NUMERIC_CAST),
@@ -18,6 +17,7 @@ store.register_group(true, "clippy::style", Some("clippy_style"), vec![
1817
LintId::of(dereference::NEEDLESS_BORROW),
1918
LintId::of(derive::DERIVE_PARTIAL_EQ_WITHOUT_EQ),
2019
LintId::of(disallowed_methods::DISALLOWED_METHODS),
20+
LintId::of(disallowed_names::DISALLOWED_NAMES),
2121
LintId::of(disallowed_types::DISALLOWED_TYPES),
2222
LintId::of(doc::MISSING_SAFETY_DOC),
2323
LintId::of(doc::NEEDLESS_DOCTEST_MAIN),

clippy_lints/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ mod assertions_on_result_states;
177177
mod async_yields_async;
178178
mod attrs;
179179
mod await_holding_invalid;
180-
mod blacklisted_name;
181180
mod blocks_in_if_conditions;
182181
mod bool_assert_comparison;
183182
mod booleans;
@@ -205,6 +204,7 @@ mod dereference;
205204
mod derivable_impls;
206205
mod derive;
207206
mod disallowed_methods;
207+
mod disallowed_names;
208208
mod disallowed_script_idents;
209209
mod disallowed_types;
210210
mod doc;
@@ -683,8 +683,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
683683
store.register_late_pass(|| Box::new(swap::Swap));
684684
store.register_late_pass(|| Box::new(overflow_check_conditional::OverflowCheckConditional));
685685
store.register_late_pass(|| Box::new(new_without_default::NewWithoutDefault::default()));
686-
let blacklisted_names = conf.blacklisted_names.iter().cloned().collect::<FxHashSet<_>>();
687-
store.register_late_pass(move || Box::new(blacklisted_name::BlacklistedName::new(blacklisted_names.clone())));
686+
let disallowed_names = conf.disallowed_names.iter().cloned().collect::<FxHashSet<_>>();
687+
store.register_late_pass(move || Box::new(disallowed_names::DisallowedNames::new(disallowed_names.clone())));
688688
let too_many_arguments_threshold = conf.too_many_arguments_threshold;
689689
let too_many_lines_threshold = conf.too_many_lines_threshold;
690690
store.register_late_pass(move || {

clippy_lints/src/renamed_lints.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[
55
("clippy::block_in_if_condition_expr", "clippy::blocks_in_if_conditions"),
66
("clippy::block_in_if_condition_stmt", "clippy::blocks_in_if_conditions"),
77
("clippy::box_vec", "clippy::box_collection"),
8+
("clippy::blacklisted_name", "clippy::disallowed_names"),
89
("clippy::const_static_lifetime", "clippy::redundant_static_lifetimes"),
910
("clippy::cyclomatic_complexity", "clippy::cognitive_complexity"),
1011
("clippy::disallowed_method", "clippy::disallowed_methods"),

clippy_lints/src/utils/conf.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const DEFAULT_DOC_VALID_IDENTS: &[&str] = &[
3030
"MinGW",
3131
"CamelCase",
3232
];
33-
const DEFAULT_BLACKLISTED_NAMES: &[&str] = &["foo", "baz", "quux"];
33+
const DEFAULT_DISALLOWED_NAMES: &[&str] = &["foo", "baz", "quux"];
3434

3535
/// Holds information used by `MISSING_ENFORCED_IMPORT_RENAMES` lint.
3636
#[derive(Clone, Debug, Deserialize)]
@@ -159,7 +159,7 @@ macro_rules! define_Conf {
159159
"duplicate field `", stringify!($new_conf),
160160
"` (provided as `", stringify!($name), "`)"
161161
))),
162-
None => $new_conf = Some(value),
162+
None => $new_conf = $name.clone(),
163163
})?
164164
},
165165
}
@@ -217,12 +217,11 @@ define_Conf! {
217217
///
218218
/// The minimum rust version that the project supports
219219
(msrv: Option<String> = None),
220-
/// Lint: BLACKLISTED_NAME.
220+
/// DEPRECATED LINT: BLACKLISTED_NAME.
221221
///
222-
/// The list of blacklisted names to lint about. NB: `bar` is not here since it has legitimate uses. The value
223-
/// `".."` can be used as part of the list to indicate, that the configured values should be appended to the
224-
/// default configuration of Clippy. By default any configuraction will replace the default value.
225-
(blacklisted_names: Vec<String> = super::DEFAULT_BLACKLISTED_NAMES.iter().map(ToString::to_string).collect()),
222+
/// Use the Disallowed Names lint instead
223+
#[conf_deprecated("Please use `disallowed-names` instead", disallowed_names)]
224+
(blacklisted_names: Vec<String> = Vec::new()),
226225
/// Lint: COGNITIVE_COMPLEXITY.
227226
///
228227
/// The maximum cognitive complexity a function can have
@@ -232,6 +231,12 @@ define_Conf! {
232231
/// Use the Cognitive Complexity lint instead.
233232
#[conf_deprecated("Please use `cognitive-complexity-threshold` instead", cognitive_complexity_threshold)]
234233
(cyclomatic_complexity_threshold: u64 = 25),
234+
/// Lint: DISALLOWED_NAMES.
235+
///
236+
/// The list of disallowed names to lint about. NB: `bar` is not here since it has legitimate uses. The value
237+
/// `".."` can be used as part of the list to indicate, that the configured values should be appended to the
238+
/// default configuration of Clippy. By default any configuration will replace the default value.
239+
(disallowed_names: Vec<String> = super::DEFAULT_DISALLOWED_NAMES.iter().map(ToString::to_string).collect()),
235240
/// Lint: DOC_MARKDOWN.
236241
///
237242
/// The list of words this lint should not consider as identifiers needing ticks. The value
@@ -434,7 +439,7 @@ pub fn read(path: &Path) -> TryConf {
434439
match toml::from_str::<TryConf>(&content) {
435440
Ok(mut conf) => {
436441
extend_vec_if_indicator_present(&mut conf.conf.doc_valid_idents, DEFAULT_DOC_VALID_IDENTS);
437-
extend_vec_if_indicator_present(&mut conf.conf.blacklisted_names, DEFAULT_BLACKLISTED_NAMES);
442+
extend_vec_if_indicator_present(&mut conf.conf.disallowed_names, DEFAULT_DISALLOWED_NAMES);
438443

439444
conf
440445
},

clippy_lints/src/utils/internal_lints/metadata_collector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ impl<'hir> LateLintPass<'hir> for MetadataCollector {
619619
if_chain! {
620620
// item validation
621621
if is_lint_ref_type(cx, ty);
622-
// blacklist check
622+
// disallow check
623623
let lint_name = sym_to_string(item.ident.name).to_ascii_lowercase();
624624
if !BLACK_LISTED_LINTS.contains(&lint_name.as_str());
625625
// metadata extraction
@@ -644,7 +644,7 @@ impl<'hir> LateLintPass<'hir> for MetadataCollector {
644644

645645
if_chain! {
646646
if is_deprecated_lint(cx, ty);
647-
// blacklist check
647+
// disallow check
648648
let lint_name = sym_to_string(item.ident.name).to_ascii_lowercase();
649649
if !BLACK_LISTED_LINTS.contains(&lint_name.as_str());
650650
// Metadata the little we can get from a deprecated lint
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
blacklisted-names = 42
1+
disallowed-names = 42
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: error reading Clippy's configuration file `$DIR/clippy.toml`: invalid type: integer `42`, expected a sequence for key `blacklisted-names`
1+
error: error reading Clippy's configuration file `$DIR/clippy.toml`: invalid type: integer `42`, expected a sequence for key `disallowed-names`
22

33
error: aborting due to previous error
44

tests/ui-toml/blacklisted_names_append/blacklisted_names.stderr

-16
This file was deleted.

tests/ui-toml/blacklisted_names_append/clippy.toml

-1
This file was deleted.

tests/ui-toml/blacklisted_names_replace/blacklisted_names.stderr

-10
This file was deleted.

tests/ui-toml/blacklisted_names_replace/clippy.toml

-1
This file was deleted.

tests/ui-toml/conf_deprecated_key/clippy.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# that one is a warning
1+
# Expect errors from these deprecated configs
22
cyclomatic-complexity-threshold = 2
3+
blacklisted-names = [ "..", "wibble" ]
34

45
# that one is white-listed
56
[third-party]

tests/ui-toml/conf_deprecated_key/conf_deprecated_key.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
warning: error reading Clippy's configuration file `$DIR/clippy.toml`: deprecated field `cyclomatic-complexity-threshold`. Please use `cognitive-complexity-threshold` instead
22

3+
warning: error reading Clippy's configuration file `$DIR/clippy.toml`: deprecated field `blacklisted-names`. Please use `disallowed-names` instead
4+
35
error: the function has a cognitive complexity of (3/2)
46
--> $DIR/conf_deprecated_key.rs:4:4
57
|
@@ -9,5 +11,5 @@ LL | fn cognitive_complexity() {
911
= note: `-D clippy::cognitive-complexity` implied by `-D warnings`
1012
= help: you could split it up into multiple smaller functions
1113

12-
error: aborting due to previous error; 1 warning emitted
14+
error: aborting due to previous error; 2 warnings emitted
1315

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
disallowed-names = ["ducks", ".."]

tests/ui-toml/blacklisted_names_replace/blacklisted_names.rs tests/ui-toml/disallowed_names_append/disallowed_names.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#[warn(clippy::blacklisted_name)]
1+
#[warn(clippy::disallowed_names)]
22

33
fn main() {
44
// `foo` is part of the default configuration
55
let foo = "bar";
6-
// `ducks` was unrightfully blacklisted
6+
// `ducks` was unrightfully disallowed
77
let ducks = ["quack", "quack"];
88
// `fox` is okay
99
let fox = ["what", "does", "the", "fox", "say", "?"];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: use of a disallowed/placeholder name `foo`
2+
--> $DIR/disallowed_names.rs:5:9
3+
|
4+
LL | let foo = "bar";
5+
| ^^^
6+
|
7+
= note: `-D clippy::disallowed-names` implied by `-D warnings`
8+
9+
error: use of a disallowed/placeholder name `ducks`
10+
--> $DIR/disallowed_names.rs:7:9
11+
|
12+
LL | let ducks = ["quack", "quack"];
13+
| ^^^^^
14+
15+
error: aborting due to 2 previous errors
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
disallowed-names = ["ducks"]

tests/ui-toml/blacklisted_names_append/blacklisted_names.rs tests/ui-toml/disallowed_names_replace/disallowed_names.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#[warn(clippy::blacklisted_name)]
1+
#[warn(clippy::disallowed_names)]
22

33
fn main() {
44
// `foo` is part of the default configuration
55
let foo = "bar";
6-
// `ducks` was unrightfully blacklisted
6+
// `ducks` was unrightfully disallowed
77
let ducks = ["quack", "quack"];
88
// `fox` is okay
99
let fox = ["what", "does", "the", "fox", "say", "?"];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: use of a disallowed/placeholder name `ducks`
2+
--> $DIR/disallowed_names.rs:7:9
3+
|
4+
LL | let ducks = ["quack", "quack"];
5+
| ^^^^^
6+
|
7+
= note: `-D clippy::disallowed-names` implied by `-D warnings`
8+
9+
error: aborting due to previous error
10+

tests/ui-toml/toml_blacklist/clippy.toml

-1
This file was deleted.

0 commit comments

Comments
 (0)