-
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #395 from dtolnay/fallback
Move fallback expansion to separate module
- Loading branch information
Showing
3 changed files
with
36 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use crate::expand::call_site_ident; | ||
use proc_macro2::TokenStream; | ||
use quote::quote; | ||
use syn::DeriveInput; | ||
|
||
pub(crate) fn expand(input: &DeriveInput, error: syn::Error) -> TokenStream { | ||
let ty = call_site_ident(&input.ident); | ||
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); | ||
|
||
let error = error.to_compile_error(); | ||
|
||
quote! { | ||
#error | ||
|
||
#[allow(unused_qualifications)] | ||
#[automatically_derived] | ||
impl #impl_generics ::thiserror::__private::Error for #ty #ty_generics #where_clause | ||
where | ||
// Work around trivial bounds being unstable. | ||
// https://github.com/rust-lang/rust/issues/48214 | ||
for<'workaround> #ty #ty_generics: ::core::fmt::Debug, | ||
{} | ||
|
||
#[allow(unused_qualifications)] | ||
#[automatically_derived] | ||
impl #impl_generics ::core::fmt::Display for #ty #ty_generics #where_clause { | ||
fn fmt(&self, __formatter: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { | ||
::core::unreachable!() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters