diff --git a/tasks/ast_codegen/src/util.rs b/tasks/ast_codegen/src/util.rs index 615037ea997d6f..af0dc688f2a560 100644 --- a/tasks/ast_codegen/src/util.rs +++ b/tasks/ast_codegen/src/util.rs @@ -259,9 +259,13 @@ impl TokenStreamExt for TokenStream { } } -pub fn write_all_to>(data: &[u8], path: S) -> std::io::Result<()> { +pub fn write_all_to>(data: &[u8], path: S) -> std::io::Result<()> { use std::{fs, io::Write}; - let mut file = fs::File::create(path.as_ref())?; + let path = path.as_ref(); + if let Some(parent) = path.parent() { + fs::create_dir_all(parent)?; + } + let mut file = fs::File::create(path)?; file.write_all(data)?; Ok(()) }