From c7a079d32d33684d70b8a920eeaa10fc1d0a1fc5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 16 Oct 2020 19:47:47 +0200 Subject: [PATCH] Improve compile time a tiny bit --- xtask/src/codegen.rs | 4 ++-- xtask/src/codegen/gen_assists_docs.rs | 2 +- xtask/src/codegen/gen_features.rs | 2 +- xtask/src/codegen/gen_syntax.rs | 15 +++++++++------ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs index 45b17bb482..1e78946174 100644 --- a/xtask/src/codegen.rs +++ b/xtask/src/codegen.rs @@ -77,12 +77,12 @@ fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> { const PREAMBLE: &str = "Generated file, do not edit by hand, see `xtask/src/codegen`"; -fn reformat(text: impl std::fmt::Display) -> Result { +fn reformat(text: &str) -> Result { let _e = pushenv("RUSTUP_TOOLCHAIN", "stable"); ensure_rustfmt()?; let stdout = run!( "rustfmt --config-path {} --config fn_single_line=true", project_root().join("rustfmt.toml").display(); - Result { #(#definitions),* ]; }; - reformat(ts) + reformat(&ts.to_string()) } diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index 733493fef0..02f4095ce8 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs @@ -61,10 +61,13 @@ fn generate_tokens(grammar: &AstSrc) -> Result { } }); - let pretty = reformat(quote! { - use crate::{SyntaxKind::{self, *}, SyntaxToken, ast::AstToken}; - #(#tokens)* - })? + let pretty = reformat( + "e! { + use crate::{SyntaxKind::{self, *}, SyntaxToken, ast::AstToken}; + #(#tokens)* + } + .to_string(), + )? .replace("#[derive", "\n#[derive"); Ok(pretty) } @@ -261,7 +264,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> Result { } } - let pretty = reformat(res)?; + let pretty = reformat(&res)?; Ok(pretty) } @@ -383,7 +386,7 @@ fn generate_syntax_kinds(grammar: KindsSrc<'_>) -> Result { } }; - reformat(ast) + reformat(&ast.to_string()) } fn to_upper_snake_case(s: &str) -> String {