aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/codegen/gen_features.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-02-27 14:56:24 +0000
committerGitHub <[email protected]>2021-02-27 14:56:24 +0000
commitf682627da4be4777fa0c1527398ef4136cd929b1 (patch)
tree31317659408bc153c113df7b839582d7ba974c78 /xtask/src/codegen/gen_features.rs
parenta8cf346b972b5e79a3b18de5a7f71e49a228be7c (diff)
parent351670f6201d7ceabaec3e4b79e5dcf4c5048e12 (diff)
Merge #7797
7797: Format generated lints and features manually r=matklad a=lnicola As `quote` and `rustfmt` leave them on a single line, which makes running `grep` in the repository quite annoying. Also removes a dead `gen_features.rs` file (`gen_lint_completions.rs` does the same thing). Co-authored-by: LaurenČ›iu Nicola <[email protected]>
Diffstat (limited to 'xtask/src/codegen/gen_features.rs')
-rw-r--r--xtask/src/codegen/gen_features.rs48
1 files changed, 0 insertions, 48 deletions
diff --git a/xtask/src/codegen/gen_features.rs b/xtask/src/codegen/gen_features.rs
deleted file mode 100644
index 3cf15ce02..000000000
--- a/xtask/src/codegen/gen_features.rs
+++ /dev/null
@@ -1,48 +0,0 @@
1//! Generates descriptors structure for unstable feature from Unstable Book
2use std::path::{Path, PathBuf};
3
4use quote::quote;
5use walkdir::WalkDir;
6use xshell::{cmd, read_file};
7
8use crate::codegen::{project_root, reformat, update, Mode, Result};
9
10pub fn generate_features(mode: Mode) -> Result<()> {
11 if !Path::new("./target/rust").exists() {
12 cmd!("git clone https://github.com/rust-lang/rust ./target/rust").run()?;
13 }
14
15 let contents = generate_descriptor("./target/rust/src/doc/unstable-book/src".into())?;
16
17 let destination = project_root().join("crates/ide/src/completion/generated_features.rs");
18 update(destination.as_path(), &contents, mode)?;
19
20 Ok(())
21}
22
23fn generate_descriptor(src_dir: PathBuf) -> Result<String> {
24 let definitions = ["language-features", "library-features"]
25 .iter()
26 .flat_map(|it| WalkDir::new(src_dir.join(it)))
27 .filter_map(|e| e.ok())
28 .filter(|entry| {
29 // Get all `.md ` files
30 entry.file_type().is_file() && entry.path().extension().unwrap_or_default() == "md"
31 })
32 .map(|entry| {
33 let path = entry.path();
34 let feature_ident = path.file_stem().unwrap().to_str().unwrap().replace("-", "_");
35 let doc = read_file(path).unwrap();
36
37 quote! { LintCompletion { label: #feature_ident, description: #doc } }
38 });
39
40 let ts = quote! {
41 use crate::completion::complete_attribute::LintCompletion;
42
43 pub(super) const FEATURES: &[LintCompletion] = &[
44 #(#definitions),*
45 ];
46 };
47 reformat(&ts.to_string())
48}