Skip to content

Commit

Permalink
Remove HashSets from Conf
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexendoo committed Aug 12, 2024
1 parent 182cd5f commit a22ce2d
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 27 deletions.
4 changes: 2 additions & 2 deletions book/src/lint_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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:**
Expand Down Expand Up @@ -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 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:**
Expand Down
23 changes: 11 additions & 12 deletions clippy_config/src/conf.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::msrvs::Msrv;
use crate::types::{DisallowedPath, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour, Rename};
use crate::ClippyConfiguration;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::Applicability;
use rustc_session::Session;
use rustc_span::edit_distance::edit_distance;
Expand Down Expand Up @@ -218,7 +217,7 @@ macro_rules! define_Conf {
define_Conf! {
/// Which crates to allow absolute paths from
#[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
/// be linted.
#[lints(absolute_paths)]
Expand Down Expand Up @@ -280,12 +279,12 @@ define_Conf! {
allowed_dotfiles: Vec<String> = Vec::default(),
/// A list of crate names to allow duplicates of
#[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
/// 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.
#[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(),
/// 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`),
Expand Down Expand Up @@ -323,7 +322,7 @@ define_Conf! {
/// 2. Paths with any segment that containing the word 'prelude'
/// are already allowed by default.
#[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.
///
/// If a specific operation is desired, consider using `arithmetic_side_effects_allowed_binary` or `arithmetic_side_effects_allowed_unary` instead.
Expand Down Expand Up @@ -355,7 +354,7 @@ define_Conf! {
/// arithmetic-side-effects-allowed-binary = [["SomeType" , "f32"], ["AnotherType", "*"]]
/// ```
#[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" (`-`).
///
/// #### Example
Expand Down Expand Up @@ -431,7 +430,7 @@ define_Conf! {
/// * `doc-valid-idents = ["ClipPy"]` would replace the default list with `["ClipPy"]`.
/// * `doc-valid-idents = ["ClipPy", ".."]` would append `ClipPy` to the default list.
#[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`.
#[lints(non_send_fields_in_send_ty)]
enable_raw_pointer_heuristic_for_send: bool = true,
Expand Down Expand Up @@ -706,12 +705,12 @@ fn deserialize(file: &SourceFile) -> TryConf {
DEFAULT_ALLOWED_TRAITS_WITH_RENAMED_PARAMS,
);
// 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
.allowed_idents_below_min_chars
.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
.doc_valid_idents
.extend(DEFAULT_DOC_VALID_IDENTS.iter().map(ToString::to_string));
Expand Down Expand Up @@ -890,14 +889,14 @@ fn calculate_dimensions(fields: &[&str]) -> (usize, Vec<usize>) {

#[cfg(test)]
mod tests {
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use serde::de::IgnoredAny;
use std::collections::{HashMap, HashSet};
use std::fs;
use walkdir::WalkDir;

#[test]
fn configs_are_tested() {
let mut names: FxHashSet<String> = crate::get_configuration_metadata()
let mut names: HashSet<String> = crate::get_configuration_metadata()
.into_iter()
.map(|meta| meta.name.replace('_', "-"))
.collect();
Expand All @@ -910,7 +909,7 @@ mod tests {
for entry in toml_files {
let file = fs::read_to_string(entry.path()).unwrap();
#[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() {
names.remove(name.as_str());
}
Expand Down
1 change: 0 additions & 1 deletion clippy_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

extern crate rustc_ast;
extern crate rustc_attr;
extern crate rustc_data_structures;
#[allow(unused_extern_crates)]
extern crate rustc_driver;
extern crate rustc_errors;
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/cargo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ declare_clippy_lint! {
}

pub struct Cargo {
allowed_duplicate_crates: &'static FxHashSet<String>,
allowed_duplicate_crates: FxHashSet<String>,
ignore_publish: bool,
}

Expand All @@ -221,7 +221,7 @@ impl_lint_pass!(Cargo => [
impl Cargo {
pub fn new(conf: &'static Conf) -> 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,
}
}
Expand Down Expand Up @@ -263,7 +263,7 @@ impl LateLintPass<'_> for Cargo {
{
match MetadataCommand::new().exec() {
Ok(metadata) => {
multiple_crate_versions::check(cx, &metadata, self.allowed_duplicate_crates);
multiple_crate_versions::check(cx, &metadata, &self.allowed_duplicate_crates);
},
Err(e) => {
for lint in WITH_DEPS_LINTS {
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/doc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,14 @@ declare_clippy_lint! {
}

pub struct Documentation {
valid_idents: &'static FxHashSet<String>,
valid_idents: FxHashSet<String>,
check_private_items: bool,
}

impl Documentation {
pub fn new(conf: &'static Conf) -> Self {
Self {
valid_idents: &conf.doc_valid_idents,
valid_idents: conf.doc_valid_idents.iter().cloned().collect(),
check_private_items: conf.check_private_items,
}
}
Expand All @@ -452,7 +452,7 @@ impl_lint_pass!(Documentation => [

impl<'tcx> LateLintPass<'tcx> for Documentation {
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;
};

Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/min_ident_chars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ declare_clippy_lint! {
impl_lint_pass!(MinIdentChars => [MIN_IDENT_CHARS]);

pub struct MinIdentChars {
allowed_idents_below_min_chars: &'static FxHashSet<String>,
allowed_idents_below_min_chars: FxHashSet<String>,
min_ident_chars_threshold: u64,
}

impl MinIdentChars {
pub fn new(conf: &'static Conf) -> 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,
}
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/operators/arithmetic_side_effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl ArithmeticSideEffects {
("f64", FxHashSet::from_iter(["f64"])),
("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);
}
for s in &conf.arithmetic_side_effects_allowed {
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/wildcard_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ declare_clippy_lint! {

pub struct WildcardImports {
warn_on_all: bool,
allowed_segments: &'static FxHashSet<String>,
allowed_segments: FxHashSet<String>,
}

impl WildcardImports {
pub fn new(conf: &'static Conf) -> Self {
Self {
warn_on_all: conf.warn_on_all_wildcard_imports,
allowed_segments: &conf.allowed_wildcard_imports,
allowed_segments: conf.allowed_wildcard_imports.iter().cloned().collect(),
}
}
}
Expand Down Expand Up @@ -181,7 +181,7 @@ impl WildcardImports {
fn check_exceptions(&self, cx: &LateContext<'_>, item: &Item<'_>, segments: &[PathSegment<'_>]) -> bool {
item.span.from_expansion()
|| 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()))
}
}
Expand Down

0 comments on commit a22ce2d

Please sign in to comment.