Skip to content

Commit 0b9ba49

Browse files
committed
Generate default lint groups
1 parent 343df88 commit 0b9ba49

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

crates/ide_db/src/helpers/generated_lints.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub struct Lint {
77

88
pub const DEFAULT_LINTS: &[Lint] = &[
99
Lint { label: "----", description: r##"-------"## },
10+
Lint { label: "----", description: r##"lint group for: ---------"## },
1011
Lint {
1112
label: "absolute-paths-not-starting-with-crate",
1213
description: r##"fully qualified paths that start with a module name instead of `crate`, `self`, or an extern crate name"##,
@@ -97,6 +98,10 @@ pub const DEFAULT_LINTS: &[Lint] = &[
9798
label: "function-item-references",
9899
description: r##"suggest casting to a function pointer when attempting to take references to function items"##,
99100
},
101+
Lint {
102+
label: "future-incompatible",
103+
description: r##"lint group for: keyword-idents, anonymous-parameters, ellipsis-inclusive-range-patterns, forbidden-lint-groups, illegal-floating-point-literal-pattern, private-in-public, pub-use-of-private-extern-crate, invalid-type-param-default, const-err, unaligned-references, patterns-in-fns-without-body, missing-fragment-specifier, late-bound-lifetime-arguments, order-dependent-trait-objects, coherence-leak-check, tyvar-behind-raw-pointer, bare-trait-objects, absolute-paths-not-starting-with-crate, unstable-name-collisions, where-clauses-object-safety, proc-macro-derive-resolution-fallback, macro-expanded-macro-exports-accessed-by-absolute-paths, ill-formed-attribute-input, conflicting-repr-hints, ambiguous-associated-items, mutable-borrow-reservation-conflict, indirect-structural-match, pointer-structural-match, nontrivial-structural-match, soft-unstable, cenum-impl-drop-cast, const-evaluatable-unchecked, uninhabited-static, unsupported-naked-functions, semicolon-in-expressions-from-macros, legacy-derive-helpers, proc-macro-back-compat, array-into-iter"##,
104+
},
100105
Lint {
101106
label: "ill-formed-attribute-input",
102107
description: r##"ill-formed attribute inputs that were previously accepted and used in practice"##,
@@ -222,6 +227,10 @@ pub const DEFAULT_LINTS: &[Lint] = &[
222227
label: "non-upper-case-globals",
223228
description: r##"static constants should have uppercase identifiers"##,
224229
},
230+
Lint {
231+
label: "nonstandard-style",
232+
description: r##"lint group for: non-camel-case-types, non-snake-case, non-upper-case-globals"##,
233+
},
225234
Lint {
226235
label: "nontrivial-structural-match",
227236
description: r##"constant used in pattern of non-structural-match type and the constant's initializer expression contains values of non-structural-match types"##,
@@ -276,6 +285,18 @@ pub const DEFAULT_LINTS: &[Lint] = &[
276285
label: "renamed-and-removed-lints",
277286
description: r##"lints that have been renamed or removed"##,
278287
},
288+
Lint {
289+
label: "rust-2018-compatibility",
290+
description: r##"lint group for: keyword-idents, anonymous-parameters, tyvar-behind-raw-pointer, absolute-paths-not-starting-with-crate"##,
291+
},
292+
Lint {
293+
label: "rust-2018-idioms",
294+
description: r##"lint group for: bare-trait-objects, unused-extern-crates, ellipsis-inclusive-range-patterns, elided-lifetimes-in-paths, explicit-outlives-requirements"##,
295+
},
296+
Lint {
297+
label: "rust-2021-compatibility",
298+
description: r##"lint group for: ellipsis-inclusive-range-patterns, bare-trait-objects"##,
299+
},
279300
Lint {
280301
label: "semicolon-in-expressions-from-macros",
281302
description: r##"trailing semicolon in macro body used as expression"##,
@@ -365,6 +386,10 @@ pub const DEFAULT_LINTS: &[Lint] = &[
365386
label: "unsupported-naked-functions",
366387
description: r##"unsupported naked function definitions"##,
367388
},
389+
Lint {
390+
label: "unused",
391+
description: r##"lint group for: unused-imports, unused-variables, unused-assignments, dead-code, unused-mut, unreachable-code, unreachable-patterns, unused-must-use, unused-unsafe, path-statements, unused-attributes, unused-macros, unused-allocation, unused-doc-comments, unused-extern-crates, unused-features, unused-labels, unused-parens, unused-braces, redundant-semicolons"##,
392+
},
368393
Lint {
369394
label: "unused-allocation",
370395
description: r##"detects unnecessary allocations that can be eliminated"##,
@@ -443,6 +468,10 @@ pub const DEFAULT_LINTS: &[Lint] = &[
443468
label: "warnings",
444469
description: r##"mass-change the level for lints which produce warnings"##,
445470
},
471+
Lint {
472+
label: "warnings",
473+
description: r##"lint group for: all lints that are set to issue warnings"##,
474+
},
446475
Lint {
447476
label: "where-clauses-object-safety",
448477
description: r##"checks the object safety of where clauses"##,

xtask/src/codegen/gen_lint_completions.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! Generates descriptors structure for unstable feature from Unstable Book
2+
use std::borrow::Cow;
23
use std::fmt::Write;
34
use std::path::{Path, PathBuf};
45

@@ -38,22 +39,36 @@ pub(crate) fn generate_lint_completions() -> Result<()> {
3839

3940
fn generate_lint_descriptor(buf: &mut String) -> Result<()> {
4041
let stdout = cmd!("rustc -W help").read()?;
41-
let start = stdout.find("---- ------- -------").ok_or_else(|| anyhow::format_err!(""))?;
42-
let end =
43-
stdout.rfind("Lint groups provided by rustc:").ok_or_else(|| anyhow::format_err!(""))?;
42+
let start_lints =
43+
stdout.find("---- ------- -------").ok_or_else(|| anyhow::format_err!(""))?;
44+
let start_lint_groups =
45+
stdout.find("---- ---------").ok_or_else(|| anyhow::format_err!(""))?;
46+
let end_lints =
47+
stdout.find("Lint groups provided by rustc:").ok_or_else(|| anyhow::format_err!(""))?;
48+
let end_lint_groups = stdout
49+
.find("Lint tools like Clippy can provide additional lints and lint groups.")
50+
.ok_or_else(|| anyhow::format_err!(""))?;
4451
buf.push_str(r#"pub const DEFAULT_LINTS: &[Lint] = &["#);
4552
buf.push('\n');
46-
let mut lints = stdout[start..end]
53+
let mut lints = stdout[start_lints..end_lints]
4754
.lines()
4855
.filter(|l| !l.is_empty())
49-
.flat_map(|line| {
50-
let (name, rest) = line.trim().split_once(char::is_whitespace)?;
51-
let (_default_level, description) = rest.trim().split_once(char::is_whitespace)?;
52-
Some((name.trim(), description.trim()))
56+
.map(|line| {
57+
let (name, rest) = line.trim().split_once(char::is_whitespace).unwrap();
58+
let (_default_level, description) =
59+
rest.trim().split_once(char::is_whitespace).unwrap();
60+
(name.trim(), Cow::Borrowed(description.trim()))
5361
})
5462
.collect::<Vec<_>>();
63+
lints.extend(stdout[start_lint_groups..end_lint_groups].lines().filter(|l| !l.is_empty()).map(
64+
|line| {
65+
let (name, lints) = line.trim().split_once(char::is_whitespace).unwrap();
66+
(name.trim(), format!("lint group for: {}", lints.trim()).into())
67+
},
68+
));
69+
5570
lints.sort_by(|(ident, _), (ident2, _)| ident.cmp(ident2));
56-
lints.into_iter().for_each(|(name, description)| push_lint_completion(buf, name, description));
71+
lints.into_iter().for_each(|(name, description)| push_lint_completion(buf, name, &description));
5772
buf.push_str("];\n");
5873
Ok(())
5974
}

0 commit comments

Comments
 (0)