11use crate :: ast:: { Enum , Field , Input , Struct } ;
22use crate :: attr:: Trait ;
3+ use crate :: fallback;
34use crate :: generics:: InferredBounds ;
45use crate :: unraw:: MemberUnraw ;
56use proc_macro2:: { Ident , Span , TokenStream } ;
@@ -13,7 +14,7 @@ pub fn derive(input: &DeriveInput) -> TokenStream {
1314 // If there are invalid attributes in the input, expand to an Error impl
1415 // anyway to minimize spurious knock-on errors in other code that uses
1516 // this type as an Error.
16- Err ( error) => fallback ( input, error) ,
17+ Err ( error) => fallback:: expand ( input, error) ,
1718 }
1819}
1920
@@ -26,34 +27,6 @@ fn try_expand(input: &DeriveInput) -> Result<TokenStream> {
2627 } )
2728}
2829
29- fn fallback ( input : & DeriveInput , error : syn:: Error ) -> TokenStream {
30- let ty = call_site_ident ( & input. ident ) ;
31- let ( impl_generics, ty_generics, where_clause) = input. generics . split_for_impl ( ) ;
32-
33- let error = error. to_compile_error ( ) ;
34-
35- quote ! {
36- #error
37-
38- #[ allow( unused_qualifications) ]
39- #[ automatically_derived]
40- impl #impl_generics :: thiserror:: __private:: Error for #ty #ty_generics #where_clause
41- where
42- // Work around trivial bounds being unstable.
43- // https://github.com/rust-lang/rust/issues/48214
44- for <' workaround> #ty #ty_generics: :: core:: fmt:: Debug ,
45- { }
46-
47- #[ allow( unused_qualifications) ]
48- #[ automatically_derived]
49- impl #impl_generics :: core:: fmt:: Display for #ty #ty_generics #where_clause {
50- fn fmt( & self , __formatter: & mut :: core:: fmt:: Formatter ) -> :: core:: fmt:: Result {
51- :: core:: unreachable!( )
52- }
53- }
54- }
55- }
56-
5730fn impl_struct ( input : Struct ) -> TokenStream {
5831 let ty = call_site_ident ( & input. ident ) ;
5932 let ( impl_generics, ty_generics, where_clause) = input. generics . split_for_impl ( ) ;
@@ -494,7 +467,7 @@ fn impl_enum(input: Enum) -> TokenStream {
494467
495468// Create an ident with which we can expand `impl Trait for #ident {}` on a
496469// deprecated type without triggering deprecation warning on the generated impl.
497- fn call_site_ident ( ident : & Ident ) -> Ident {
470+ pub ( crate ) fn call_site_ident ( ident : & Ident ) -> Ident {
498471 let mut ident = ident. clone ( ) ;
499472 ident. set_span ( ident. span ( ) . resolved_at ( Span :: call_site ( ) ) ) ;
500473 ident
0 commit comments