Remove HashSets from Conf

This commit is contained in:
Alex Macleod 2024-08-12 16:25:14 +00:00
parent 182cd5f278
commit a22ce2d005
8 changed files with 25 additions and 27 deletions

View File

@ -199,7 +199,7 @@ Allowed names below the minimum allowed characters. The value `".."` can be used
the list to indicate, that the configured values should be appended to the default the list to indicate, that the configured values should be appended to the default
configuration of Clippy. By default, any configuration will replace the default value. configuration of Clippy. By default, any configuration will replace the default value.
**Default Value:** `["j", "z", "i", "y", "n", "x", "w"]` **Default Value:** `["i", "j", "x", "y", "z", "w", "n"]`
--- ---
**Affected lints:** **Affected lints:**
@ -455,7 +455,7 @@ default configuration of Clippy. By default, any configuration will replace the
* `doc-valid-idents = ["ClipPy"]` would replace the default list with `["ClipPy"]`. * `doc-valid-idents = ["ClipPy"]` would replace the default list with `["ClipPy"]`.
* `doc-valid-idents = ["ClipPy", ".."]` would append `ClipPy` to the default list. * `doc-valid-idents = ["ClipPy", ".."]` would append `ClipPy` to the default list.
**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"]` **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"]`
--- ---
**Affected lints:** **Affected lints:**

View File

@ -1,7 +1,6 @@
use crate::msrvs::Msrv; use crate::msrvs::Msrv;
use crate::types::{DisallowedPath, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour, Rename}; use crate::types::{DisallowedPath, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour, Rename};
use crate::ClippyConfiguration; use crate::ClippyConfiguration;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_session::Session; use rustc_session::Session;
use rustc_span::edit_distance::edit_distance; use rustc_span::edit_distance::edit_distance;
@ -218,7 +217,7 @@ pub fn get_configuration_metadata() -> Vec<ClippyConfiguration> {
define_Conf! { define_Conf! {
/// Which crates to allow absolute paths from /// Which crates to allow absolute paths from
#[lints(absolute_paths)] #[lints(absolute_paths)]
absolute_paths_allowed_crates: FxHashSet<String> = FxHashSet::default(), absolute_paths_allowed_crates: Vec<String> = Vec::new(),
/// The maximum number of segments a path can have before being linted, anything above this will /// The maximum number of segments a path can have before being linted, anything above this will
/// be linted. /// be linted.
#[lints(absolute_paths)] #[lints(absolute_paths)]
@ -280,12 +279,12 @@ pub fn get_configuration_metadata() -> Vec<ClippyConfiguration> {
allowed_dotfiles: Vec<String> = Vec::default(), allowed_dotfiles: Vec<String> = Vec::default(),
/// A list of crate names to allow duplicates of /// A list of crate names to allow duplicates of
#[lints(multiple_crate_versions)] #[lints(multiple_crate_versions)]
allowed_duplicate_crates: FxHashSet<String> = FxHashSet::default(), allowed_duplicate_crates: Vec<String> = Vec::new(),
/// Allowed names below the minimum allowed characters. The value `".."` can be used as part of /// Allowed names below the minimum allowed characters. The value `".."` can be used as part of
/// the list to indicate, that the configured values should be appended to the default /// the list to indicate, that the configured values should be appended to the default
/// configuration of Clippy. By default, any configuration will replace the default value. /// configuration of Clippy. By default, any configuration will replace the default value.
#[lints(min_ident_chars)] #[lints(min_ident_chars)]
allowed_idents_below_min_chars: FxHashSet<String> = allowed_idents_below_min_chars: Vec<String> =
DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS.iter().map(ToString::to_string).collect(), DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS.iter().map(ToString::to_string).collect(),
/// List of prefixes to allow when determining whether an item's name ends with the module's name. /// List of prefixes to allow when determining whether an item's name ends with the module's name.
/// If the rest of an item's name is an allowed prefix (e.g. item `ToFoo` or `to_foo` in module `foo`), /// 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 @@ pub fn get_configuration_metadata() -> Vec<ClippyConfiguration> {
/// 2. Paths with any segment that containing the word 'prelude' /// 2. Paths with any segment that containing the word 'prelude'
/// are already allowed by default. /// are already allowed by default.
#[lints(wildcard_imports)] #[lints(wildcard_imports)]
allowed_wildcard_imports: FxHashSet<String> = FxHashSet::default(), allowed_wildcard_imports: Vec<String> = Vec::new(),
/// Suppress checking of the passed type names in all types of operations. /// Suppress checking of the passed type names in all types of operations.
/// ///
/// If a specific operation is desired, consider using `arithmetic_side_effects_allowed_binary` or `arithmetic_side_effects_allowed_unary` instead. /// If a specific operation is desired, consider using `arithmetic_side_effects_allowed_binary` or `arithmetic_side_effects_allowed_unary` instead.
@ -355,7 +354,7 @@ pub fn get_configuration_metadata() -> Vec<ClippyConfiguration> {
/// arithmetic-side-effects-allowed-binary = [["SomeType" , "f32"], ["AnotherType", "*"]] /// arithmetic-side-effects-allowed-binary = [["SomeType" , "f32"], ["AnotherType", "*"]]
/// ``` /// ```
#[lints(arithmetic_side_effects)] #[lints(arithmetic_side_effects)]
arithmetic_side_effects_allowed_binary: Vec<[String; 2]> = <_>::default(), arithmetic_side_effects_allowed_binary: Vec<(String, String)> = <_>::default(),
/// Suppress checking of the passed type names in unary operations like "negation" (`-`). /// Suppress checking of the passed type names in unary operations like "negation" (`-`).
/// ///
/// #### Example /// #### Example
@ -431,7 +430,7 @@ pub fn get_configuration_metadata() -> Vec<ClippyConfiguration> {
/// * `doc-valid-idents = ["ClipPy"]` would replace the default list with `["ClipPy"]`. /// * `doc-valid-idents = ["ClipPy"]` would replace the default list with `["ClipPy"]`.
/// * `doc-valid-idents = ["ClipPy", ".."]` would append `ClipPy` to the default list. /// * `doc-valid-idents = ["ClipPy", ".."]` would append `ClipPy` to the default list.
#[lints(doc_markdown)] #[lints(doc_markdown)]
doc_valid_idents: FxHashSet<String> = DEFAULT_DOC_VALID_IDENTS.iter().map(ToString::to_string).collect(), doc_valid_idents: Vec<String> = DEFAULT_DOC_VALID_IDENTS.iter().map(ToString::to_string).collect(),
/// Whether to apply the raw pointer heuristic to determine if a type is `Send`. /// Whether to apply the raw pointer heuristic to determine if a type is `Send`.
#[lints(non_send_fields_in_send_ty)] #[lints(non_send_fields_in_send_ty)]
enable_raw_pointer_heuristic_for_send: bool = true, enable_raw_pointer_heuristic_for_send: bool = true,
@ -706,12 +705,12 @@ fn deserialize(file: &SourceFile) -> TryConf {
DEFAULT_ALLOWED_TRAITS_WITH_RENAMED_PARAMS, DEFAULT_ALLOWED_TRAITS_WITH_RENAMED_PARAMS,
); );
// TODO: THIS SHOULD BE TESTED, this comment will be gone soon // TODO: THIS SHOULD BE TESTED, this comment will be gone soon
if conf.conf.allowed_idents_below_min_chars.contains("..") { if conf.conf.allowed_idents_below_min_chars.iter().any(|e| e == "..") {
conf.conf conf.conf
.allowed_idents_below_min_chars .allowed_idents_below_min_chars
.extend(DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS.iter().map(ToString::to_string)); .extend(DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS.iter().map(ToString::to_string));
} }
if conf.conf.doc_valid_idents.contains("..") { if conf.conf.doc_valid_idents.iter().any(|e| e == "..") {
conf.conf conf.conf
.doc_valid_idents .doc_valid_idents
.extend(DEFAULT_DOC_VALID_IDENTS.iter().map(ToString::to_string)); .extend(DEFAULT_DOC_VALID_IDENTS.iter().map(ToString::to_string));
@ -890,14 +889,14 @@ fn calculate_dimensions(fields: &[&str]) -> (usize, Vec<usize>) {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use serde::de::IgnoredAny; use serde::de::IgnoredAny;
use std::collections::{HashMap, HashSet};
use std::fs; use std::fs;
use walkdir::WalkDir; use walkdir::WalkDir;
#[test] #[test]
fn configs_are_tested() { fn configs_are_tested() {
let mut names: FxHashSet<String> = crate::get_configuration_metadata() let mut names: HashSet<String> = crate::get_configuration_metadata()
.into_iter() .into_iter()
.map(|meta| meta.name.replace('_', "-")) .map(|meta| meta.name.replace('_', "-"))
.collect(); .collect();
@ -910,7 +909,7 @@ fn configs_are_tested() {
for entry in toml_files { for entry in toml_files {
let file = fs::read_to_string(entry.path()).unwrap(); let file = fs::read_to_string(entry.path()).unwrap();
#[allow(clippy::zero_sized_map_values)] #[allow(clippy::zero_sized_map_values)]
if let Ok(map) = toml::from_str::<FxHashMap<String, IgnoredAny>>(&file) { if let Ok(map) = toml::from_str::<HashMap<String, IgnoredAny>>(&file) {
for name in map.keys() { for name in map.keys() {
names.remove(name.as_str()); names.remove(name.as_str());
} }

View File

@ -15,7 +15,6 @@
extern crate rustc_ast; extern crate rustc_ast;
extern crate rustc_attr; extern crate rustc_attr;
extern crate rustc_data_structures;
#[allow(unused_extern_crates)] #[allow(unused_extern_crates)]
extern crate rustc_driver; extern crate rustc_driver;
extern crate rustc_errors; extern crate rustc_errors;

View File

@ -205,7 +205,7 @@
} }
pub struct Cargo { pub struct Cargo {
allowed_duplicate_crates: &'static FxHashSet<String>, allowed_duplicate_crates: FxHashSet<String>,
ignore_publish: bool, ignore_publish: bool,
} }
@ -221,7 +221,7 @@ pub struct Cargo {
impl Cargo { impl Cargo {
pub fn new(conf: &'static Conf) -> Self { pub fn new(conf: &'static Conf) -> Self {
Self { Self {
allowed_duplicate_crates: &conf.allowed_duplicate_crates, allowed_duplicate_crates: conf.allowed_duplicate_crates.iter().cloned().collect(),
ignore_publish: conf.cargo_ignore_publish, ignore_publish: conf.cargo_ignore_publish,
} }
} }
@ -263,7 +263,7 @@ fn check_crate(&mut self, cx: &LateContext<'_>) {
{ {
match MetadataCommand::new().exec() { match MetadataCommand::new().exec() {
Ok(metadata) => { Ok(metadata) => {
multiple_crate_versions::check(cx, &metadata, self.allowed_duplicate_crates); multiple_crate_versions::check(cx, &metadata, &self.allowed_duplicate_crates);
}, },
Err(e) => { Err(e) => {
for lint in WITH_DEPS_LINTS { for lint in WITH_DEPS_LINTS {

View File

@ -423,14 +423,14 @@
} }
pub struct Documentation { pub struct Documentation {
valid_idents: &'static FxHashSet<String>, valid_idents: FxHashSet<String>,
check_private_items: bool, check_private_items: bool,
} }
impl Documentation { impl Documentation {
pub fn new(conf: &'static Conf) -> Self { pub fn new(conf: &'static Conf) -> Self {
Self { Self {
valid_idents: &conf.doc_valid_idents, valid_idents: conf.doc_valid_idents.iter().cloned().collect(),
check_private_items: conf.check_private_items, check_private_items: conf.check_private_items,
} }
} }
@ -452,7 +452,7 @@ pub fn new(conf: &'static Conf) -> Self {
impl<'tcx> LateLintPass<'tcx> for Documentation { impl<'tcx> LateLintPass<'tcx> for Documentation {
fn check_attributes(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) { fn check_attributes(&mut self, cx: &LateContext<'tcx>, attrs: &'tcx [Attribute]) {
let Some(headers) = check_attrs(cx, self.valid_idents, attrs) else { let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else {
return; return;
}; };

View File

@ -41,14 +41,14 @@
impl_lint_pass!(MinIdentChars => [MIN_IDENT_CHARS]); impl_lint_pass!(MinIdentChars => [MIN_IDENT_CHARS]);
pub struct MinIdentChars { pub struct MinIdentChars {
allowed_idents_below_min_chars: &'static FxHashSet<String>, allowed_idents_below_min_chars: FxHashSet<String>,
min_ident_chars_threshold: u64, min_ident_chars_threshold: u64,
} }
impl MinIdentChars { impl MinIdentChars {
pub fn new(conf: &'static Conf) -> Self { pub fn new(conf: &'static Conf) -> Self {
Self { Self {
allowed_idents_below_min_chars: &conf.allowed_idents_below_min_chars, allowed_idents_below_min_chars: conf.allowed_idents_below_min_chars.iter().cloned().collect(),
min_ident_chars_threshold: conf.min_ident_chars_threshold, min_ident_chars_threshold: conf.min_ident_chars_threshold,
} }
} }

View File

@ -35,7 +35,7 @@ pub fn new(conf: &'static Conf) -> Self {
("f64", FxHashSet::from_iter(["f64"])), ("f64", FxHashSet::from_iter(["f64"])),
("std::string::String", FxHashSet::from_iter(["str"])), ("std::string::String", FxHashSet::from_iter(["str"])),
]); ]);
for [lhs, rhs] in &conf.arithmetic_side_effects_allowed_binary { for (lhs, rhs) in &conf.arithmetic_side_effects_allowed_binary {
allowed_binary.entry(lhs).or_default().insert(rhs); allowed_binary.entry(lhs).or_default().insert(rhs);
} }
for s in &conf.arithmetic_side_effects_allowed { for s in &conf.arithmetic_side_effects_allowed {

View File

@ -100,14 +100,14 @@
pub struct WildcardImports { pub struct WildcardImports {
warn_on_all: bool, warn_on_all: bool,
allowed_segments: &'static FxHashSet<String>, allowed_segments: FxHashSet<String>,
} }
impl WildcardImports { impl WildcardImports {
pub fn new(conf: &'static Conf) -> Self { pub fn new(conf: &'static Conf) -> Self {
Self { Self {
warn_on_all: conf.warn_on_all_wildcard_imports, warn_on_all: conf.warn_on_all_wildcard_imports,
allowed_segments: &conf.allowed_wildcard_imports, allowed_segments: conf.allowed_wildcard_imports.iter().cloned().collect(),
} }
} }
} }
@ -181,7 +181,7 @@ impl WildcardImports {
fn check_exceptions(&self, cx: &LateContext<'_>, item: &Item<'_>, segments: &[PathSegment<'_>]) -> bool { fn check_exceptions(&self, cx: &LateContext<'_>, item: &Item<'_>, segments: &[PathSegment<'_>]) -> bool {
item.span.from_expansion() item.span.from_expansion()
|| is_prelude_import(segments) || is_prelude_import(segments)
|| is_allowed_via_config(segments, self.allowed_segments) || is_allowed_via_config(segments, &self.allowed_segments)
|| (is_super_only_import(segments) && is_in_test(cx.tcx, item.hir_id())) || (is_super_only_import(segments) && is_in_test(cx.tcx, item.hir_id()))
} }
} }