Skip to content

Commit

Permalink
Work around rustdoc's doc(hidden) bug again
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Sep 11, 2024
1 parent 6232266 commit 975ed59
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 75 deletions.
14 changes: 5 additions & 9 deletions src/ident.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
#[cfg(feature = "parsing")]
use crate::lookahead;

pub use proc_macro2::Ident;

#[cfg(feature = "parsing")]
pub_if_not_doc! {
#[doc(hidden)]
#[allow(non_snake_case)]
pub fn Ident(marker: lookahead::TokenMarker) -> Ident {
match marker {}
}
pub(crate) use crate::typed_lookahead::Ident;

pub(crate) mod syntax_tree {
// Type namespace only.
pub use proc_macro2::Ident;
}

macro_rules! ident_from_token {
Expand Down
19 changes: 14 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ pub use crate::generics::{ImplGenerics, Turbofish, TypeGenerics};

mod ident;
#[doc(inline)]
pub use crate::ident::Ident;
pub use crate::ident::syntax_tree::Ident;

#[cfg(feature = "full")]
mod item;
Expand All @@ -425,15 +425,15 @@ pub use crate::item::{

mod lifetime;
#[doc(inline)]
pub use crate::lifetime::Lifetime;
pub use crate::lifetime::syntax_tree::Lifetime;

mod lit;
#[doc(hidden)] // https://github.com/dtolnay/syn/issues/1566
pub use crate::lit::StrStyle;
#[doc(inline)]
pub use crate::lit::{
pub use crate::lit::syntax_tree::{
Lit, LitBool, LitByte, LitByteStr, LitCStr, LitChar, LitFloat, LitInt, LitStr,
};
#[doc(hidden)] // https://github.com/dtolnay/syn/issues/1566
pub use crate::lit::StrStyle;

#[cfg(feature = "parsing")]
mod lookahead;
Expand Down Expand Up @@ -531,6 +531,15 @@ pub use crate::ty::{
TypeSlice, TypeTraitObject, TypeTuple,
};

// These signatures need to be included in the crate root, rather than exported
// via `pub use` from a submodule, due to a rustdoc bug in which rustdoc does
// not respect doc(hidden) on items that are re-exported.
#[cfg(feature = "parsing")]
include!("typed_lookahead.rs");
// Make module get visited by cargo-fmt.
#[cfg(any())]
mod typed_lookahead;

#[cfg(all(any(feature = "full", feature = "derive"), feature = "parsing"))]
mod verbatim;

Expand Down
23 changes: 12 additions & 11 deletions src/lifetime.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
#[cfg(feature = "parsing")]
use crate::lookahead;
use proc_macro2::{Ident, Span};
use std::cmp::Ordering;
use std::fmt::{self, Display};
use std::hash::{Hash, Hasher};

#[cfg(feature = "parsing")]
pub(crate) use crate::typed_lookahead::Lifetime;

pub(crate) mod syntax_tree {
// Type namespace.
pub use crate::lifetime::*;

// Shadow the value namespace.
#[allow(unused_imports)]
use crate::typed_lookahead::Lifetime;
}

/// A Rust lifetime: `'a`.
///
/// Lifetime names must conform to the following rules:
Expand Down Expand Up @@ -111,15 +121,6 @@ impl Hash for Lifetime {
}
}

#[cfg(feature = "parsing")]
pub_if_not_doc! {
#[doc(hidden)]
#[allow(non_snake_case)]
pub fn Lifetime(marker: lookahead::TokenMarker) -> Lifetime {
match marker {}
}
}

#[cfg(feature = "parsing")]
pub(crate) mod parsing {
use crate::error::Result;
Expand Down
46 changes: 17 additions & 29 deletions src/lit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#[cfg(feature = "parsing")]
use crate::lookahead;
#[cfg(feature = "parsing")]
use crate::parse::{Parse, Parser};
use crate::{Error, Result};
use proc_macro2::{Ident, Literal, Span};
Expand All @@ -12,6 +10,23 @@ use std::fmt::{self, Display};
use std::hash::{Hash, Hasher};
use std::str::{self, FromStr};

#[cfg(feature = "parsing")]
pub(crate) use crate::typed_lookahead::{
Lit, LitBool, LitByte, LitByteStr, LitCStr, LitChar, LitFloat, LitInt, LitStr,
};

#[cfg(feature = "parsing")]
pub(crate) mod syntax_tree {
// Type namespace.
pub use crate::lit::*;

// Shadow the value namespace.
#[allow(unused_imports)]
use crate::typed_lookahead::{
Lit, LitBool, LitByte, LitByteStr, LitCStr, LitChar, LitFloat, LitInt, LitStr,
};
}

ast_enum_of_structs! {
/// A Rust literal such as a string or integer or boolean.
///
Expand Down Expand Up @@ -798,15 +813,6 @@ macro_rules! lit_extra_traits {
self.repr.token.to_string().hash(state);
}
}

#[cfg(feature = "parsing")]
pub_if_not_doc! {
#[doc(hidden)]
#[allow(non_snake_case)]
pub fn $ty(marker: lookahead::TokenMarker) -> $ty {
match marker {}
}
}
};
}

Expand All @@ -818,15 +824,6 @@ lit_extra_traits!(LitChar);
lit_extra_traits!(LitInt);
lit_extra_traits!(LitFloat);

#[cfg(feature = "parsing")]
pub_if_not_doc! {
#[doc(hidden)]
#[allow(non_snake_case)]
pub fn LitBool(marker: lookahead::TokenMarker) -> LitBool {
match marker {}
}
}

/// 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 @@ -839,15 +836,6 @@ pub enum StrStyle {
Raw(usize),
}

#[cfg(feature = "parsing")]
pub_if_not_doc! {
#[doc(hidden)]
#[allow(non_snake_case)]
pub fn Lit(marker: lookahead::TokenMarker) -> Lit {
match marker {}
}
}

#[cfg(feature = "parsing")]
pub(crate) mod parsing {
use crate::buffer::Cursor;
Expand Down
21 changes: 0 additions & 21 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,27 +138,6 @@ macro_rules! generate_to_tokens {
};
}

// Rustdoc bug: does not respect the doc(hidden) on some items.
#[cfg(all(doc, feature = "parsing"))]
macro_rules! pub_if_not_doc {
($(#[$m:meta])* $pub:ident $($item:tt)*) => {
check_keyword_matches!(pub $pub);

$(#[$m])*
$pub(crate) $($item)*
};
}

#[cfg(all(not(doc), feature = "parsing"))]
macro_rules! pub_if_not_doc {
($(#[$m:meta])* $pub:ident $($item:tt)*) => {
check_keyword_matches!(pub $pub);

$(#[$m])*
$pub $($item)*
};
}

macro_rules! check_keyword_matches {
(enum enum) => {};
(pub pub) => {};
Expand Down
80 changes: 80 additions & 0 deletions src/typed_lookahead.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#[doc(hidden)]
#[allow(non_snake_case)]
pub fn Ident(marker: lookahead::TokenMarker) -> Ident {
match marker {}
}

#[doc(hidden)]
#[allow(non_snake_case)]
pub fn Lifetime(marker: lookahead::TokenMarker) -> Lifetime {
match marker {}
}

#[doc(hidden)]
#[allow(non_snake_case)]
pub fn Lit(marker: lookahead::TokenMarker) -> Lit {
match marker {}
}

#[doc(hidden)]
#[allow(non_snake_case)]
pub fn LitBool(marker: lookahead::TokenMarker) -> LitBool {
match marker {}
}

#[doc(hidden)]
#[allow(non_snake_case)]
pub fn LitByte(marker: lookahead::TokenMarker) -> LitByte {
match marker {}
}

#[doc(hidden)]
#[allow(non_snake_case)]
pub fn LitByteStr(marker: lookahead::TokenMarker) -> LitByteStr {
match marker {}
}

#[doc(hidden)]
#[allow(non_snake_case)]
pub fn LitCStr(marker: lookahead::TokenMarker) -> LitCStr {
match marker {}
}

#[doc(hidden)]
#[allow(non_snake_case)]
pub fn LitChar(marker: lookahead::TokenMarker) -> LitChar {
match marker {}
}

#[doc(hidden)]
#[allow(non_snake_case)]
pub fn LitFloat(marker: lookahead::TokenMarker) -> LitFloat {
match marker {}
}

#[doc(hidden)]
#[allow(non_snake_case)]
pub fn LitInt(marker: lookahead::TokenMarker) -> LitInt {
match marker {}
}

#[doc(hidden)]
#[allow(non_snake_case)]
pub fn LitStr(marker: lookahead::TokenMarker) -> LitStr {
match marker {}
}

mod typed_lookahead {
// Value namespace.
pub(crate) use crate::*;

// Shadow the type namespace.
#[allow(unused_imports)]
use crate::ident::syntax_tree::Ident;
#[allow(unused_imports)]
use crate::lifetime::syntax_tree::Lifetime;
#[allow(unused_imports)]
use crate::lit::syntax_tree::{
Lit, LitBool, LitByte, LitByteStr, LitCStr, LitChar, LitFloat, LitInt, LitStr,
};
}

0 comments on commit 975ed59

Please sign in to comment.