1pub trait SpanError {
2 #[allow(non_snake_case)]
3 fn EXPECTED_Span_OR_ToTokens<D: std::fmt::Display>(&self, msg: D) -> syn::Error;
4}
5
6pub trait ToTokensError {
7 #[allow(non_snake_case)]
8 fn EXPECTED_Span_OR_ToTokens<D: std::fmt::Display>(&self, msg: D) -> syn::Error;
9}
10
11impl<T: quote::ToTokens> ToTokensError for T {
12 fn EXPECTED_Span_OR_ToTokens<D: std::fmt::Display>(&self, msg: D) -> syn::Error {
13 // Curb monomorphization from generating too many identical `new_spanned`.
14 syn::Error::new_spanned(self.to_token_stream(), message:msg)
15 }
16}
17
18impl SpanError for proc_macro2::Span {
19 fn EXPECTED_Span_OR_ToTokens<D: std::fmt::Display>(&self, msg: D) -> syn::Error {
20 syn::Error::new(*self, message:msg)
21 }
22}
23