Skip to content

Commit ab7381f

Browse files
committed
Move declare_clippy_lint back into clippy_lints
1 parent c7869b8 commit ab7381f

File tree

9 files changed

+112
-124
lines changed

9 files changed

+112
-124
lines changed

clippy_dev/src/lib.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,11 @@ fn gather_from_file(dir_entry: &walkdir::DirEntry) -> impl Iterator<Item = Lint>
186186
let path_buf = path.with_file_name(filename);
187187
let mut rel_path = path_buf
188188
.strip_prefix(clippy_project_root().join("clippy_lints/src"))
189-
.map(PathBuf::from)
190-
.or_else(|_| {
191-
path_buf
192-
.strip_prefix(clippy_project_root().join("clippy_utils/src"))
193-
.map(|c| Path::new("utils").join(c))
194-
})
195-
.expect("only files in `clippy_lints/src` or `clippy_utils/src` should be looked at");
189+
.expect("only files in `clippy_lints/src` should be looked at");
196190
// If the lints are stored in mod.rs, we get the module name from
197191
// the containing directory:
198192
if filename == "mod" {
199-
rel_path = rel_path.parent().unwrap().to_path_buf();
193+
rel_path = rel_path.parent().unwrap();
200194
}
201195

202196
let module = rel_path
@@ -219,15 +213,13 @@ fn parse_contents(content: &str, module: &str) -> impl Iterator<Item = Lint> {
219213
lints.chain(deprecated).collect::<Vec<Lint>>().into_iter()
220214
}
221215

222-
/// Collects all .rs files in the `clippy_lints/src` and `clippy_utils/src` directories
216+
/// Collects all .rs files in the `clippy_lints/src` directory
223217
fn lint_files() -> impl Iterator<Item = walkdir::DirEntry> {
224218
// We use `WalkDir` instead of `fs::read_dir` here in order to recurse into subdirectories.
225219
// Otherwise we would not collect all the lints, for example in `clippy_lints/src/methods/`.
226-
let clippy_lints_path = clippy_project_root().join("clippy_lints/src");
227-
let clippy_utils_path = clippy_project_root().join("clippy_utils/src");
228-
WalkDir::new(clippy_lints_path)
220+
let path = clippy_project_root().join("clippy_lints/src");
221+
WalkDir::new(path)
229222
.into_iter()
230-
.chain(WalkDir::new(clippy_utils_path).into_iter())
231223
.filter_map(Result::ok)
232224
.filter(|f| f.path().extension() == Some(OsStr::new("rs")))
233225
}

clippy_lints/src/lib.rs

+95-1
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,103 @@ use rustc_data_structures::fx::FxHashSet;
4646
use rustc_lint::LintId;
4747
use rustc_session::Session;
4848

49+
/// Macro used to declare a Clippy lint.
50+
///
51+
/// Every lint declaration consists of 4 parts:
52+
///
53+
/// 1. The documentation, which is used for the website
54+
/// 2. The `LINT_NAME`. See [lint naming][lint_naming] on lint naming conventions.
55+
/// 3. The `lint_level`, which is a mapping from *one* of our lint groups to `Allow`, `Warn` or
56+
/// `Deny`. The lint level here has nothing to do with what lint groups the lint is a part of.
57+
/// 4. The `description` that contains a short explanation on what's wrong with code where the
58+
/// lint is triggered.
59+
///
60+
/// Currently the categories `style`, `correctness`, `complexity` and `perf` are enabled by default.
61+
/// As said in the README.md of this repository, if the lint level mapping changes, please update
62+
/// README.md.
63+
///
64+
/// # Example
65+
///
66+
/// ```
67+
/// #![feature(rustc_private)]
68+
/// extern crate rustc_session;
69+
/// use rustc_session::declare_tool_lint;
70+
/// use clippy_lints::declare_clippy_lint;
71+
///
72+
/// declare_clippy_lint! {
73+
/// /// **What it does:** Checks for ... (describe what the lint matches).
74+
/// ///
75+
/// /// **Why is this bad?** Supply the reason for linting the code.
76+
/// ///
77+
/// /// **Known problems:** None. (Or describe where it could go wrong.)
78+
/// ///
79+
/// /// **Example:**
80+
/// ///
81+
/// /// ```rust
82+
/// /// // Bad
83+
/// /// Insert a short example of code that triggers the lint
84+
/// ///
85+
/// /// // Good
86+
/// /// Insert a short example of improved code that doesn't trigger the lint
87+
/// /// ```
88+
/// pub LINT_NAME,
89+
/// pedantic,
90+
/// "description"
91+
/// }
92+
/// ```
93+
/// [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
4994
#[macro_export]
5095
macro_rules! declare_clippy_lint {
51-
( $($x:tt)* ) => { clippy_utils::declare_clippy_lint!($($x)*); }
96+
{ $(#[$attr:meta])* pub $name:tt, style, $description:tt } => {
97+
declare_tool_lint! {
98+
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
99+
}
100+
};
101+
{ $(#[$attr:meta])* pub $name:tt, correctness, $description:tt } => {
102+
declare_tool_lint! {
103+
$(#[$attr])* pub clippy::$name, Deny, $description, report_in_external_macro: true
104+
}
105+
};
106+
{ $(#[$attr:meta])* pub $name:tt, complexity, $description:tt } => {
107+
declare_tool_lint! {
108+
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
109+
}
110+
};
111+
{ $(#[$attr:meta])* pub $name:tt, perf, $description:tt } => {
112+
declare_tool_lint! {
113+
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
114+
}
115+
};
116+
{ $(#[$attr:meta])* pub $name:tt, pedantic, $description:tt } => {
117+
declare_tool_lint! {
118+
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
119+
}
120+
};
121+
{ $(#[$attr:meta])* pub $name:tt, restriction, $description:tt } => {
122+
declare_tool_lint! {
123+
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
124+
}
125+
};
126+
{ $(#[$attr:meta])* pub $name:tt, cargo, $description:tt } => {
127+
declare_tool_lint! {
128+
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
129+
}
130+
};
131+
{ $(#[$attr:meta])* pub $name:tt, nursery, $description:tt } => {
132+
declare_tool_lint! {
133+
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
134+
}
135+
};
136+
{ $(#[$attr:meta])* pub $name:tt, internal, $description:tt } => {
137+
declare_tool_lint! {
138+
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
139+
}
140+
};
141+
{ $(#[$attr:meta])* pub $name:tt, internal_warn, $description:tt } => {
142+
declare_tool_lint! {
143+
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
144+
}
145+
};
52146
}
53147

54148
#[macro_export]

clippy_lints/src/utils.rs

-1
This file was deleted.

clippy_utils/src/author.rs renamed to clippy_lints/src/utils/author.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! A group of attributes that can be attached to Rust code in order
22
//! to generate a clippy lint detecting said code automatically.
33
4-
use crate::{declare_clippy_lint, get_attr};
4+
use crate::utils::get_attr;
55
use rustc_ast::ast::{Attribute, LitFloatType, LitKind};
66
use rustc_ast::walk_list;
77
use rustc_data_structures::fx::FxHashMap;

clippy_utils/src/inspector.rs renamed to clippy_lints/src/utils/inspector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! checks for attributes
22
3-
use crate::{declare_clippy_lint, get_attr};
3+
use crate::utils::get_attr;
44
use rustc_ast::ast::{Attribute, InlineAsmTemplatePiece};
55
use rustc_hir as hir;
66
use rustc_lint::{LateContext, LateLintPass, LintContext};

clippy_utils/src/internal_lints.rs renamed to clippy_lints/src/utils/internal_lints.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::consts::{constant_simple, Constant};
2-
use crate::{
3-
declare_clippy_lint, is_expn_of, match_def_path, match_qpath, match_type, method_calls, path_to_res, paths,
4-
run_lints, snippet, span_lint, span_lint_and_help, span_lint_and_sugg, SpanlessEq,
2+
use crate::utils::{
3+
is_expn_of, match_def_path, match_qpath, match_type, method_calls, path_to_res, paths, run_lints, snippet,
4+
span_lint, span_lint_and_help, span_lint_and_sugg, SpanlessEq,
55
};
66
use if_chain::if_chain;
77
use rustc_ast::ast::{Crate as AstCrate, ItemKind, LitKind, NodeId};

clippy_lints/src/utils/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pub mod author;
2+
pub mod inspector;
3+
#[cfg(feature = "internal-lints")]
4+
pub mod internal_lints;
5+
6+
pub use clippy_utils::*;

clippy_utils/src/lib.rs

-103
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ pub mod sym_helper;
3030
#[allow(clippy::module_name_repetitions)]
3131
pub mod ast_utils;
3232
pub mod attrs;
33-
pub mod author;
3433
pub mod camel_case;
3534
pub mod comparisons;
3635
pub mod conf;
@@ -39,9 +38,6 @@ mod diagnostics;
3938
pub mod eager_or_lazy;
4039
pub mod higher;
4140
mod hir_utils;
42-
pub mod inspector;
43-
#[cfg(feature = "internal-lints")]
44-
pub mod internal_lints;
4541
pub mod numeric_literal;
4642
pub mod paths;
4743
pub mod ptr;
@@ -90,105 +86,6 @@ use smallvec::SmallVec;
9086

9187
use crate::consts::{constant, Constant};
9288

93-
/// Macro used to declare a Clippy lint.
94-
///
95-
/// Every lint declaration consists of 4 parts:
96-
///
97-
/// 1. The documentation, which is used for the website
98-
/// 2. The `LINT_NAME`. See [lint naming][lint_naming] on lint naming conventions.
99-
/// 3. The `lint_level`, which is a mapping from *one* of our lint groups to `Allow`, `Warn` or
100-
/// `Deny`. The lint level here has nothing to do with what lint groups the lint is a part of.
101-
/// 4. The `description` that contains a short explanation on what's wrong with code where the
102-
/// lint is triggered.
103-
///
104-
/// Currently the categories `style`, `correctness`, `complexity` and `perf` are enabled by default.
105-
/// As said in the README.md of this repository, if the lint level mapping changes, please update
106-
/// README.md.
107-
///
108-
/// # Example
109-
///
110-
/// ```
111-
/// #![feature(rustc_private)]
112-
/// extern crate rustc_session;
113-
/// use rustc_session::declare_tool_lint;
114-
/// use clippy_utils::declare_clippy_lint;
115-
///
116-
/// declare_clippy_lint! {
117-
/// /// **What it does:** Checks for ... (describe what the lint matches).
118-
/// ///
119-
/// /// **Why is this bad?** Supply the reason for linting the code.
120-
/// ///
121-
/// /// **Known problems:** None. (Or describe where it could go wrong.)
122-
/// ///
123-
/// /// **Example:**
124-
/// ///
125-
/// /// ```rust
126-
/// /// // Bad
127-
/// /// Insert a short example of code that triggers the lint
128-
/// ///
129-
/// /// // Good
130-
/// /// Insert a short example of improved code that doesn't trigger the lint
131-
/// /// ```
132-
/// pub LINT_NAME,
133-
/// pedantic,
134-
/// "description"
135-
/// }
136-
/// ```
137-
/// [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
138-
#[macro_export]
139-
macro_rules! declare_clippy_lint {
140-
{ $(#[$attr:meta])* pub $name:tt, style, $description:tt } => {
141-
declare_tool_lint! {
142-
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
143-
}
144-
};
145-
{ $(#[$attr:meta])* pub $name:tt, correctness, $description:tt } => {
146-
declare_tool_lint! {
147-
$(#[$attr])* pub clippy::$name, Deny, $description, report_in_external_macro: true
148-
}
149-
};
150-
{ $(#[$attr:meta])* pub $name:tt, complexity, $description:tt } => {
151-
declare_tool_lint! {
152-
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
153-
}
154-
};
155-
{ $(#[$attr:meta])* pub $name:tt, perf, $description:tt } => {
156-
declare_tool_lint! {
157-
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
158-
}
159-
};
160-
{ $(#[$attr:meta])* pub $name:tt, pedantic, $description:tt } => {
161-
declare_tool_lint! {
162-
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
163-
}
164-
};
165-
{ $(#[$attr:meta])* pub $name:tt, restriction, $description:tt } => {
166-
declare_tool_lint! {
167-
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
168-
}
169-
};
170-
{ $(#[$attr:meta])* pub $name:tt, cargo, $description:tt } => {
171-
declare_tool_lint! {
172-
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
173-
}
174-
};
175-
{ $(#[$attr:meta])* pub $name:tt, nursery, $description:tt } => {
176-
declare_tool_lint! {
177-
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
178-
}
179-
};
180-
{ $(#[$attr:meta])* pub $name:tt, internal, $description:tt } => {
181-
declare_tool_lint! {
182-
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
183-
}
184-
};
185-
{ $(#[$attr:meta])* pub $name:tt, internal_warn, $description:tt } => {
186-
declare_tool_lint! {
187-
$(#[$attr])* pub clippy::$name, Warn, $description, report_in_external_macro: true
188-
}
189-
};
190-
}
191-
19289
pub fn parse_msrv(msrv: &str, sess: Option<&Session>, span: Option<Span>) -> Option<RustcVersion> {
19390
if let Ok(version) = RustcVersion::parse(msrv) {
19491
return Some(version);

tests/ui-internal/custom_ice_message.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
thread 'rustc' panicked at 'Would you like some help with that?', clippy_utils/src/internal_lints.rs
1+
thread 'rustc' panicked at 'Would you like some help with that?', clippy_lints/src/utils/internal_lints.rs
22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
33

44
error: internal compiler error: unexpected panic

0 commit comments

Comments
 (0)