From 1faea079ed6271f806617a624f6b2ad15d838cd2 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 16 Aug 2023 20:10:47 -0700 Subject: [PATCH] Partially work around ridiculous rust-analyzer behavior --- src/custom_keyword.rs | 2 +- src/custom_punctuation.rs | 2 +- src/export.rs | 39 +++++++++++++++++++++++++++++++++++---- src/group.rs | 8 ++++++++ src/parse_quote.rs | 1 + src/span.rs | 1 + src/token.rs | 3 +++ 7 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/custom_keyword.rs b/src/custom_keyword.rs index 379d159e74..9f3ad87029 100644 --- a/src/custom_keyword.rs +++ b/src/custom_keyword.rs @@ -224,7 +224,7 @@ macro_rules! impl_clone_for_custom_keyword { macro_rules! impl_extra_traits_for_custom_keyword { ($ident:ident) => { impl $crate::__private::Debug for $ident { - fn fmt(&self, f: &mut $crate::__private::Formatter) -> $crate::__private::fmt::Result { + fn fmt(&self, f: &mut $crate::__private::Formatter) -> $crate::__private::FmtResult { $crate::__private::Formatter::write_str( f, $crate::__private::concat!( diff --git a/src/custom_punctuation.rs b/src/custom_punctuation.rs index e8cbcd2feb..dba91c17f9 100644 --- a/src/custom_punctuation.rs +++ b/src/custom_punctuation.rs @@ -195,7 +195,7 @@ macro_rules! impl_clone_for_custom_punctuation { macro_rules! impl_extra_traits_for_custom_punctuation { ($ident:ident, $($tt:tt)+) => { impl $crate::__private::Debug for $ident { - fn fmt(&self, f: &mut $crate::__private::Formatter) -> $crate::__private::fmt::Result { + fn fmt(&self, f: &mut $crate::__private::Formatter) -> $crate::__private::FmtResult { $crate::__private::Formatter::write_str(f, $crate::__private::stringify!($ident)) } } diff --git a/src/export.rs b/src/export.rs index e6d3ffd07c..febd322e11 100644 --- a/src/export.rs +++ b/src/export.rs @@ -1,38 +1,69 @@ +#[doc(hidden)] pub use std::clone::Clone; +#[doc(hidden)] pub use std::cmp::{Eq, PartialEq}; +#[doc(hidden)] pub use std::concat; +#[doc(hidden)] pub use std::default::Default; -pub use std::fmt::{self, Debug, Formatter}; +#[doc(hidden)] +pub use std::fmt::Debug; +#[doc(hidden)] pub use std::hash::{Hash, Hasher}; +#[doc(hidden)] pub use std::marker::Copy; +#[doc(hidden)] pub use std::option::Option::{None, Some}; -pub use std::primitive::{bool, str}; +#[doc(hidden)] pub use std::result::Result::{Err, Ok}; +#[doc(hidden)] pub use std::stringify; +#[doc(hidden)] +pub type Formatter<'a> = std::fmt::Formatter<'a>; +#[doc(hidden)] +pub type FmtResult = std::fmt::Result; + +#[doc(hidden)] +pub type bool = std::primitive::bool; +#[doc(hidden)] +pub type str = std::primitive::str; + #[cfg(feature = "printing")] +#[doc(hidden)] pub use quote; -pub use proc_macro2::{Span, TokenStream as TokenStream2}; +#[doc(hidden)] +pub type Span = proc_macro2::Span; +#[doc(hidden)] +pub type TokenStream2 = proc_macro2::TokenStream; #[cfg(feature = "parsing")] +#[doc(hidden)] pub use crate::group::{parse_braces, parse_brackets, parse_parens}; +#[doc(hidden)] pub use crate::span::IntoSpans; #[cfg(all(feature = "parsing", feature = "printing"))] +#[doc(hidden)] pub use crate::parse_quote::parse as parse_quote; #[cfg(feature = "parsing")] +#[doc(hidden)] pub use crate::token::parsing::{peek_punct, punct as parse_punct}; #[cfg(feature = "printing")] +#[doc(hidden)] pub use crate::token::printing::punct as print_punct; #[cfg(feature = "proc-macro")] -pub use proc_macro::TokenStream; +#[doc(hidden)] +pub type TokenStream = proc_macro::TokenStream; #[cfg(feature = "printing")] +#[doc(hidden)] pub use quote::{ToTokens, TokenStreamExt}; +#[doc(hidden)] pub struct private(pub(crate) ()); diff --git a/src/group.rs b/src/group.rs index cccbc467d0..2730233163 100644 --- a/src/group.rs +++ b/src/group.rs @@ -7,21 +7,27 @@ use proc_macro2::Delimiter; // Not public API. #[doc(hidden)] pub struct Parens<'a> { + #[doc(hidden)] pub token: token::Paren, + #[doc(hidden)] pub content: ParseBuffer<'a>, } // Not public API. #[doc(hidden)] pub struct Braces<'a> { + #[doc(hidden)] pub token: token::Brace, + #[doc(hidden)] pub content: ParseBuffer<'a>, } // Not public API. #[doc(hidden)] pub struct Brackets<'a> { + #[doc(hidden)] pub token: token::Bracket, + #[doc(hidden)] pub content: ParseBuffer<'a>, } @@ -29,7 +35,9 @@ pub struct Brackets<'a> { #[cfg(any(feature = "full", feature = "derive"))] #[doc(hidden)] pub struct Group<'a> { + #[doc(hidden)] pub token: token::Group, + #[doc(hidden)] pub content: ParseBuffer<'a>, } diff --git a/src/parse_quote.rs b/src/parse_quote.rs index f5129439c7..59e51b41ea 100644 --- a/src/parse_quote.rs +++ b/src/parse_quote.rs @@ -120,6 +120,7 @@ pub fn parse(token_stream: TokenStream) -> T { } } +#[doc(hidden)] pub trait ParseQuote: Sized { fn parse(input: ParseStream) -> Result; } diff --git a/src/span.rs b/src/span.rs index 50a26b8337..eb2779479a 100644 --- a/src/span.rs +++ b/src/span.rs @@ -1,6 +1,7 @@ use proc_macro2::extra::DelimSpan; use proc_macro2::{Delimiter, Group, Span, TokenStream}; +#[doc(hidden)] pub trait IntoSpans { fn into_spans(self) -> S; } diff --git a/src/token.rs b/src/token.rs index c140571a95..c7e0e1f1a6 100644 --- a/src/token.rs +++ b/src/token.rs @@ -974,6 +974,7 @@ pub(crate) mod parsing { } } + #[doc(hidden)] pub fn punct(input: ParseStream, token: &str) -> Result<[Span; N]> { let mut spans = [input.span(); N]; punct_helper(input, token, &mut spans)?; @@ -1006,6 +1007,7 @@ pub(crate) mod parsing { }) } + #[doc(hidden)] pub fn peek_punct(mut cursor: Cursor, token: &str) -> bool { for (i, ch) in token.chars().enumerate() { match cursor.punct() { @@ -1033,6 +1035,7 @@ pub(crate) mod printing { use proc_macro2::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream}; use quote::TokenStreamExt; + #[doc(hidden)] pub fn punct(s: &str, spans: &[Span], tokens: &mut TokenStream) { assert_eq!(s.len(), spans.len());