mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
Generate default lint groups
This commit is contained in:
parent
343df88ac7
commit
0b9ba4977e
@ -7,6 +7,7 @@ pub struct Lint {
|
||||
|
||||
pub const DEFAULT_LINTS: &[Lint] = &[
|
||||
Lint { label: "----", description: r##"-------"## },
|
||||
Lint { label: "----", description: r##"lint group for: ---------"## },
|
||||
Lint {
|
||||
label: "absolute-paths-not-starting-with-crate",
|
||||
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] = &[
|
||||
label: "function-item-references",
|
||||
description: r##"suggest casting to a function pointer when attempting to take references to function items"##,
|
||||
},
|
||||
Lint {
|
||||
label: "future-incompatible",
|
||||
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"##,
|
||||
},
|
||||
Lint {
|
||||
label: "ill-formed-attribute-input",
|
||||
description: r##"ill-formed attribute inputs that were previously accepted and used in practice"##,
|
||||
@ -222,6 +227,10 @@ pub const DEFAULT_LINTS: &[Lint] = &[
|
||||
label: "non-upper-case-globals",
|
||||
description: r##"static constants should have uppercase identifiers"##,
|
||||
},
|
||||
Lint {
|
||||
label: "nonstandard-style",
|
||||
description: r##"lint group for: non-camel-case-types, non-snake-case, non-upper-case-globals"##,
|
||||
},
|
||||
Lint {
|
||||
label: "nontrivial-structural-match",
|
||||
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] = &[
|
||||
label: "renamed-and-removed-lints",
|
||||
description: r##"lints that have been renamed or removed"##,
|
||||
},
|
||||
Lint {
|
||||
label: "rust-2018-compatibility",
|
||||
description: r##"lint group for: keyword-idents, anonymous-parameters, tyvar-behind-raw-pointer, absolute-paths-not-starting-with-crate"##,
|
||||
},
|
||||
Lint {
|
||||
label: "rust-2018-idioms",
|
||||
description: r##"lint group for: bare-trait-objects, unused-extern-crates, ellipsis-inclusive-range-patterns, elided-lifetimes-in-paths, explicit-outlives-requirements"##,
|
||||
},
|
||||
Lint {
|
||||
label: "rust-2021-compatibility",
|
||||
description: r##"lint group for: ellipsis-inclusive-range-patterns, bare-trait-objects"##,
|
||||
},
|
||||
Lint {
|
||||
label: "semicolon-in-expressions-from-macros",
|
||||
description: r##"trailing semicolon in macro body used as expression"##,
|
||||
@ -365,6 +386,10 @@ pub const DEFAULT_LINTS: &[Lint] = &[
|
||||
label: "unsupported-naked-functions",
|
||||
description: r##"unsupported naked function definitions"##,
|
||||
},
|
||||
Lint {
|
||||
label: "unused",
|
||||
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"##,
|
||||
},
|
||||
Lint {
|
||||
label: "unused-allocation",
|
||||
description: r##"detects unnecessary allocations that can be eliminated"##,
|
||||
@ -443,6 +468,10 @@ pub const DEFAULT_LINTS: &[Lint] = &[
|
||||
label: "warnings",
|
||||
description: r##"mass-change the level for lints which produce warnings"##,
|
||||
},
|
||||
Lint {
|
||||
label: "warnings",
|
||||
description: r##"lint group for: all lints that are set to issue warnings"##,
|
||||
},
|
||||
Lint {
|
||||
label: "where-clauses-object-safety",
|
||||
description: r##"checks the object safety of where clauses"##,
|
||||
|
@ -1,4 +1,5 @@
|
||||
//! Generates descriptors structure for unstable feature from Unstable Book
|
||||
use std::borrow::Cow;
|
||||
use std::fmt::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
@ -38,22 +39,36 @@ pub(crate) fn generate_lint_completions() -> Result<()> {
|
||||
|
||||
fn generate_lint_descriptor(buf: &mut String) -> Result<()> {
|
||||
let stdout = cmd!("rustc -W help").read()?;
|
||||
let start = stdout.find("---- ------- -------").ok_or_else(|| anyhow::format_err!(""))?;
|
||||
let end =
|
||||
stdout.rfind("Lint groups provided by rustc:").ok_or_else(|| anyhow::format_err!(""))?;
|
||||
let start_lints =
|
||||
stdout.find("---- ------- -------").ok_or_else(|| anyhow::format_err!(""))?;
|
||||
let start_lint_groups =
|
||||
stdout.find("---- ---------").ok_or_else(|| anyhow::format_err!(""))?;
|
||||
let end_lints =
|
||||
stdout.find("Lint groups provided by rustc:").ok_or_else(|| anyhow::format_err!(""))?;
|
||||
let end_lint_groups = stdout
|
||||
.find("Lint tools like Clippy can provide additional lints and lint groups.")
|
||||
.ok_or_else(|| anyhow::format_err!(""))?;
|
||||
buf.push_str(r#"pub const DEFAULT_LINTS: &[Lint] = &["#);
|
||||
buf.push('\n');
|
||||
let mut lints = stdout[start..end]
|
||||
let mut lints = stdout[start_lints..end_lints]
|
||||
.lines()
|
||||
.filter(|l| !l.is_empty())
|
||||
.flat_map(|line| {
|
||||
let (name, rest) = line.trim().split_once(char::is_whitespace)?;
|
||||
let (_default_level, description) = rest.trim().split_once(char::is_whitespace)?;
|
||||
Some((name.trim(), description.trim()))
|
||||
.map(|line| {
|
||||
let (name, rest) = line.trim().split_once(char::is_whitespace).unwrap();
|
||||
let (_default_level, description) =
|
||||
rest.trim().split_once(char::is_whitespace).unwrap();
|
||||
(name.trim(), Cow::Borrowed(description.trim()))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
lints.extend(stdout[start_lint_groups..end_lint_groups].lines().filter(|l| !l.is_empty()).map(
|
||||
|line| {
|
||||
let (name, lints) = line.trim().split_once(char::is_whitespace).unwrap();
|
||||
(name.trim(), format!("lint group for: {}", lints.trim()).into())
|
||||
},
|
||||
));
|
||||
|
||||
lints.sort_by(|(ident, _), (ident2, _)| ident.cmp(ident2));
|
||||
lints.into_iter().for_each(|(name, description)| push_lint_completion(buf, name, description));
|
||||
lints.into_iter().for_each(|(name, description)| push_lint_completion(buf, name, &description));
|
||||
buf.push_str("];\n");
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user