Skip to content

Destructure Conf in register_lints #11790

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 1 commit into from
Nov 11, 2023
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
8 changes: 1 addition & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,10 @@ For example, the [`else_if_without_else`][else_if_without_else] lint is register
pub mod else_if_without_else;
// ...

pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &Conf) {
pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
// ...
store.register_early_pass(|| Box::new(else_if_without_else::ElseIfWithoutElse));
// ...

store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![
// ...
LintId::of(&else_if_without_else::ELSE_IF_WITHOUT_ELSE),
// ...
]);
}
```

Expand Down
2 changes: 1 addition & 1 deletion book/src/development/adding_lints.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ When using `cargo dev new_lint`, the lint is automatically registered and
nothing more has to be done.

When declaring a new lint by hand and `cargo dev update_lints` is used, the lint
pass may have to be registered manually in the `register_plugins` function in
pass may have to be registered manually in the `register_lints` function in
`clippy_lints/src/lib.rs`:

```rust,ignore
Expand Down
2 changes: 1 addition & 1 deletion book/src/development/defining_lints.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ However, sometimes we might want to declare a new lint by hand. In this case,
we'd use `cargo dev update_lints` command afterwards.

When a lint is manually declared, we might need to register the lint pass
manually in the `register_plugins` function in `clippy_lints/src/lib.rs`:
manually in the `register_lints` function in `clippy_lints/src/lib.rs`:

```rust
store.register_late_pass(|_| Box::new(foo_functions::FooFunctions));
Expand Down
24 changes: 5 additions & 19 deletions clippy_config/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use serde::de::{self, Deserializer, Visitor};
use serde::{ser, Deserialize, Serialize};
use std::fmt;
use std::hash::{Hash, Hasher};

#[derive(Clone, Debug, Deserialize)]
pub struct Rename {
Expand Down Expand Up @@ -33,32 +32,19 @@ impl DisallowedPath {
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub enum MatchLintBehaviour {
AllTypes,
WellKnownTypes,
Never,
}

#[derive(Clone, Debug)]
#[derive(Debug)]
pub struct MacroMatcher {
pub name: String,
pub braces: (String, String),
pub braces: (char, char),
}

impl Hash for MacroMatcher {
fn hash<H: Hasher>(&self, state: &mut H) {
self.name.hash(state);
}
}

impl PartialEq for MacroMatcher {
fn eq(&self, other: &Self) -> bool {
self.name == other.name
}
}
impl Eq for MacroMatcher {}

impl<'de> Deserialize<'de> for MacroMatcher {
fn deserialize<D>(deser: D) -> Result<Self, D::Error>
where
Expand All @@ -83,7 +69,7 @@ impl<'de> Deserialize<'de> for MacroMatcher {
V: de::MapAccess<'de>,
{
let mut name = None;
let mut brace: Option<String> = None;
let mut brace: Option<char> = None;
while let Some(key) = map.next_key()? {
match key {
Field::Name => {
Expand All @@ -104,7 +90,7 @@ impl<'de> Deserialize<'de> for MacroMatcher {
let brace = brace.ok_or_else(|| de::Error::missing_field("brace"))?;
Ok(MacroMatcher {
name,
braces: [("(", ")"), ("{", "}"), ("[", "]")]
braces: [('(', ')'), ('{', '}'), ('[', ']')]
.into_iter()
.find(|b| b.0 == brace)
.map(|(o, c)| (o.to_owned(), c.to_owned()))
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/disallowed_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ pub struct DisallowedNames {
}

impl DisallowedNames {
pub fn new(disallow: FxHashSet<String>) -> Self {
pub fn new(disallowed_names: &[String]) -> Self {
Self {
disallow,
disallow: disallowed_names.iter().cloned().collect(),
test_modules_deep: 0,
}
}
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ pub struct DocMarkdown {
}

impl DocMarkdown {
pub fn new(valid_idents: FxHashSet<String>) -> Self {
pub fn new(valid_idents: &[String]) -> Self {
Self {
valid_idents,
valid_idents: valid_idents.iter().cloned().collect(),
in_trait_impl: false,
}
}
Expand Down
Loading