Skip to content

Commit

Permalink
Merge pull request #1514 from dtolnay/pubnotdoc
Browse files Browse the repository at this point in the history
Work around doc breakage in generate-link-to-definition mode
  • Loading branch information
dtolnay committed Sep 16, 2023
2 parents ce360ff + 7bfef4b commit 6ae1a97
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 25 deletions.
11 changes: 6 additions & 5 deletions src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ use crate::lookahead;
pub use proc_macro2::Ident;

#[cfg(feature = "parsing")]
#[cfg(not(doc))] // Rustdoc bug: does not respect the doc(hidden)
#[doc(hidden)]
#[allow(non_snake_case)]
pub fn Ident(marker: lookahead::TokenMarker) -> Ident {
match marker {}
pub_if_not_doc! {
#[doc(hidden)]
#[allow(non_snake_case)]
pub fn Ident(marker: lookahead::TokenMarker) -> Ident {
match marker {}
}
}

macro_rules! ident_from_token {
Expand Down
11 changes: 6 additions & 5 deletions src/lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ impl Hash for Lifetime {
}

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

#[cfg(feature = "parsing")]
Expand Down
33 changes: 18 additions & 15 deletions src/lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,11 +758,12 @@ macro_rules! lit_extra_traits {
}

#[cfg(feature = "parsing")]
#[cfg(not(doc))] // Rustdoc bug: does not respect the doc(hidden)
#[doc(hidden)]
#[allow(non_snake_case)]
pub fn $ty(marker: lookahead::TokenMarker) -> $ty {
match marker {}
pub_if_not_doc! {
#[doc(hidden)]
#[allow(non_snake_case)]
pub fn $ty(marker: lookahead::TokenMarker) -> $ty {
match marker {}
}
}
};
}
Expand All @@ -775,11 +776,12 @@ lit_extra_traits!(LitInt);
lit_extra_traits!(LitFloat);

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

ast_enum! {
Expand All @@ -796,11 +798,12 @@ ast_enum! {
}

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

#[cfg(feature = "parsing")]
Expand Down
17 changes: 17 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,20 @@ macro_rules! check_keyword_matches {
(enum enum) => {};
(pub pub) => {};
}

// 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 $($item:tt)*) => {
$(#[$m])*
pub(crate) $($item)*
};
}

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

0 comments on commit 6ae1a97

Please sign in to comment.