mirror of
https://github.com/dtolnay/thiserror.git
synced 2025-04-06 06:17:39 +03:00
Update to nightly's new Error::provide API
This commit is contained in:
parent
543e1237d6
commit
8a95c2583e
6 changed files with 78 additions and 83 deletions
|
@ -60,19 +60,19 @@ fn impl_struct(input: Struct) -> TokenStream {
|
|||
});
|
||||
|
||||
let provide_method = input.backtrace_field().map(|backtrace_field| {
|
||||
let demand = quote!(demand);
|
||||
let request = quote!(request);
|
||||
let backtrace = &backtrace_field.member;
|
||||
let body = if let Some(source_field) = input.source_field() {
|
||||
let source = &source_field.member;
|
||||
let source_provide = if type_is_option(source_field.ty) {
|
||||
quote_spanned! {source.span()=>
|
||||
if let std::option::Option::Some(source) = &self.#source {
|
||||
source.thiserror_provide(#demand);
|
||||
source.thiserror_provide(#request);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quote_spanned! {source.span()=>
|
||||
self.#source.thiserror_provide(#demand);
|
||||
self.#source.thiserror_provide(#request);
|
||||
}
|
||||
};
|
||||
let self_provide = if source == backtrace {
|
||||
|
@ -80,12 +80,12 @@ fn impl_struct(input: Struct) -> TokenStream {
|
|||
} else if type_is_option(backtrace_field.ty) {
|
||||
Some(quote! {
|
||||
if let std::option::Option::Some(backtrace) = &self.#backtrace {
|
||||
#demand.provide_ref::<std::backtrace::Backtrace>(backtrace);
|
||||
#request.provide_ref::<std::backtrace::Backtrace>(backtrace);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Some(quote! {
|
||||
#demand.provide_ref::<std::backtrace::Backtrace>(&self.#backtrace);
|
||||
#request.provide_ref::<std::backtrace::Backtrace>(&self.#backtrace);
|
||||
})
|
||||
};
|
||||
quote! {
|
||||
|
@ -96,16 +96,16 @@ fn impl_struct(input: Struct) -> TokenStream {
|
|||
} else if type_is_option(backtrace_field.ty) {
|
||||
quote! {
|
||||
if let std::option::Option::Some(backtrace) = &self.#backtrace {
|
||||
#demand.provide_ref::<std::backtrace::Backtrace>(backtrace);
|
||||
#request.provide_ref::<std::backtrace::Backtrace>(backtrace);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
#demand.provide_ref::<std::backtrace::Backtrace>(&self.#backtrace);
|
||||
#request.provide_ref::<std::backtrace::Backtrace>(&self.#backtrace);
|
||||
}
|
||||
};
|
||||
quote! {
|
||||
fn provide<'_demand>(&'_demand self, #demand: &mut std::any::Demand<'_demand>) {
|
||||
fn provide<'_request>(&'_request self, #request: &mut std::error::Request<'_request>) {
|
||||
#body
|
||||
}
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ fn impl_enum(input: Enum) -> TokenStream {
|
|||
};
|
||||
|
||||
let provide_method = if input.has_backtrace() {
|
||||
let demand = quote!(demand);
|
||||
let request = quote!(request);
|
||||
let arms = input.variants.iter().map(|variant| {
|
||||
let ident = &variant.ident;
|
||||
match (variant.backtrace_field(), variant.source_field()) {
|
||||
|
@ -259,23 +259,23 @@ fn impl_enum(input: Enum) -> TokenStream {
|
|||
let source_provide = if type_is_option(source_field.ty) {
|
||||
quote_spanned! {source.span()=>
|
||||
if let std::option::Option::Some(source) = #varsource {
|
||||
source.thiserror_provide(#demand);
|
||||
source.thiserror_provide(#request);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quote_spanned! {source.span()=>
|
||||
#varsource.thiserror_provide(#demand);
|
||||
#varsource.thiserror_provide(#request);
|
||||
}
|
||||
};
|
||||
let self_provide = if type_is_option(backtrace_field.ty) {
|
||||
quote! {
|
||||
if let std::option::Option::Some(backtrace) = backtrace {
|
||||
#demand.provide_ref::<std::backtrace::Backtrace>(backtrace);
|
||||
#request.provide_ref::<std::backtrace::Backtrace>(backtrace);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
#demand.provide_ref::<std::backtrace::Backtrace>(backtrace);
|
||||
#request.provide_ref::<std::backtrace::Backtrace>(backtrace);
|
||||
}
|
||||
};
|
||||
quote! {
|
||||
|
@ -298,12 +298,12 @@ fn impl_enum(input: Enum) -> TokenStream {
|
|||
let source_provide = if type_is_option(source_field.ty) {
|
||||
quote_spanned! {backtrace.span()=>
|
||||
if let std::option::Option::Some(source) = #varsource {
|
||||
source.thiserror_provide(#demand);
|
||||
source.thiserror_provide(#request);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quote_spanned! {backtrace.span()=>
|
||||
#varsource.thiserror_provide(#demand);
|
||||
#varsource.thiserror_provide(#request);
|
||||
}
|
||||
};
|
||||
quote! {
|
||||
|
@ -318,12 +318,12 @@ fn impl_enum(input: Enum) -> TokenStream {
|
|||
let body = if type_is_option(backtrace_field.ty) {
|
||||
quote! {
|
||||
if let std::option::Option::Some(backtrace) = backtrace {
|
||||
#demand.provide_ref::<std::backtrace::Backtrace>(backtrace);
|
||||
#request.provide_ref::<std::backtrace::Backtrace>(backtrace);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
#demand.provide_ref::<std::backtrace::Backtrace>(backtrace);
|
||||
#request.provide_ref::<std::backtrace::Backtrace>(backtrace);
|
||||
}
|
||||
};
|
||||
quote! {
|
||||
|
@ -338,7 +338,7 @@ fn impl_enum(input: Enum) -> TokenStream {
|
|||
}
|
||||
});
|
||||
Some(quote! {
|
||||
fn provide<'_demand>(&'_demand self, #demand: &mut std::any::Demand<'_demand>) {
|
||||
fn provide<'_request>(&'_request self, #request: &mut std::error::Request<'_request>) {
|
||||
#[allow(deprecated)]
|
||||
match self {
|
||||
#(#arms)*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue