diff --git a/bin/convert.rs b/bin/convert.rs index 151fc29674..978756cffb 100644 --- a/bin/convert.rs +++ b/bin/convert.rs @@ -237,23 +237,12 @@ fn main() { _ => unreachable!(), }; - let file = fs::OpenOptions::new() - .write(true) - .truncate(true) - .create(true) - .open(output_path) - .unwrap(); - - let mut writer = glsl::Writer::new(file, &module, info.as_ref().unwrap(), ¶ms.glsl) - .unwrap_pretty(); - - writer - .write() - .map_err(|e| { - fs::remove_file(output_path).unwrap(); - e - }) - .unwrap(); + let mut buffer = String::new(); + let mut writer = + glsl::Writer::new(&mut buffer, &module, info.as_ref().unwrap(), ¶ms.glsl) + .unwrap_pretty(); + writer.write().unwrap(); + fs::write(output_path, buffer).unwrap(); } #[cfg(feature = "dot-out")] "dot" => { diff --git a/src/back/glsl/features.rs b/src/back/glsl/features.rs index d5c835f9d0..5ae44b71d9 100644 --- a/src/back/glsl/features.rs +++ b/src/back/glsl/features.rs @@ -3,7 +3,7 @@ use crate::{ Binding, Bytes, Handle, ImageClass, ImageDimension, Interpolation, Sampling, ScalarKind, ShaderStage, StorageClass, StorageFormat, Type, TypeInner, }; -use std::io::Write; +use std::fmt::Write; bitflags::bitflags! { /// Structure used to encode a set of additions to glsl that aren't supported by all versions diff --git a/src/back/glsl/mod.rs b/src/back/glsl/mod.rs index 11b4c2fd08..4a5f5d643f 100644 --- a/src/back/glsl/mod.rs +++ b/src/back/glsl/mod.rs @@ -57,7 +57,7 @@ use features::FeaturesManager; use std::{ cmp::Ordering, fmt, - io::{Error as IoError, Write}, + fmt::{Error as FmtError, Write}, }; use thiserror::Error; @@ -271,8 +271,8 @@ type BackendResult = Result<(), Error>; #[derive(Debug, Error)] pub enum Error { /// A error occurred while writing to the output - #[error("I/O error")] - IoError(#[from] IoError), + #[error("Format error")] + FmtError(#[from] FmtError), /// The specified [`Version`](Version) doesn't have all required [`Features`](super) /// /// Contains the missing [`Features`](Features) diff --git a/tests/snapshots.rs b/tests/snapshots.rs index a52b8b6f5e..bbb92b3b41 100644 --- a/tests/snapshots.rs +++ b/tests/snapshots.rs @@ -189,14 +189,12 @@ fn check_output_glsl( entry_point: ep_name.to_string(), }; - let mut buffer = Vec::new(); + let mut buffer = String::new(); let mut writer = glsl::Writer::new(&mut buffer, module, info, &options).unwrap(); writer.write().unwrap(); - let string = String::from_utf8(buffer).unwrap(); - let ext = format!("{:?}.glsl", stage); - fs::write(destination.with_extension(&ext), string).unwrap(); + fs::write(destination.with_extension(&ext), buffer).unwrap(); } #[cfg(feature = "hlsl-out")]