Skip to content

Commit

Permalink
Make it clearer that the private implementation details are private
Browse files Browse the repository at this point in the history
This was doc(hidden) and commented "Not public API but occasionally
people still try to refer to it anyway.
  • Loading branch information
dtolnay committed Jan 5, 2021
1 parent ebfb8f2 commit 957840e
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 59 deletions.
46 changes: 23 additions & 23 deletions src/custom_keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,23 @@ macro_rules! custom_keyword {
($ident:ident) => {
#[allow(non_camel_case_types)]
pub struct $ident {
pub span: $crate::export::Span,
pub span: $crate::__private::Span,
}

#[doc(hidden)]
#[allow(dead_code, non_snake_case)]
pub fn $ident<__S: $crate::export::IntoSpans<[$crate::export::Span; 1]>>(
pub fn $ident<__S: $crate::__private::IntoSpans<[$crate::__private::Span; 1]>>(
span: __S,
) -> $ident {
$ident {
span: $crate::export::IntoSpans::into_spans(span)[0],
span: $crate::__private::IntoSpans::into_spans(span)[0],
}
}

impl $crate::export::Default for $ident {
impl $crate::__private::Default for $ident {
fn default() -> Self {
$ident {
span: $crate::export::Span::call_site(),
span: $crate::__private::Span::call_site(),
}
}
}
Expand All @@ -127,28 +127,28 @@ macro_rules! impl_parse_for_custom_keyword {
($ident:ident) => {
// For peek.
impl $crate::token::CustomToken for $ident {
fn peek(cursor: $crate::buffer::Cursor) -> $crate::export::bool {
fn peek(cursor: $crate::buffer::Cursor) -> $crate::__private::bool {
if let Some((ident, _rest)) = cursor.ident() {
ident == stringify!($ident)
} else {
false
}
}

fn display() -> &'static $crate::export::str {
fn display() -> &'static $crate::__private::str {
concat!("`", stringify!($ident), "`")
}
}

impl $crate::parse::Parse for $ident {
fn parse(input: $crate::parse::ParseStream) -> $crate::parse::Result<$ident> {
input.step(|cursor| {
if let $crate::export::Some((ident, rest)) = cursor.ident() {
if let $crate::__private::Some((ident, rest)) = cursor.ident() {
if ident == stringify!($ident) {
return $crate::export::Ok(($ident { span: ident.span() }, rest));
return $crate::__private::Ok(($ident { span: ident.span() }, rest));
}
}
$crate::export::Err(cursor.error(concat!(
$crate::__private::Err(cursor.error(concat!(
"expected `",
stringify!($ident),
"`"
Expand All @@ -173,10 +173,10 @@ macro_rules! impl_parse_for_custom_keyword {
#[macro_export]
macro_rules! impl_to_tokens_for_custom_keyword {
($ident:ident) => {
impl $crate::export::ToTokens for $ident {
fn to_tokens(&self, tokens: &mut $crate::export::TokenStream2) {
impl $crate::__private::ToTokens for $ident {
fn to_tokens(&self, tokens: &mut $crate::__private::TokenStream2) {
let ident = $crate::Ident::new(stringify!($ident), self.span);
$crate::export::TokenStreamExt::append(tokens, ident);
$crate::__private::TokenStreamExt::append(tokens, ident);
}
}
};
Expand All @@ -196,9 +196,9 @@ macro_rules! impl_to_tokens_for_custom_keyword {
#[macro_export]
macro_rules! impl_clone_for_custom_keyword {
($ident:ident) => {
impl $crate::export::Copy for $ident {}
impl $crate::__private::Copy for $ident {}

impl $crate::export::Clone for $ident {
impl $crate::__private::Clone for $ident {
fn clone(&self) -> Self {
*self
}
Expand All @@ -220,25 +220,25 @@ macro_rules! impl_clone_for_custom_keyword {
#[macro_export]
macro_rules! impl_extra_traits_for_custom_keyword {
($ident:ident) => {
impl $crate::export::Debug for $ident {
fn fmt(&self, f: &mut $crate::export::Formatter) -> $crate::export::fmt::Result {
$crate::export::Formatter::write_str(
impl $crate::__private::Debug for $ident {
fn fmt(&self, f: &mut $crate::__private::Formatter) -> $crate::__private::fmt::Result {
$crate::__private::Formatter::write_str(
f,
concat!("Keyword [", stringify!($ident), "]"),
)
}
}

impl $crate::export::Eq for $ident {}
impl $crate::__private::Eq for $ident {}

impl $crate::export::PartialEq for $ident {
fn eq(&self, _other: &Self) -> $crate::export::bool {
impl $crate::__private::PartialEq for $ident {
fn eq(&self, _other: &Self) -> $crate::__private::bool {
true
}
}

impl $crate::export::Hash for $ident {
fn hash<__H: $crate::export::Hasher>(&self, _state: &mut __H) {}
impl $crate::__private::Hash for $ident {
fn hash<__H: $crate::__private::Hasher>(&self, _state: &mut __H) {}
}
};
}
Expand Down
36 changes: 18 additions & 18 deletions src/custom_punctuation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,18 @@ macro_rules! custom_punctuation {

#[doc(hidden)]
#[allow(dead_code, non_snake_case)]
pub fn $ident<__S: $crate::export::IntoSpans<$crate::custom_punctuation_repr!($($tt)+)>>(
pub fn $ident<__S: $crate::__private::IntoSpans<$crate::custom_punctuation_repr!($($tt)+)>>(
spans: __S,
) -> $ident {
let _validate_len = 0 $(+ $crate::custom_punctuation_len!(strict, $tt))*;
$ident {
spans: $crate::export::IntoSpans::into_spans(spans)
spans: $crate::__private::IntoSpans::into_spans(spans)
}
}

impl $crate::export::Default for $ident {
impl $crate::__private::Default for $ident {
fn default() -> Self {
$ident($crate::export::Span::call_site())
$ident($crate::__private::Span::call_site())
}
}

Expand All @@ -116,7 +116,7 @@ macro_rules! impl_parse_for_custom_punctuation {
$crate::token::parsing::peek_punct(cursor, $crate::stringify_punct!($($tt)+))
}

fn display() -> &'static $crate::export::str {
fn display() -> &'static $crate::__private::str {
concat!("`", $crate::stringify_punct!($($tt)+), "`")
}
}
Expand Down Expand Up @@ -145,8 +145,8 @@ macro_rules! impl_parse_for_custom_punctuation {
#[macro_export]
macro_rules! impl_to_tokens_for_custom_punctuation {
($ident:ident, $($tt:tt)+) => {
impl $crate::export::ToTokens for $ident {
fn to_tokens(&self, tokens: &mut $crate::export::TokenStream2) {
impl $crate::__private::ToTokens for $ident {
fn to_tokens(&self, tokens: &mut $crate::__private::TokenStream2) {
$crate::token::printing::punct($crate::stringify_punct!($($tt)+), &self.spans, tokens)
}
}
Expand All @@ -167,9 +167,9 @@ macro_rules! impl_to_tokens_for_custom_punctuation {
#[macro_export]
macro_rules! impl_clone_for_custom_punctuation {
($ident:ident, $($tt:tt)+) => {
impl $crate::export::Copy for $ident {}
impl $crate::__private::Copy for $ident {}

impl $crate::export::Clone for $ident {
impl $crate::__private::Clone for $ident {
fn clone(&self) -> Self {
*self
}
Expand All @@ -191,22 +191,22 @@ macro_rules! impl_clone_for_custom_punctuation {
#[macro_export]
macro_rules! impl_extra_traits_for_custom_punctuation {
($ident:ident, $($tt:tt)+) => {
impl $crate::export::Debug for $ident {
fn fmt(&self, f: &mut $crate::export::Formatter) -> $crate::export::fmt::Result {
$crate::export::Formatter::write_str(f, stringify!($ident))
impl $crate::__private::Debug for $ident {
fn fmt(&self, f: &mut $crate::__private::Formatter) -> $crate::__private::fmt::Result {
$crate::__private::Formatter::write_str(f, stringify!($ident))
}
}

impl $crate::export::Eq for $ident {}
impl $crate::__private::Eq for $ident {}

impl $crate::export::PartialEq for $ident {
fn eq(&self, _other: &Self) -> $crate::export::bool {
impl $crate::__private::PartialEq for $ident {
fn eq(&self, _other: &Self) -> $crate::__private::bool {
true
}
}

impl $crate::export::Hash for $ident {
fn hash<__H: $crate::export::Hasher>(&self, _state: &mut __H) {}
impl $crate::__private::Hash for $ident {
fn hash<__H: $crate::__private::Hasher>(&self, _state: &mut __H) {}
}
};
}
Expand All @@ -224,7 +224,7 @@ macro_rules! impl_extra_traits_for_custom_punctuation {
#[macro_export]
macro_rules! custom_punctuation_repr {
($($tt:tt)+) => {
[$crate::export::Span; 0 $(+ $crate::custom_punctuation_len!(lenient, $tt))+]
[$crate::__private::Span; 0 $(+ $crate::custom_punctuation_len!(lenient, $tt))+]
};
}

Expand Down
18 changes: 9 additions & 9 deletions src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ fn parse_delimited<'a>(
macro_rules! parenthesized {
($content:ident in $cursor:expr) => {
match $crate::group::parse_parens(&$cursor) {
$crate::export::Ok(parens) => {
$crate::__private::Ok(parens) => {
$content = parens.content;
parens.token
}
$crate::export::Err(error) => {
return $crate::export::Err(error);
$crate::__private::Err(error) => {
return $crate::__private::Err(error);
}
}
};
Expand Down Expand Up @@ -215,12 +215,12 @@ macro_rules! parenthesized {
macro_rules! braced {
($content:ident in $cursor:expr) => {
match $crate::group::parse_braces(&$cursor) {
$crate::export::Ok(braces) => {
$crate::__private::Ok(braces) => {
$content = braces.content;
braces.token
}
$crate::export::Err(error) => {
return $crate::export::Err(error);
$crate::__private::Err(error) => {
return $crate::__private::Err(error);
}
}
};
Expand Down Expand Up @@ -270,12 +270,12 @@ macro_rules! braced {
macro_rules! bracketed {
($content:ident in $cursor:expr) => {
match $crate::group::parse_brackets(&$cursor) {
$crate::export::Ok(brackets) => {
$crate::__private::Ok(brackets) => {
$content = brackets.content;
brackets.token
}
$crate::export::Err(error) => {
return $crate::export::Err(error);
$crate::__private::Err(error) => {
return $crate::__private::Err(error);
}
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,8 @@ pub use crate::gen::*;

// Not public API.
#[doc(hidden)]
pub mod export;
#[path = "export.rs"]
pub mod __private;

mod custom_keyword;
mod custom_punctuation;
Expand Down
12 changes: 6 additions & 6 deletions src/parse_macro_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@
macro_rules! parse_macro_input {
($tokenstream:ident as $ty:ty) => {
match $crate::parse_macro_input::parse::<$ty>($tokenstream) {
$crate::export::Ok(data) => data,
$crate::export::Err(err) => {
return $crate::export::TokenStream::from(err.to_compile_error());
$crate::__private::Ok(data) => data,
$crate::__private::Err(err) => {
return $crate::__private::TokenStream::from(err.to_compile_error());
}
}
};
($tokenstream:ident with $parser:path) => {
match $crate::parse::Parser::parse($parser, $tokenstream) {
$crate::export::Ok(data) => data,
$crate::export::Err(err) => {
return $crate::export::TokenStream::from(err.to_compile_error());
$crate::__private::Ok(data) => data,
$crate::__private::Err(err) => {
return $crate::__private::TokenStream::from(err.to_compile_error());
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/parse_quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
macro_rules! parse_quote {
($($tt:tt)*) => {
$crate::parse_quote::parse(
$crate::export::From::from(
$crate::export::quote::quote!($($tt)*)
$crate::__private::From::from(
$crate::__private::quote::quote!($($tt)*)
)
)
};
Expand Down

0 comments on commit 957840e

Please sign in to comment.