|
1 | 1 | use proc_macro2::{Span, TokenStream}; |
2 | | -use quote::quote; |
| 2 | +use quote::{format_ident, quote}; |
3 | 3 | use syn::{ |
4 | 4 | parse::{Parse, ParseStream}, |
5 | 5 | punctuated::Punctuated, |
6 | | - Data, DeriveInput, Field, Fields, Ident, Meta, PredicateType, QSelf, Token, Type, TypePath, |
7 | | - WhereClause, WherePredicate, |
| 6 | + AngleBracketedGenericArguments, Data, DeriveInput, Field, Fields, GenericArgument, Ident, |
| 7 | + Lifetime, Meta, PathArguments, PredicateType, Token, Type, TypeParamBound, WhereClause, |
| 8 | + WherePredicate, |
8 | 9 | }; |
9 | | -use syn_path::{path, ty}; |
| 10 | +use syn_path::type_path; |
10 | 11 |
|
11 | 12 | #[derive(Debug)] |
12 | 13 | struct WriteableField { |
@@ -168,14 +169,36 @@ pub fn expand_writeable(input: DeriveInput) -> syn::Result<TokenStream> { |
168 | 169 |
|
169 | 170 | // Add a necessary where clause |
170 | 171 | let mut where_clause = where_clause.cloned().unwrap_or(WhereClause { |
171 | | - where_token: Token), |
| 172 | + where_token: Default::default(), |
172 | 173 | predicates: Punctuated::new(), |
173 | 174 | }); |
| 175 | + let mut err_ty = type_path!(<::influxdb::Timestamp as ::core::convert::TryFrom>::Error); |
| 176 | + err_ty |
| 177 | + .path |
| 178 | + .segments |
| 179 | + .iter_mut() |
| 180 | + .nth(err_ty.qself.as_ref().unwrap().position - 1) |
| 181 | + .unwrap() |
| 182 | + .arguments = PathArguments::AngleBracketed(AngleBracketedGenericArguments { |
| 183 | + colon2_token: None, |
| 184 | + lt_token: Default::default(), |
| 185 | + args: [GenericArgument::Type(time_field_ty.clone())] |
| 186 | + .into_iter() |
| 187 | + .collect(), |
| 188 | + gt_token: Default::default(), |
| 189 | + }); |
174 | 190 | where_clause |
175 | 191 | .predicates |
176 | 192 | .push(WherePredicate::Type(PredicateType { |
177 | 193 | lifetimes: None, |
178 | | - bounded_ty: ty!(<::influxdb::Timestamp as ::core::convert::TryFrom>::Error), |
| 194 | + bounded_ty: Type::Path(err_ty), |
| 195 | + colon_token: Default::default(), |
| 196 | + bounds: [TypeParamBound::Lifetime(Lifetime { |
| 197 | + apostrophe: Span::call_site(), |
| 198 | + ident: format_ident!("static"), |
| 199 | + })] |
| 200 | + .into_iter() |
| 201 | + .collect(), |
179 | 202 | })); |
180 | 203 |
|
181 | 204 | // Assemble the rest of the code |
@@ -243,7 +266,7 @@ pub fn expand_writeable(input: DeriveInput) -> syn::Result<TokenStream> { |
243 | 266 | impl<T> ::core::error::Error for Error<T> |
244 | 267 | where |
245 | 268 | Timestamp: TryFrom<T>, |
246 | | - <Timestamp as TryFrom<T>>::Error: ::core::error::Error |
| 269 | + <Timestamp as TryFrom<T>>::Error: ::core::error::Error + 'static |
247 | 270 | { |
248 | 271 | fn source(&self) -> Option<&(dyn ::core::error::Error + 'static)> { |
249 | 272 | match self { |
|
0 commit comments