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 {