diff options
| author | bors <bors@rust-lang.org> | 2024-07-17 18:13:07 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-07-17 18:13:07 +0000 |
| commit | f74037e47ae8467bade27f9a5d520bfbbd7899a5 (patch) | |
| tree | 116eadb846c5d9274bf08e48bfbcda6f47a0fbd9 /book/src/development/adding_lints.md | |
| parent | 0ee9f44568b60aaef5d04684cb08f112edd89542 (diff) | |
| parent | e34c6dbae5768b5dce90c02465f3492376327c65 (diff) | |
| download | rust-f74037e47ae8467bade27f9a5d520bfbbd7899a5.tar.gz rust-f74037e47ae8467bade27f9a5d520bfbbd7899a5.zip | |
Auto merge of #13088 - Jarcho:conf_refactor2, r=flip1995
Create lint passes using `Conf` This slightly reduces the amount of code changes needed to add a config to a lint and makes things makes things more consistent between passes. A dependence on the config being a static reference is also added. This would only ever be a problem if multiple crates end up compiled in a single process. Other changes include: * Removing useless `#[derive(..)]`s * Removing `#[must_use]` on lint pass constructors. * Unified the parsing of the `DisallowedPath` struct in lint passes. * Update `disallowed_types` and `await_holding_invalid` messages to be consistent with other disallowed lints. * Remove the `(from clippy.toml)` message. I plan on having all the configured lints point to point to a span in `clippy.toml` which will be more useful. changelog: none
Diffstat (limited to 'book/src/development/adding_lints.md')
| -rw-r--r-- | book/src/development/adding_lints.md | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/book/src/development/adding_lints.md b/book/src/development/adding_lints.md index 48c00bcbf34..a71d94daca7 100644 --- a/book/src/development/adding_lints.md +++ b/book/src/development/adding_lints.md @@ -458,9 +458,8 @@ pub struct ManualStrip { } impl ManualStrip { - #[must_use] - pub fn new(msrv: Msrv) -> Self { - Self { msrv } + pub fn new(conf: &'static Conf) -> Self { + Self { msrv: conf.msrv.clone() } } } ``` @@ -689,7 +688,6 @@ for some users. Adding a configuration is done in the following steps: ]); // New manual definition struct - #[derive(Copy, Clone)] pub struct StructName {} impl_lint_pass!(StructName => [ @@ -700,7 +698,6 @@ for some users. Adding a configuration is done in the following steps: 2. Next add the configuration value and a corresponding creation method like this: ```rust - #[derive(Copy, Clone)] pub struct StructName { configuration_ident: Type, } @@ -708,9 +705,9 @@ for some users. Adding a configuration is done in the following steps: // ... impl StructName { - pub fn new(configuration_ident: Type) -> Self { + pub fn new(conf: &'static Conf) -> Self { Self { - configuration_ident, + configuration_ident: conf.configuration_ident, } } } @@ -726,8 +723,7 @@ for some users. Adding a configuration is done in the following steps: store.register_*_pass(|| box module::StructName); // New registration with configuration value - let configuration_ident = conf.configuration_ident.clone(); - store.register_*_pass(move || box module::StructName::new(configuration_ident)); + store.register_*_pass(move || box module::StructName::new(conf)); ``` Congratulations the work is almost done. The configuration value can now be |
