diff options
Diffstat (limited to 'xtask/src/codegen')
-rw-r--r-- | xtask/src/codegen/gen_lint_completions.rs | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/xtask/src/codegen/gen_lint_completions.rs b/xtask/src/codegen/gen_lint_completions.rs index d56b23218..b797067cd 100644 --- a/xtask/src/codegen/gen_lint_completions.rs +++ b/xtask/src/codegen/gen_lint_completions.rs | |||
@@ -1,4 +1,5 @@ | |||
1 | //! Generates descriptors structure for unstable feature from Unstable Book | 1 | //! Generates descriptors structure for unstable feature from Unstable Book |
2 | use std::borrow::Cow; | ||
2 | use std::fmt::Write; | 3 | use std::fmt::Write; |
3 | use std::path::{Path, PathBuf}; | 4 | use std::path::{Path, PathBuf}; |
4 | 5 | ||
@@ -38,22 +39,36 @@ pub(crate) fn generate_lint_completions() -> Result<()> { | |||
38 | 39 | ||
39 | fn generate_lint_descriptor(buf: &mut String) -> Result<()> { | 40 | fn generate_lint_descriptor(buf: &mut String) -> Result<()> { |
40 | let stdout = cmd!("rustc -W help").read()?; | 41 | let stdout = cmd!("rustc -W help").read()?; |
41 | let start = stdout.find("---- ------- -------").ok_or_else(|| anyhow::format_err!(""))?; | 42 | let start_lints = |
42 | let end = | 43 | stdout.find("---- ------- -------").ok_or_else(|| anyhow::format_err!(""))?; |
43 | stdout.rfind("Lint groups provided by rustc:").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!(""))?; | ||
44 | buf.push_str(r#"pub const DEFAULT_LINTS: &[Lint] = &["#); | 51 | buf.push_str(r#"pub const DEFAULT_LINTS: &[Lint] = &["#); |
45 | buf.push('\n'); | 52 | buf.push('\n'); |
46 | let mut lints = stdout[start..end] | 53 | let mut lints = stdout[start_lints..end_lints] |
47 | .lines() | 54 | .lines() |
48 | .filter(|l| !l.is_empty()) | 55 | .filter(|l| !l.is_empty()) |
49 | .flat_map(|line| { | 56 | .map(|line| { |
50 | let (name, rest) = line.trim().split_once(char::is_whitespace)?; | 57 | let (name, rest) = line.trim().split_once(char::is_whitespace).unwrap(); |
51 | let (_default_level, description) = rest.trim().split_once(char::is_whitespace)?; | 58 | let (_default_level, description) = |
52 | Some((name.trim(), description.trim())) | 59 | rest.trim().split_once(char::is_whitespace).unwrap(); |
60 | (name.trim(), Cow::Borrowed(description.trim())) | ||
53 | }) | 61 | }) |
54 | .collect::<Vec<_>>(); | 62 | .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 | |||
55 | lints.sort_by(|(ident, _), (ident2, _)| ident.cmp(ident2)); | 70 | 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)); |
57 | buf.push_str("];\n"); | 72 | buf.push_str("];\n"); |
58 | Ok(()) | 73 | Ok(()) |
59 | } | 74 | } |