From ac4e38a3d99f0b1a9fa4ecaddb54ac9b4ed47c0b Mon Sep 17 00:00:00 2001 From: Aaron Loucks Date: Sat, 16 Mar 2019 12:56:27 -0400 Subject: [PATCH] Remove deprecated method impls for std Error --- ash/src/entry.rs | 23 ++--------------------- ash/src/vk.rs | 37 +------------------------------------ ash/tests/display.rs | 9 --------- generator/src/lib.rs | 35 +++++++---------------------------- 4 files changed, 10 insertions(+), 94 deletions(-) diff --git a/ash/src/entry.rs b/ash/src/entry.rs index f000764..b17fa0a 100644 --- a/ash/src/entry.rs +++ b/ash/src/entry.rs @@ -50,15 +50,7 @@ impl fmt::Display for LoadingError { } } -impl Error for LoadingError { - fn description(&self) -> &str { - "LoadingError" - } - - fn cause(&self) -> Option<&Error> { - None - } -} +impl Error for LoadingError {} #[derive(Debug)] pub enum InstanceError { @@ -72,18 +64,7 @@ impl fmt::Display for InstanceError { } } -impl Error for InstanceError { - fn description(&self) -> &str { - "InstanceError" - } - - fn cause(&self) -> Option<&Error> { - if let &InstanceError::VkError(ref err) = self { - return err.source(); - } - None - } -} +impl Error for InstanceError {} #[allow(non_camel_case_types)] pub trait EntryV1_0 { diff --git a/ash/src/vk.rs b/ash/src/vk.rs index a843d70..1fa4412 100644 --- a/ash/src/vk.rs +++ b/ash/src/vk.rs @@ -41314,42 +41314,7 @@ impl Result { #[doc = "A requested pool allocation has failed due to fragmentation of the pool\'s memory"] pub const ERROR_FRAGMENTED_POOL: Self = Result(-12); } -impl ::std::error::Error for Result { - fn description(&self) -> &str { - let name = match *self { - Result::SUCCESS => Some("Command completed successfully"), - Result::NOT_READY => Some("A fence or query has not yet completed"), - Result::TIMEOUT => Some("A wait operation has not completed in the specified time"), - Result::EVENT_SET => Some("An event is signaled"), - Result::EVENT_RESET => Some("An event is unsignaled"), - Result::INCOMPLETE => Some("A return array was too small for the result"), - Result::ERROR_OUT_OF_HOST_MEMORY => Some("A host memory allocation has failed"), - Result::ERROR_OUT_OF_DEVICE_MEMORY => Some("A device memory allocation has failed"), - Result::ERROR_INITIALIZATION_FAILED => Some("Initialization of a object has failed"), - Result::ERROR_DEVICE_LOST => { - Some("The logical device has been lost. See <>") - } - Result::ERROR_MEMORY_MAP_FAILED => Some("Mapping of a memory object has failed"), - Result::ERROR_LAYER_NOT_PRESENT => Some("Layer specified does not exist"), - Result::ERROR_EXTENSION_NOT_PRESENT => Some("Extension specified does not exist"), - Result::ERROR_FEATURE_NOT_PRESENT => { - Some("Requested feature is not available on this device") - } - Result::ERROR_INCOMPATIBLE_DRIVER => Some("Unable to find a Vulkan driver"), - Result::ERROR_TOO_MANY_OBJECTS => { - Some("Too many objects of the type have already been created") - } - Result::ERROR_FORMAT_NOT_SUPPORTED => { - Some("Requested format is not supported on this device") - } - Result::ERROR_FRAGMENTED_POOL => Some( - "A requested pool allocation has failed due to fragmentation of the pool\'s memory", - ), - _ => None, - }; - name.unwrap_or("unknown error") - } -} +impl std::error::Error for Result {} impl fmt::Display for Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { let name = match *self { diff --git a/ash/tests/display.rs b/ash/tests/display.rs index 7a510bd..c05dea7 100644 --- a/ash/tests/display.rs +++ b/ash/tests/display.rs @@ -19,12 +19,3 @@ fn display_enum() { fn display_result() { assert_eq!(vk::Result::SUCCESS.to_string(), "SUCCESS"); } - -#[test] -fn error_result_description() { - use std::error::Error; - assert_eq!( - vk::Result::SUCCESS.description(), - "Command completed successfully" - ); -} diff --git a/generator/src/lib.rs b/generator/src/lib.rs index 3bcc4c0..4dcca97 100644 --- a/generator/src/lib.rs +++ b/generator/src/lib.rs @@ -15,9 +15,9 @@ use itertools::Itertools; use proc_macro2::{Literal, Term}; use quote::Tokens; use std::collections::{BTreeMap, HashMap, HashSet}; +use std::fmt::Display; use std::path::Path; use syn::Ident; -use std::fmt::Display; pub trait ExtensionExt {} #[derive(Copy, Clone, Debug)] @@ -88,7 +88,10 @@ named!(cfloat<&str, f32>, ); fn khronos_link(name: &S) -> Literal { - Literal::string(&format!("", name=name)) + Literal::string(&format!( + "", + name = name + )) } pub fn define_handle_macro() -> Tokens { @@ -1210,23 +1213,6 @@ pub fn generate_enum<'a>( } pub fn generate_result(ident: Ident, _enum: &vkxml::Enumeration) -> Tokens { - let description_notation = _enum.elements.iter().filter_map(|elem| { - let (variant_name, notation) = match *elem { - vkxml::EnumerationElement::Enum(ref constant) => ( - constant.name.as_str(), - constant.notation.as_ref().map(|s| s.as_str()).unwrap_or(""), - ), - _ => { - return None; - } - }; - - let variant_ident = variant_ident(&_enum.name, variant_name); - Some(quote! { - #ident::#variant_ident => Some(#notation) - }) - }); - let display_notation = _enum.elements.iter().filter_map(|elem| { let variant_name = match *elem { vkxml::EnumerationElement::Enum(ref constant) => constant.name.as_str(), @@ -1242,15 +1228,8 @@ pub fn generate_result(ident: Ident, _enum: &vkxml::Enumeration) -> Tokens { }); quote! { - impl ::std::error::Error for #ident { - fn description(&self) -> &str { - let name = match *self { - #(#description_notation),*, - _ => None, - }; - name.unwrap_or("unknown error") - } - } + impl std::error::Error for #ident {} + impl fmt::Display for #ident { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { let name = match *self {