dtolnay / syn

Parser for Rust source code
Apache License 2.0
2.82k stars 308 forks source link

Wrong visibility in impl_parse_for_custom_keyword macro ? #1586

Closed Alphapage closed 7 months ago

Alphapage commented 7 months ago

Hello,

I wasn't able to compile my project because of private field in:

macro_rules! impl_parse_for_custom_keyword {
    ($ident:ident) => {
        // For peek.
        impl $crate::__private::CustomToken for $ident {
            fn peek(cursor: $crate::buffer::Cursor) -> $crate::__private::bool { // Error need to change to $crate::__private::buffer::Cursor
                if let $crate::__private::Some((ident, _rest)) = cursor.ident() {
                    ident == $crate::__private::stringify!($ident)
                } else {
                    false
                }
            }

            fn display() -> &'static $crate::__private::str {
                $crate::__private::concat!("`", $crate::__private::stringify!($ident), "`")
            }
        }

        impl $crate::parse::Parse for $ident {
            fn parse(input: $crate::parse::ParseStream) -> $crate::parse::Result<$ident> {
                input.step(|cursor| {
                    if let $crate::__private::Some((ident, rest)) = cursor.ident() {
                        if ident == $crate::__private::stringify!($ident) {
                            return $crate::__private::Ok(($ident { span: ident.span() }, rest));
                        }
                    }
                    $crate::__private::Err(cursor.error($crate::__private::concat!(
                        "expected `",
                        $crate::__private::stringify!($ident),
                        "`",
                    )))
                })
            }
        }
    };
}

Check the comment.

Hope this could help.

dtolnay commented 7 months ago

The code above looks correct to me. What was the error?

Alphapage commented 7 months ago

When compiling winit, it told me to replace $crate::buffer::Cursor by syn::buffer::Cursor, but I replaced by $crate::__private::buffer::Cursor. But it is strange because $crate::buffer::Cursor is public, so I will close the issue as I resolve it by myself and hope it is a one time bug during compilation !