diff --git a/src/custom_keyword.rs b/src/custom_keyword.rs index 9f3ad87029..6ce23db41e 100644 --- a/src/custom_keyword.rs +++ b/src/custom_keyword.rs @@ -128,7 +128,7 @@ macro_rules! custom_keyword { macro_rules! impl_parse_for_custom_keyword { ($ident:ident) => { // For peek. - impl $crate::token::CustomToken for $ident { + impl $crate::__private::CustomToken for $ident { fn peek(cursor: $crate::buffer::Cursor) -> $crate::__private::bool { if let $crate::__private::Some((ident, _rest)) = cursor.ident() { ident == $crate::__private::stringify!($ident) diff --git a/src/custom_punctuation.rs b/src/custom_punctuation.rs index 062fe51696..1b2c768f44 100644 --- a/src/custom_punctuation.rs +++ b/src/custom_punctuation.rs @@ -113,7 +113,7 @@ macro_rules! custom_punctuation { #[macro_export] macro_rules! impl_parse_for_custom_punctuation { ($ident:ident, $($tt:tt)+) => { - impl $crate::token::CustomToken for $ident { + impl $crate::__private::CustomToken for $ident { fn peek(cursor: $crate::buffer::Cursor) -> $crate::__private::bool { $crate::__private::peek_punct(cursor, $crate::stringify_punct!($($tt)+)) } diff --git a/src/export.rs b/src/export.rs index febd322e11..b9ea5c747b 100644 --- a/src/export.rs +++ b/src/export.rs @@ -57,6 +57,10 @@ pub use crate::token::parsing::{peek_punct, punct as parse_punct}; #[doc(hidden)] pub use crate::token::printing::punct as print_punct; +#[cfg(feature = "parsing")] +#[doc(hidden)] +pub use crate::token::private::CustomToken; + #[cfg(feature = "proc-macro")] #[doc(hidden)] pub type TokenStream = proc_macro::TokenStream; diff --git a/src/token.rs b/src/token.rs index af7f25c42b..05d8f5601b 100644 --- a/src/token.rs +++ b/src/token.rs @@ -88,6 +88,8 @@ //! [Printing]: https://docs.rs/quote/1.0/quote/trait.ToTokens.html //! [`Span`]: https://docs.rs/proc-macro2/1.0/proc_macro2/struct.Span.html +#[cfg(feature = "parsing")] +pub(crate) use self::private::CustomToken; use self::private::WithSpan; #[cfg(feature = "parsing")] use crate::buffer::Cursor; @@ -134,7 +136,9 @@ pub trait Token: private::Sealed { fn display() -> &'static str; } -mod private { +pub(crate) mod private { + #[cfg(feature = "parsing")] + use crate::buffer::Cursor; use proc_macro2::Span; #[cfg(feature = "parsing")] @@ -147,6 +151,14 @@ mod private { pub struct WithSpan { pub span: Span, } + + // Not public API. + #[doc(hidden)] + #[cfg(feature = "parsing")] + pub trait CustomToken { + fn peek(cursor: Cursor) -> bool; + fn display() -> &'static str; + } } #[cfg(feature = "parsing")] @@ -218,14 +230,6 @@ impl_low_level_token!("punctuation token" Punct punct); impl_low_level_token!("literal" Literal literal); impl_low_level_token!("token" TokenTree token_tree); -// Not public API. -#[doc(hidden)] -#[cfg(feature = "parsing")] -pub trait CustomToken { - fn peek(cursor: Cursor) -> bool; - fn display() -> &'static str; -} - #[cfg(feature = "parsing")] impl private::Sealed for T {}