1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//! Common errors of parsing.

use crate::spanned::IntoSpan;

/// Creates a "duplicated attribute's argument" [`syn::Error`] pointing to the
/// given [`Span`].
///
/// [`Span`]: proc_macro2::Span
#[must_use]
pub fn dup_attr_arg<S: IntoSpan>(span: S) -> syn::Error {
    syn::Error::new(span.into_span(), "duplicated attribute's argument found")
}

/// Creates an "unknown attribute's argument" [`syn::Error`] for the given
/// `name` pointing to the given [`Span`].
///
/// [`Span`]: proc_macro2::Span
#[must_use]
pub fn unknown_attr_arg<S: IntoSpan>(span: S, name: &str) -> syn::Error {
    syn::Error::new(
        span.into_span(),
        format!("unknown `{name}` attribute argument"),
    )
}

/// Creates an "expected followed by comma" [`syn::Error`] in the given
/// [`Span`].
///
/// [`Span`]: proc_macro2::Span
#[must_use]
pub fn expected_followed_by_comma<S: IntoSpan>(span: S) -> syn::Error {
    syn::Error::new(span.into_span(), "expected followed by `,`")
}