Skip to content

Commit a22ce2d

Browse files
committed
Remove HashSets from Conf
1 parent 182cd5f commit a22ce2d

File tree

8 files changed

+25
-27
lines changed

8 files changed

+25
-27
lines changed

book/src/lint_configuration.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ Allowed names below the minimum allowed characters. The value `".."` can be used
199199
the list to indicate, that the configured values should be appended to the default
200200
configuration of Clippy. By default, any configuration will replace the default value.
201201

202-
**Default Value:** `["j", "z", "i", "y", "n", "x", "w"]`
202+
**Default Value:** `["i", "j", "x", "y", "z", "w", "n"]`
203203

204204
---
205205
**Affected lints:**
@@ -455,7 +455,7 @@ default configuration of Clippy. By default, any configuration will replace the
455455
* `doc-valid-idents = ["ClipPy"]` would replace the default list with `["ClipPy"]`.
456456
* `doc-valid-idents = ["ClipPy", ".."]` would append `ClipPy` to the default list.
457457

458-
**Default Value:** `["TiB", "CoreGraphics", "CoffeeScript", "TeX", "Direct2D", "PiB", "DirectX", "NetBSD", "OAuth", "NaN", "OpenType", "WebGL2", "WebTransport", "JavaScript", "OpenSSL", "OpenSSH", "EiB", "PureScript", "OpenAL", "MiB", "WebAssembly", "MinGW", "CoreFoundation", "WebGPU", "ClojureScript", "CamelCase", "OpenDNS", "NaNs", "OpenMP", "GitLab", "KiB", "sRGB", "CoreText", "macOS", "TypeScript", "GiB", "OpenExr", "YCbCr", "OpenTelemetry", "OpenBSD", "FreeBSD", "GPLv2", "PostScript", "WebP", "LaTeX", "TensorFlow", "AccessKit", "TrueType", "OpenStreetMap", "OpenGL", "DevOps", "OCaml", "WebRTC", "WebGL", "BibLaTeX", "GitHub", "GraphQL", "iOS", "Direct3D", "BibTeX", "DirectWrite", "GPLv3", "IPv6", "WebSocket", "IPv4", "ECMAScript"]`
458+
**Default Value:** `["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "AccessKit", "CoreFoundation", "CoreGraphics", "CoreText", "DevOps", "Direct2D", "Direct3D", "DirectWrite", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "ClojureScript", "CoffeeScript", "JavaScript", "PostScript", "PureScript", "TypeScript", "WebAssembly", "NaN", "NaNs", "OAuth", "GraphQL", "OCaml", "OpenAL", "OpenDNS", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenTelemetry", "OpenType", "WebGL", "WebGL2", "WebGPU", "WebRTC", "WebSocket", "WebTransport", "WebP", "OpenExr", "YCbCr", "sRGB", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "NetBSD", "OpenBSD", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase"]`
459459

460460
---
461461
**Affected lints:**

clippy_config/src/conf.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::msrvs::Msrv;
22
use crate::types::{DisallowedPath, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour, Rename};
33
use crate::ClippyConfiguration;
4-
use rustc_data_structures::fx::FxHashSet;
54
use rustc_errors::Applicability;
65
use rustc_session::Session;
76
use rustc_span::edit_distance::edit_distance;
@@ -218,7 +217,7 @@ macro_rules! define_Conf {
218217
define_Conf! {
219218
/// Which crates to allow absolute paths from
220219
#[lints(absolute_paths)]
221-
absolute_paths_allowed_crates: FxHashSet<String> = FxHashSet::default(),
220+
absolute_paths_allowed_crates: Vec<String> = Vec::new(),
222221
/// The maximum number of segments a path can have before being linted, anything above this will
223222
/// be linted.
224223
#[lints(absolute_paths)]
@@ -280,12 +279,12 @@ define_Conf! {
280279
allowed_dotfiles: Vec<String> = Vec::default(),
281280
/// A list of crate names to allow duplicates of
282281
#[lints(multiple_crate_versions)]
283-
allowed_duplicate_crates: FxHashSet<String> = FxHashSet::default(),
282+
allowed_duplicate_crates: Vec<String> = Vec::new(),
284283
/// Allowed names below the minimum allowed characters. The value `".."` can be used as part of
285284
/// the list to indicate, that the configured values should be appended to the default
286285
/// configuration of Clippy. By default, any configuration will replace the default value.
287286
#[lints(min_ident_chars)]
288-
allowed_idents_below_min_chars: FxHashSet<String> =
287+
allowed_idents_below_min_chars: Vec<String> =
289288
DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS.iter().map(ToString::to_string).collect(),
290289
/// List of prefixes to allow when determining whether an item's name ends with the module's name.
291290
/// If the rest of an item's name is an allowed prefix (e.g. item `ToFoo` or `to_foo` in module `foo`),
@@ -323,7 +322,7 @@ define_Conf! {
323322
/// 2. Paths with any segment that containing the word 'prelude'
324323
/// are already allowed by default.
325324
#[lints(wildcard_imports)]
326-
allowed_wildcard_imports: FxHashSet<String> = FxHashSet::default(),
325+
allowed_wildcard_imports: Vec<String> = Vec::new(),
327326
/// Suppress checking of the passed type names in all types of operations.
328327
///
329328
/// If a specific operation is desired, consider using `arithmetic_side_effects_allowed_binary` or `arithmetic_side_effects_allowed_unary` instead.
@@ -355,7 +354,7 @@ define_Conf! {
355354
/// arithmetic-side-effects-allowed-binary = [["SomeType" , "f32"], ["AnotherType", "*"]]
356355
/// ```
357356
#[lints(arithmetic_side_effects)]
358-
arithmetic_side_effects_allowed_binary: Vec<[String; 2]> = <_>::default(),
357+
arithmetic_side_effects_allowed_binary: Vec<(String, String)> = <_>::default(),
359358
/// Suppress checking of the passed type names in unary operations like "negation" (`-`).
360359
///
361360
/// #### Example
@@ -431,7 +430,7 @@ define_Conf! {
431430
/// * `doc-valid-idents = ["ClipPy"]` would replace the default list with `["ClipPy"]`.
432431
/// * `doc-valid-idents = ["ClipPy", ".."]` would append `ClipPy` to the default list.
433432
#[lints(doc_markdown)]
434-
doc_valid_idents: FxHashSet<String> = DEFAULT_DOC_VALID_IDENTS.iter().map(ToString::to_string).collect(),
433+
doc_valid_idents: Vec<String> = DEFAULT_DOC_VALID_IDENTS.iter().map(ToString::to_string).collect(),
435434
/// Whether to apply the raw pointer heuristic to determine if a type is `Send`.
436435
#[lints(non_send_fields_in_send_ty)]
437436
enable_raw_pointer_heuristic_for_send: bool = true,
@@ -706,12 +705,12 @@ fn deserialize(file: &SourceFile) -> TryConf {
706705
DEFAULT_ALLOWED_TRAITS_WITH_RENAMED_PARAMS,
707706
);
708707
// TODO: THIS SHOULD BE TESTED, this comment will be gone soon
709-
if conf.conf.allowed_idents_below_min_chars.contains("..") {
708+
if conf.conf.allowed_idents_below_min_chars.iter().any(|e| e == "..") {
710709
conf.conf
711710
.allowed_idents_below_min_chars
712711
.extend(DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS.iter().map(ToString::to_string));
713712
}
714-
if conf.conf.doc_valid_idents.contains("..") {
713+
if conf.conf.doc_valid_idents.iter().any(|e| e == "..") {
715714
conf.conf
716715
.doc_valid_idents
717716
.extend(DEFAULT_DOC_VALID_IDENTS.iter().map(ToString::to_string));
@@ -890,14 +889,14 @@ fn calculate_dimensions(fields: &[&str]) -> (usize, Vec<usize>) {
890889

891890
#[cfg(test)]
892891
mod tests {
893-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
894892
use serde::de::IgnoredAny;
893+
use std::collections::{HashMap, HashSet};
895894
use std::fs;
896895
use walkdir::WalkDir;
897896

898897
#[test]
899898
fn configs_are_tested() {
900-
let mut names: FxHashSet<String> = crate::get_configuration_metadata()
899+
let mut names: HashSet<String> = crate::get_configuration_metadata()
901900
.into_iter()
902901
.map(|meta| meta.name.replace('_', "-"))
903902
.collect();
@@ -910,7 +909,7 @@ mod tests {
910909
for entry in toml_files {
911910
let file = fs::read_to_string(entry.path()).unwrap();
912911
#[allow(clippy::zero_sized_map_values)]
913-
if let Ok(map) = toml::from_str::<FxHashMap<String, IgnoredAny>>(&file) {
912+
if let Ok(map) = toml::from_str::<HashMap<String, IgnoredAny>>(&file) {
914913
for name in map.keys() {
915914
names.remove(name.as_str());
916915
}

clippy_config/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
extern crate rustc_ast;
1717
extern crate rustc_attr;
18-
extern crate rustc_data_structures;
1918
#[allow(unused_extern_crates)]
2019
extern crate rustc_driver;
2120
extern crate rustc_errors;

clippy_lints/src/cargo/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ declare_clippy_lint! {
205205
}
206206

207207
pub struct Cargo {
208-
allowed_duplicate_crates: &'static FxHashSet<String>,
208+
allowed_duplicate_crates: FxHashSet<String>,
209209
ignore_publish: bool,
210210
}
211211

@@ -221,7 +221,7 @@ impl_lint_pass!(Cargo => [
221221
impl Cargo {
222222
pub fn new(conf: &'static Conf) -> Self {
223223
Self {
224-
allowed_duplicate_crates: &conf.allowed_duplicate_crates,
224+
allowed_duplicate_crates: conf.allowed_duplicate_crates.iter().cloned().collect(),
225225
ignore_publish: conf.cargo_ignore_publish,
226226
}
227227
}
@@ -263,7 +263,7 @@ impl LateLintPass<'_> for Cargo {
263263
{
264264
match MetadataCommand::new().exec() {
265265
Ok(metadata) => {
266-
multiple_crate_versions::check(cx, &metadata, self.allowed_duplicate_crates);
266+
multiple_crate_versions::check(cx, &metadata, &self.allowed_duplicate_crates);
267267
},
268268
Err(e) => {
269269
for lint in WITH_DEPS_LINTS {

clippy_lints/src/doc/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -423,14 +423,14 @@ declare_clippy_lint! {
423423
}
424424

425425
pub struct Documentation {
426-
valid_idents: &'static FxHashSet<String>,
426+
valid_idents: FxHashSet<String>,
427427
check_private_items: bool,
428428
}
429429

430430
impl Documentation {
431431
pub fn new(conf: &'static Conf) -> Self {
432432
Self {
433-
valid_idents: &conf.doc_valid_idents,
433+
valid_idents: conf.doc_valid_idents.iter().cloned().collect(),
434434
check_private_items: conf.check_private_items,
435435
}
436436
}
@@ -452,7 +452,7 @@ impl_lint_pass!(Documentation => [
452452

453453
impl<'tcx> LateLintPass<'tcx> for Documentation {
454454
fn check_attributes(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) {
455-
let Some(headers) = check_attrs(cx, self.valid_idents, attrs) else {
455+
let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else {
456456
return;
457457
};
458458

clippy_lints/src/min_ident_chars.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ declare_clippy_lint! {
4141
impl_lint_pass!(MinIdentChars => [MIN_IDENT_CHARS]);
4242

4343
pub struct MinIdentChars {
44-
allowed_idents_below_min_chars: &'static FxHashSet<String>,
44+
allowed_idents_below_min_chars: FxHashSet<String>,
4545
min_ident_chars_threshold: u64,
4646
}
4747

4848
impl MinIdentChars {
4949
pub fn new(conf: &'static Conf) -> Self {
5050
Self {
51-
allowed_idents_below_min_chars: &conf.allowed_idents_below_min_chars,
51+
allowed_idents_below_min_chars: conf.allowed_idents_below_min_chars.iter().cloned().collect(),
5252
min_ident_chars_threshold: conf.min_ident_chars_threshold,
5353
}
5454
}

clippy_lints/src/operators/arithmetic_side_effects.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl ArithmeticSideEffects {
3535
("f64", FxHashSet::from_iter(["f64"])),
3636
("std::string::String", FxHashSet::from_iter(["str"])),
3737
]);
38-
for [lhs, rhs] in &conf.arithmetic_side_effects_allowed_binary {
38+
for (lhs, rhs) in &conf.arithmetic_side_effects_allowed_binary {
3939
allowed_binary.entry(lhs).or_default().insert(rhs);
4040
}
4141
for s in &conf.arithmetic_side_effects_allowed {

clippy_lints/src/wildcard_imports.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ declare_clippy_lint! {
100100

101101
pub struct WildcardImports {
102102
warn_on_all: bool,
103-
allowed_segments: &'static FxHashSet<String>,
103+
allowed_segments: FxHashSet<String>,
104104
}
105105

106106
impl WildcardImports {
107107
pub fn new(conf: &'static Conf) -> Self {
108108
Self {
109109
warn_on_all: conf.warn_on_all_wildcard_imports,
110-
allowed_segments: &conf.allowed_wildcard_imports,
110+
allowed_segments: conf.allowed_wildcard_imports.iter().cloned().collect(),
111111
}
112112
}
113113
}
@@ -181,7 +181,7 @@ impl WildcardImports {
181181
fn check_exceptions(&self, cx: &LateContext<'_>, item: &Item<'_>, segments: &[PathSegment<'_>]) -> bool {
182182
item.span.from_expansion()
183183
|| is_prelude_import(segments)
184-
|| is_allowed_via_config(segments, self.allowed_segments)
184+
|| is_allowed_via_config(segments, &self.allowed_segments)
185185
|| (is_super_only_import(segments) && is_in_test(cx.tcx, item.hir_id()))
186186
}
187187
}

0 commit comments

Comments
 (0)