diff options
Diffstat (limited to 'vendor/thiserror-impl/src')
-rw-r--r-- | vendor/thiserror-impl/src/attr.rs | 19 | ||||
-rw-r--r-- | vendor/thiserror-impl/src/expand.rs | 36 |
2 files changed, 21 insertions, 34 deletions
diff --git a/vendor/thiserror-impl/src/attr.rs b/vendor/thiserror-impl/src/attr.rs index 0b1b89dce..aa71665dd 100644 --- a/vendor/thiserror-impl/src/attr.rs +++ b/vendor/thiserror-impl/src/attr.rs @@ -1,7 +1,6 @@ use proc_macro2::{Delimiter, Group, Span, TokenStream, TokenTree}; use quote::{format_ident, quote, ToTokens}; use std::collections::BTreeSet as Set; -use std::iter::FromIterator; use syn::parse::ParseStream; use syn::{ braced, bracketed, parenthesized, token, Attribute, Error, Ident, Index, LitInt, LitStr, Meta, @@ -57,13 +56,13 @@ pub fn get(input: &[Attribute]) -> Result<Attrs> { if attr.path().is_ident("error") { parse_error_attribute(&mut attrs, attr)?; } else if attr.path().is_ident("source") { - require_empty_attribute(attr)?; + attr.meta.require_path_only()?; if attrs.source.is_some() { return Err(Error::new_spanned(attr, "duplicate #[source] attribute")); } attrs.source = Some(attr); } else if attr.path().is_ident("backtrace") { - require_empty_attribute(attr)?; + attr.meta.require_path_only()?; if attrs.backtrace.is_some() { return Err(Error::new_spanned(attr, "duplicate #[backtrace] attribute")); } @@ -193,24 +192,12 @@ fn parse_token_expr(input: ParseStream, mut begin_expr: bool) -> Result<TokenStr Ok(TokenStream::from_iter(tokens)) } -fn require_empty_attribute(attr: &Attribute) -> Result<()> { - let error_span = match &attr.meta { - Meta::Path(_) => return Ok(()), - Meta::List(meta) => meta.delimiter.span().open(), - Meta::NameValue(meta) => meta.eq_token.span, - }; - Err(Error::new( - error_span, - "unexpected token in thiserror attribute", - )) -} - impl ToTokens for Display<'_> { fn to_tokens(&self, tokens: &mut TokenStream) { let fmt = &self.fmt; let args = &self.args; tokens.extend(quote! { - write!(__formatter, #fmt #args) + std::write!(__formatter, #fmt #args) }); } } diff --git a/vendor/thiserror-impl/src/expand.rs b/vendor/thiserror-impl/src/expand.rs index ef8eaf31b..f6822b205 100644 --- a/vendor/thiserror-impl/src/expand.rs +++ b/vendor/thiserror-impl/src/expand.rs @@ -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)* |