| 1 | use quote::ToTokens; |
| 2 | use syn::{spanned::Spanned, Meta}; |
| 3 | |
| 4 | #[inline] |
| 5 | pub(crate) fn union_without_unsafe(meta: &Meta) -> syn::Error { |
| 6 | let mut s = meta.into_token_stream().to_string(); |
| 7 | |
| 8 | match s.len() { |
| 9 | 4 => s.push_str("(unsafe)"), |
| 10 | 6 => s.insert_str(10, "unsafe"), |
| 11 | _ => unreachable!(), |
| 12 | } |
| 13 | |
| 14 | syn::Error::new( |
| 15 | meta.span(), |
| 16 | format!( |
| 17 | "a union's `Hash` implementation is not precise, because it ignores the type of \ |
| 18 | fields\n* If your union doesn't care about that, use `#[educe({s})]` to implement \ |
| 19 | the `Hash` trait for it." |
| 20 | ), |
| 21 | ) |
| 22 | } |