| 1 | use crate::expand::call_site_ident; |
| 2 | use proc_macro2::TokenStream; |
| 3 | use quote::quote; |
| 4 | use syn::DeriveInput; |
| 5 | |
| 6 | pub(crate) fn expand(input: &DeriveInput, error: syn::Error) -> TokenStream { |
| 7 | let ty = call_site_ident(&input.ident); |
| 8 | let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); |
| 9 | |
| 10 | let error = error.to_compile_error(); |
| 11 | |
| 12 | quote! { |
| 13 | #error |
| 14 | |
| 15 | #[allow(unused_qualifications)] |
| 16 | #[automatically_derived] |
| 17 | impl #impl_generics ::thiserror::__private::Error for #ty #ty_generics #where_clause |
| 18 | where |
| 19 | // Work around trivial bounds being unstable. |
| 20 | // https://github.com/rust-lang/rust/issues/48214 |
| 21 | for<'workaround> #ty #ty_generics: ::core::fmt::Debug, |
| 22 | {} |
| 23 | |
| 24 | #[allow(unused_qualifications)] |
| 25 | #[automatically_derived] |
| 26 | impl #impl_generics ::core::fmt::Display for #ty #ty_generics #where_clause { |
| 27 | fn fmt(&self, __formatter: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { |
| 28 | ::core::unreachable!() |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | |