From d4f50bd3502a5fe7de85489afaa5cb9a9777e9ac Mon Sep 17 00:00:00 2001 From: Theo Bogusta <3322313+theo3@users.noreply.github.com> Date: Tue, 27 Apr 2021 14:48:15 +0000 Subject: [PATCH] Improve Result's Display impl for extension values (#424) Previously, the `Display` impl for `vk::Result` did not include handling for extension values. For example, `VK_ERROR_OUT_OF_DATE_KHR` would display simply as `"-1000001004"`. Now, we fall back to the `Debug` impl of the `Result` if the value is unknown (i.e. from an extension). This preserves the current nice messages for non-extension values, and the numeric output for truly unknown values, but displays the enum variant name (e.g. `"ERROR_OUT_OF_DATE"`) for extension values. --- ash/src/vk/enums.rs | 2 +- generator/src/lib.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ash/src/vk/enums.rs b/ash/src/vk/enums.rs index ca89df3..bcbb6ac 100644 --- a/ash/src/vk/enums.rs +++ b/ash/src/vk/enums.rs @@ -997,7 +997,7 @@ impl fmt::Display for Result { if let Some(x) = name { fmt.write_str(x) } else { - self.0.fmt(fmt) + ::fmt(&self, fmt) } } } diff --git a/generator/src/lib.rs b/generator/src/lib.rs index 1f77d07..9d41cf1 100644 --- a/generator/src/lib.rs +++ b/generator/src/lib.rs @@ -1535,7 +1535,9 @@ pub fn generate_result(ident: Ident, enum_: &vk_parse::Enums) -> TokenStream { if let Some(x) = name { fmt.write_str(x) } else { - self.0.fmt(fmt) + // If we don't have a nice message to show, call the generated `Debug` impl + // which includes *all* enum variants, including those from extensions. + ::fmt(&self, fmt) } } }