summaryrefslogtreecommitdiffstats
path: root/vendor/thiserror-impl/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/thiserror-impl/src
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/thiserror-impl/src')
-rw-r--r--vendor/thiserror-impl/src/attr.rs38
-rw-r--r--vendor/thiserror-impl/src/expand.rs11
2 files changed, 29 insertions, 20 deletions
diff --git a/vendor/thiserror-impl/src/attr.rs b/vendor/thiserror-impl/src/attr.rs
index 9963fd6db..0b1b89dce 100644
--- a/vendor/thiserror-impl/src/attr.rs
+++ b/vendor/thiserror-impl/src/attr.rs
@@ -2,9 +2,9 @@ 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::{Nothing, ParseStream};
+use syn::parse::ParseStream;
use syn::{
- braced, bracketed, parenthesized, token, Attribute, Error, Ident, Index, LitInt, LitStr,
+ braced, bracketed, parenthesized, token, Attribute, Error, Ident, Index, LitInt, LitStr, Meta,
Result, Token,
};
@@ -54,24 +54,27 @@ pub fn get(input: &[Attribute]) -> Result<Attrs> {
};
for attr in input {
- if attr.path.is_ident("error") {
+ if attr.path().is_ident("error") {
parse_error_attribute(&mut attrs, attr)?;
- } else if attr.path.is_ident("source") {
+ } else if attr.path().is_ident("source") {
require_empty_attribute(attr)?;
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") {
+ } else if attr.path().is_ident("backtrace") {
require_empty_attribute(attr)?;
if attrs.backtrace.is_some() {
return Err(Error::new_spanned(attr, "duplicate #[backtrace] attribute"));
}
attrs.backtrace = Some(attr);
- } else if attr.path.is_ident("from") {
- if !attr.tokens.is_empty() {
- // Assume this is meant for derive_more crate or something.
- continue;
+ } else if attr.path().is_ident("from") {
+ match attr.meta {
+ Meta::Path(_) => {}
+ Meta::List(_) | Meta::NameValue(_) => {
+ // Assume this is meant for derive_more crate or something.
+ continue;
+ }
}
if attrs.from.is_some() {
return Err(Error::new_spanned(attr, "duplicate #[from] attribute"));
@@ -166,21 +169,21 @@ fn parse_token_expr(input: ParseStream, mut begin_expr: bool) -> Result<TokenStr
let delimiter = parenthesized!(content in input);
let nested = parse_token_expr(&content, true)?;
let mut group = Group::new(Delimiter::Parenthesis, nested);
- group.set_span(delimiter.span);
+ group.set_span(delimiter.span.join());
TokenTree::Group(group)
} else if input.peek(token::Brace) {
let content;
let delimiter = braced!(content in input);
let nested = parse_token_expr(&content, true)?;
let mut group = Group::new(Delimiter::Brace, nested);
- group.set_span(delimiter.span);
+ group.set_span(delimiter.span.join());
TokenTree::Group(group)
} else if input.peek(token::Bracket) {
let content;
let delimiter = bracketed!(content in input);
let nested = parse_token_expr(&content, true)?;
let mut group = Group::new(Delimiter::Bracket, nested);
- group.set_span(delimiter.span);
+ group.set_span(delimiter.span.join());
TokenTree::Group(group)
} else {
input.parse()?
@@ -191,8 +194,15 @@ fn parse_token_expr(input: ParseStream, mut begin_expr: bool) -> Result<TokenStr
}
fn require_empty_attribute(attr: &Attribute) -> Result<()> {
- syn::parse2::<Nothing>(attr.tokens.clone())?;
- Ok(())
+ 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<'_> {
diff --git a/vendor/thiserror-impl/src/expand.rs b/vendor/thiserror-impl/src/expand.rs
index 43522096a..ef8eaf31b 100644
--- a/vendor/thiserror-impl/src/expand.rs
+++ b/vendor/thiserror-impl/src/expand.rs
@@ -528,15 +528,14 @@ fn type_parameter_of_option(ty: &Type) -> Option<&Type> {
fn spanned_error_trait(input: &DeriveInput) -> TokenStream {
let vis_span = match &input.vis {
- Visibility::Public(vis) => Some(vis.pub_token.span()),
- Visibility::Crate(vis) => Some(vis.crate_token.span()),
- Visibility::Restricted(vis) => Some(vis.pub_token.span()),
+ Visibility::Public(vis) => Some(vis.span),
+ Visibility::Restricted(vis) => Some(vis.pub_token.span),
Visibility::Inherited => None,
};
let data_span = match &input.data {
- Data::Struct(data) => data.struct_token.span(),
- Data::Enum(data) => data.enum_token.span(),
- Data::Union(data) => data.union_token.span(),
+ Data::Struct(data) => data.struct_token.span,
+ Data::Enum(data) => data.enum_token.span,
+ Data::Union(data) => data.union_token.span,
};
let first_span = vis_span.unwrap_or(data_span);
let last_span = input.ident.span();