Skip to content

Commit c81cf91

Browse files
committed
show default lint levels
1 parent 3507173 commit c81cf91

File tree

4 files changed

+44
-25
lines changed

4 files changed

+44
-25
lines changed

clippy_dev/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ fn update_lints(update_mode: &UpdateMode) {
102102
103103
pub mod lint;
104104
pub use lint::Lint;
105+
pub use lint::LINT_LEVELS;
105106
106107
pub const ALL_LINTS: [Lint; {}] = {:#?};\n",
107108
sorted_usable_lints.len(),

src/driver.rs

+12-25
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,17 @@ Available lint options:
125125
"
126126
);
127127

128+
let lint_level = |lint: &Lint| {
129+
LINT_LEVELS
130+
.iter()
131+
.find(|level_mapping| level_mapping.0 == lint.group)
132+
.map(|(_, level)| level)
133+
.unwrap()
134+
};
135+
128136
let mut lints: Vec<_> = ALL_LINTS.iter().collect();
129137
// The sort doesn't case-fold but it's doubtful we care.
130-
lints.sort_by_cached_key(|x: &&Lint| ("unknown", x.name));
138+
lints.sort_by_cached_key(|x: &&Lint| (lint_level(x), x.name));
131139

132140
let max_name_len = lints
133141
.iter()
@@ -153,7 +161,7 @@ Available lint options:
153161
let print_lints = |lints: &[&Lint]| {
154162
for lint in lints {
155163
let name = lint.name.replace("_", "-");
156-
println!(" {} {:7.7} {}", padded(&scoped(&name)), "unknown", lint.desc);
164+
println!(" {} {:7.7} {}", padded(&scoped(&name)), lint_level(lint), lint.desc);
157165
}
158166
println!("\n");
159167
};
@@ -179,12 +187,12 @@ Available lint options:
179187
println!("Lint groups provided by rustc:\n");
180188
println!(" {} sub-lints", padded("name"));
181189
println!(" {} ---------", padded("----"));
182-
// println!(" {} all lints that are set to issue warnings", padded("warnings"));
183190

184191
let print_lint_groups = || {
185192
for group in lint_groups {
186193
let name = group.to_lowercase().replace("_", "-");
187-
let desc = lints.iter()
194+
let desc = lints
195+
.iter()
188196
.filter(|&lint| lint.group == group)
189197
.map(|lint| lint.name)
190198
.map(|name| name.replace("_", "-"))
@@ -196,27 +204,6 @@ Available lint options:
196204
};
197205

198206
print_lint_groups();
199-
200-
// print_lint_groups(builtin_groups);
201-
202-
// match (loaded_plugins, plugin.len(), plugin_groups.len()) {
203-
// (false, 0, _) | (false, _, 0) => {
204-
// println!("Compiler plugins can provide additional lints and lint groups. To see a \
205-
// listing of these, re-run `rustc -W help` with a crate filename.");
206-
// }
207-
// (false, ..) => panic!("didn't load lint plugins but got them anyway!"),
208-
// (true, 0, 0) => println!("This crate does not load any lint plugins or lint groups."),
209-
// (true, l, g) => {
210-
// if l > 0 {
211-
// println!("Lint checks provided by plugins loaded by this crate:\n");
212-
// print_lints(plugin);
213-
// }
214-
// if g > 0 {
215-
// println!("Lint groups provided by plugins loaded by this crate:\n");
216-
// print_lint_groups(plugin_groups);
217-
// }
218-
// }
219-
// }
220207
}
221208

222209
fn display_help() {

src/lintlist/lint.rs

+30
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,33 @@ pub struct Lint {
77
pub deprecation: Option<&'static str>,
88
pub module: &'static str,
99
}
10+
11+
#[derive(PartialOrd, PartialEq, Ord, Eq)]
12+
pub enum LintLevel {
13+
Allow,
14+
Warn,
15+
Deny,
16+
}
17+
18+
impl std::fmt::Display for LintLevel {
19+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
20+
let s = match self {
21+
LintLevel::Allow => "allow",
22+
LintLevel::Warn => "warn",
23+
LintLevel::Deny => "deny",
24+
};
25+
26+
write!(f, "{}", s)
27+
}
28+
}
29+
30+
pub const LINT_LEVELS: [(&str, LintLevel); 8] = [
31+
("correctness", LintLevel::Deny),
32+
("style", LintLevel::Warn),
33+
("complexity", LintLevel::Warn),
34+
("perf", LintLevel::Warn),
35+
("restriction", LintLevel::Allow),
36+
("pedantic", LintLevel::Allow),
37+
("nursery", LintLevel::Allow),
38+
("cargo", LintLevel::Allow),
39+
];

src/lintlist/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
pub mod lint;
44
pub use lint::Lint;
5+
pub use lint::LINT_LEVELS;
56

67
pub const ALL_LINTS: [Lint; 304] = [
78
Lint {

0 commit comments

Comments
 (0)