Skip to content

Commit

Permalink
Merge pull request #1683 from dtolnay/peekimpl
Browse files Browse the repository at this point in the history
List peekable token types in documentation of Peek trait
  • Loading branch information
dtolnay authored Jun 20, 2024
2 parents 26ce3d9 + 0c90291 commit 2955706
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::buffer::Cursor;
use crate::error::Result;
use crate::parse::ParseStream;
use crate::parse::Peek;
use crate::sealed::lookahead;
use crate::token::CustomToken;
use proc_macro2::Ident;

Expand Down Expand Up @@ -115,7 +114,8 @@ impl CustomToken for private::IdentAny {
}
}

impl lookahead::Sealed for private::PeekFn {}
#[cfg(not(docsrs))]
impl crate::sealed::lookahead::Sealed for private::PeekFn {}

mod private {
use proc_macro2::Ident;
Expand Down
7 changes: 7 additions & 0 deletions src/ident.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#[cfg(feature = "parsing")]
use crate::lookahead;
#[cfg(all(feature = "parsing", docsrs))]
use crate::lookahead::Peek;

pub use proc_macro2::Ident;

Expand All @@ -12,6 +14,11 @@ pub_if_not_doc! {
}
}

#[cfg(all(feature = "parsing", docsrs))]
impl Peek for Ident {
type Token = Self;
}

macro_rules! ident_from_token {
($token:ident) => {
impl From<Token![$token]> for Ident {
Expand Down
5 changes: 5 additions & 0 deletions src/lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ pub_if_not_doc! {
}
}

#[cfg(all(feature = "parsing", docsrs))]
impl lookahead::Peek for Lifetime {
type Token = Self;
}

#[cfg(feature = "parsing")]
pub(crate) mod parsing {
use crate::error::Result;
Expand Down
15 changes: 15 additions & 0 deletions src/lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,11 @@ macro_rules! lit_extra_traits {
match marker {}
}
}

#[cfg(all(feature = "parsing", docsrs))]
impl lookahead::Peek for $ty {
type Token = Self;
}
};
}

Expand All @@ -827,6 +832,11 @@ pub_if_not_doc! {
}
}

#[cfg(all(feature = "parsing", docsrs))]
impl lookahead::Peek for LitBool {
type Token = Self;
}

/// The style of a string literal, either plain quoted or a raw string like
/// `r##"data"##`.
#[doc(hidden)] // https://github.com/dtolnay/syn/issues/1566
Expand All @@ -848,6 +858,11 @@ pub_if_not_doc! {
}
}

#[cfg(all(feature = "parsing", docsrs))]
impl lookahead::Peek for Lit {
type Token = Self;
}

#[cfg(feature = "parsing")]
pub(crate) mod parsing {
use crate::buffer::Cursor;
Expand Down
1 change: 1 addition & 0 deletions src/lookahead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,5 @@ impl<S> IntoSpans<S> for TokenMarker {
}
}

#[cfg(not(docsrs))]
impl<F: Copy + FnOnce(TokenMarker) -> T, T: Token> Sealed for F {}
7 changes: 7 additions & 0 deletions src/sealed.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#[cfg(feature = "parsing")]
pub(crate) mod lookahead {
#[cfg(not(docsrs))]
pub trait Sealed: Copy {}

#[cfg(docsrs)]
pub trait Sealed {}

#[cfg(docsrs)]
impl<T> Sealed for T {}
}
15 changes: 15 additions & 0 deletions src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ macro_rules! define_keywords {
}
}

#[cfg(all(feature = "parsing", docsrs))]
impl crate::lookahead::Peek for $name {
type Token = Self;
}

impl std::default::Default for $name {
fn default() -> Self {
$name {
Expand Down Expand Up @@ -391,6 +396,11 @@ macro_rules! define_punctuation_structs {
}
}

#[cfg(all(feature = "parsing", docsrs))]
impl crate::lookahead::Peek for $name {
type Token = Self;
}

impl std::default::Default for $name {
fn default() -> Self {
$name {
Expand Down Expand Up @@ -500,6 +510,11 @@ macro_rules! define_delimiters {
}
}

#[cfg(all(feature = "parsing", docsrs))]
impl crate::lookahead::Peek for $name {
type Token = Self;
}

impl std::default::Default for $name {
fn default() -> Self {
$name(Span::call_site())
Expand Down

0 comments on commit 2955706

Please sign in to comment.