synthez_core/parse/
err.rs

1//! Common errors of parsing.
2
3use crate::spanned::IntoSpan;
4
5/// Creates a "duplicated attribute's argument" [`syn::Error`] pointing to the
6/// given [`Span`].
7///
8/// [`Span`]: proc_macro2::Span
9#[must_use]
10pub fn dup_attr_arg<S: IntoSpan>(span: S) -> syn::Error {
11    syn::Error::new(span.into_span(), "duplicated attribute's argument found")
12}
13
14/// Creates an "unknown attribute's argument" [`syn::Error`] for the given
15/// `name` pointing to the given [`Span`].
16///
17/// [`Span`]: proc_macro2::Span
18#[must_use]
19pub fn unknown_attr_arg<S: IntoSpan>(span: S, name: &str) -> syn::Error {
20    syn::Error::new(
21        span.into_span(),
22        format!("unknown `{name}` attribute argument"),
23    )
24}
25
26/// Creates an "expected followed by comma" [`syn::Error`] in the given
27/// [`Span`].
28///
29/// [`Span`]: proc_macro2::Span
30#[must_use]
31pub fn expected_followed_by_comma<S: IntoSpan>(span: S) -> syn::Error {
32    syn::Error::new(span.into_span(), "expected followed by `,`")
33}