Skip to content

Commit 2066368

Browse files
committed
Auto merge of #3758 - phansch:document_macro, r=flip1995
Document `declare_clippy_lint` macro Split up from my work on updating CONTRIBUTING.md, which is slowly making progress. cc #2666
2 parents bd23cb8 + a14247b commit 2066368

File tree

1 file changed

+62
-2
lines changed

1 file changed

+62
-2
lines changed

clippy_lints/src/lib.rs

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,53 @@ extern crate syntax_pos;
3737

3838
use toml;
3939

40-
// Currently, categories "style", "correctness", "complexity" and "perf" are enabled by default,
41-
// as said in the README.md of this repository. If this changes, please update README.md.
40+
/// Macro used to declare a Clippy lint.
41+
///
42+
/// Every lint declaration consists of 4 parts:
43+
///
44+
/// 1. The documentation above the lint, which is used for the website
45+
/// 2. The `LINT_NAME`. See [lint naming][lint_naming] on lint naming conventions.
46+
/// 3. The `lint_level`, which is a mapping from *one* of our lint groups to `Allow`, `Warn` or
47+
/// `Deny`. The lint level here has nothing to do with what lint groups the lint is a part of.
48+
/// 4. The `description` that contains a short explanation on what's wrong with code where the
49+
/// lint is triggered.
50+
///
51+
/// Currently the categories `style`, `correctness`, `complexity` and `perf` are enabled by default.
52+
/// As said in the README.md of this repository, if the lint level mapping changes, please update
53+
/// README.md.
54+
///
55+
/// # Example
56+
///
57+
/// ```
58+
/// # #![feature(rustc_private)]
59+
/// # #[allow(unused_extern_crates)]
60+
/// # extern crate rustc;
61+
/// # #[macro_use]
62+
/// # use clippy_lints::declare_clippy_lint;
63+
/// use rustc::declare_tool_lint;
64+
///
65+
/// /// **What it does:** Checks for ... (describe what the lint matches).
66+
/// ///
67+
/// /// **Why is this bad?** Supply the reason for linting the code.
68+
/// ///
69+
/// /// **Known problems:** None. (Or describe where it could go wrong.)
70+
/// ///
71+
/// /// **Example:**
72+
/// ///
73+
/// /// ```rust
74+
/// /// // Bad
75+
/// /// Insert a short example of code that triggers the lint
76+
/// ///
77+
/// /// // Good
78+
/// /// Insert a short example of improved code that doesn't trigger the lint
79+
/// /// ```
80+
/// declare_clippy_lint! {
81+
/// pub LINT_NAME,
82+
/// pedantic,
83+
/// "description"
84+
/// }
85+
/// ```
86+
/// [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
4287
#[macro_export]
4388
macro_rules! declare_clippy_lint {
4489
{ pub $name:tt, style, $description:tt } => {
@@ -211,6 +256,14 @@ mod reexport {
211256
crate use syntax::ast::{Name, NodeId};
212257
}
213258

259+
/// Register all pre expansion lints
260+
///
261+
/// Pre-expansion lints run before any macro expansion has happened.
262+
///
263+
/// Note that due to the architechture of the compiler, currently `cfg_attr` attributes on crate
264+
/// level (i.e `#![cfg_attr(...)]`) will still be expanded even when using a pre-expansion pass.
265+
///
266+
/// Used in `./src/driver.rs`.
214267
pub fn register_pre_expansion_lints(
215268
session: &rustc::session::Session,
216269
store: &mut rustc::lint::LintStore,
@@ -235,6 +288,7 @@ pub fn register_pre_expansion_lints(
235288
store.register_pre_expansion_pass(Some(session), true, false, box dbg_macro::Pass);
236289
}
237290

291+
#[doc(hidden)]
238292
pub fn read_conf(reg: &rustc_plugin::Registry<'_>) -> Conf {
239293
match utils::conf::file_from_args(reg.args()) {
240294
Ok(file_name) => {
@@ -292,6 +346,9 @@ pub fn read_conf(reg: &rustc_plugin::Registry<'_>) -> Conf {
292346
}
293347
}
294348

349+
/// Register all lints and lint groups with the rustc plugin registry
350+
///
351+
/// Used in `./src/driver.rs`.
295352
#[allow(clippy::too_many_lines)]
296353
#[rustfmt::skip]
297354
pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
@@ -1046,6 +1103,9 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
10461103
]);
10471104
}
10481105

1106+
/// Register renamed lints.
1107+
///
1108+
/// Used in `./src/driver.rs`.
10491109
pub fn register_renamed(ls: &mut rustc::lint::LintStore) {
10501110
ls.register_renamed("clippy::stutter", "clippy::module_name_repetitions");
10511111
ls.register_renamed("clippy::new_without_default_derive", "clippy::new_without_default");

0 commit comments

Comments
 (0)