summaryrefslogtreecommitdiff
path: root/src/attr.rs
diff options
context:
space:
mode:
authorJoel Galenson <jgalenson@google.com>2021-10-12 15:50:28 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-10-12 15:50:28 +0000
commitc7b776239decd00f7c0756ca851535bfb17eeeca (patch)
tree6aca7222df527b9db66de4db36ac97a1aa8fdd48 /src/attr.rs
parent7d38e022bd7c1f2ad3c8be3bb677d3a7869292cc (diff)
parent199b724b6942565dc1e489362c0cf06ea9737bb0 (diff)
downloadthiserror-impl-c7b776239decd00f7c0756ca851535bfb17eeeca.tar.gz
Merge "Upgrade rust/crates/thiserror-impl to 1.0.29" am: 9042e02c46 am: b94155e333 am: 6f81fd4b00 am: 199b724b69
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/thiserror-impl/+/1833325 Change-Id: I1f96abf8b9935ab6325525a3d36ba3a2c90b5afd
Diffstat (limited to 'src/attr.rs')
-rw-r--r--src/attr.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/attr.rs b/src/attr.rs
index 1ab1e28..9963fd6 100644
--- a/src/attr.rs
+++ b/src/attr.rs
@@ -1,5 +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::{Nothing, ParseStream};
use syn::{
@@ -21,6 +22,7 @@ pub struct Display<'a> {
pub fmt: LitStr,
pub args: TokenStream,
pub has_bonus_display: bool,
+ pub implied_bounds: Set<(usize, Trait)>,
}
#[derive(Copy, Clone)]
@@ -29,6 +31,19 @@ pub struct Transparent<'a> {
pub span: Span,
}
+#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
+pub enum Trait {
+ Debug,
+ Display,
+ Octal,
+ LowerHex,
+ UpperHex,
+ Pointer,
+ Binary,
+ LowerExp,
+ UpperExp,
+}
+
pub fn get(input: &[Attribute]) -> Result<Attrs> {
let mut attrs = Attrs {
display: None,
@@ -91,6 +106,7 @@ fn parse_error_attribute<'a>(attrs: &mut Attrs<'a>, attr: &'a Attribute) -> Resu
fmt: input.parse()?,
args: parse_token_expr(input, false)?,
has_bonus_display: false,
+ implied_bounds: Set::new(),
};
if attrs.display.is_some() {
return Err(Error::new_spanned(
@@ -188,3 +204,10 @@ impl ToTokens for Display<'_> {
});
}
}
+
+impl ToTokens for Trait {
+ fn to_tokens(&self, tokens: &mut TokenStream) {
+ let trait_name = format_ident!("{}", format!("{:?}", self));
+ tokens.extend(quote!(std::fmt::#trait_name));
+ }
+}