mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Minor cleanups.
- Reduce some function exposure. - Fix some comment formatting.
This commit is contained in:
parent
49908b4d90
commit
b35e576657
@ -229,8 +229,8 @@ fn generate_test(slug: &syn::Path, structure: &Structure<'_>) -> TokenStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
// We need to make sure that the same diagnostic slug can be used multiple times without causing an
|
// We need to make sure that the same diagnostic slug can be used multiple times without
|
||||||
// error, so just have a global counter here.
|
// causing an error, so just have a global counter here.
|
||||||
static COUNTER: AtomicUsize = AtomicUsize::new(0);
|
static COUNTER: AtomicUsize = AtomicUsize::new(0);
|
||||||
let slug = slug.get_ident().unwrap();
|
let slug = slug.get_ident().unwrap();
|
||||||
let ident = quote::format_ident!("verify_{slug}_{}", COUNTER.fetch_add(1, Ordering::Relaxed));
|
let ident = quote::format_ident!("verify_{slug}_{}", COUNTER.fetch_add(1, Ordering::Relaxed));
|
||||||
|
@ -53,6 +53,7 @@ pub(crate) struct DiagnosticDeriveVariantBuilder<'parent> {
|
|||||||
/// Slug is a mandatory part of the struct attribute as corresponds to the Fluent message that
|
/// Slug is a mandatory part of the struct attribute as corresponds to the Fluent message that
|
||||||
/// has the actual diagnostic message.
|
/// has the actual diagnostic message.
|
||||||
pub slug: SpannedOption<Path>,
|
pub slug: SpannedOption<Path>,
|
||||||
|
|
||||||
/// Error codes are a optional part of the struct attribute - this is only set to detect
|
/// Error codes are a optional part of the struct attribute - this is only set to detect
|
||||||
/// multiple specifications.
|
/// multiple specifications.
|
||||||
pub code: SpannedOption<()>,
|
pub code: SpannedOption<()>,
|
||||||
@ -68,7 +69,7 @@ impl DiagnosticDeriveBuilder {
|
|||||||
/// Call `f` for the struct or for each variant of the enum, returning a `TokenStream` with the
|
/// Call `f` for the struct or for each variant of the enum, returning a `TokenStream` with the
|
||||||
/// tokens from `f` wrapped in an `match` expression. Emits errors for use of derive on unions
|
/// tokens from `f` wrapped in an `match` expression. Emits errors for use of derive on unions
|
||||||
/// or attributes on the type itself when input is an enum.
|
/// or attributes on the type itself when input is an enum.
|
||||||
pub fn each_variant<'s, F>(&mut self, structure: &mut Structure<'s>, f: F) -> TokenStream
|
pub(crate) fn each_variant<'s, F>(&mut self, structure: &mut Structure<'s>, f: F) -> TokenStream
|
||||||
where
|
where
|
||||||
F: for<'a, 'v> Fn(DiagnosticDeriveVariantBuilder<'a>, &VariantInfo<'v>) -> TokenStream,
|
F: for<'a, 'v> Fn(DiagnosticDeriveVariantBuilder<'a>, &VariantInfo<'v>) -> TokenStream,
|
||||||
{
|
{
|
||||||
@ -121,7 +122,7 @@ impl DiagnosticDeriveBuilder {
|
|||||||
impl<'a> DiagnosticDeriveVariantBuilder<'a> {
|
impl<'a> DiagnosticDeriveVariantBuilder<'a> {
|
||||||
/// Generates calls to `code` and similar functions based on the attributes on the type or
|
/// Generates calls to `code` and similar functions based on the attributes on the type or
|
||||||
/// variant.
|
/// variant.
|
||||||
pub fn preamble(&mut self, variant: &VariantInfo<'_>) -> TokenStream {
|
pub(crate) fn preamble(&mut self, variant: &VariantInfo<'_>) -> TokenStream {
|
||||||
let ast = variant.ast();
|
let ast = variant.ast();
|
||||||
let attrs = &ast.attrs;
|
let attrs = &ast.attrs;
|
||||||
let preamble = attrs.iter().map(|attr| {
|
let preamble = attrs.iter().map(|attr| {
|
||||||
@ -135,7 +136,7 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
|
|||||||
|
|
||||||
/// Generates calls to `span_label` and similar functions based on the attributes on fields or
|
/// Generates calls to `span_label` and similar functions based on the attributes on fields or
|
||||||
/// calls to `set_arg` when no attributes are present.
|
/// calls to `set_arg` when no attributes are present.
|
||||||
pub fn body(&mut self, variant: &VariantInfo<'_>) -> TokenStream {
|
pub(crate) fn body(&mut self, variant: &VariantInfo<'_>) -> TokenStream {
|
||||||
let mut body = quote! {};
|
let mut body = quote! {};
|
||||||
// Generate `set_arg` calls first..
|
// Generate `set_arg` calls first..
|
||||||
for binding in variant.bindings().iter().filter(|bi| should_generate_set_arg(bi.ast())) {
|
for binding in variant.bindings().iter().filter(|bi| should_generate_set_arg(bi.ast())) {
|
||||||
|
@ -478,7 +478,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_tokens(&mut self) -> Result<TokenStream, DiagnosticDeriveError> {
|
pub(crate) fn into_tokens(&mut self) -> Result<TokenStream, DiagnosticDeriveError> {
|
||||||
let kind_slugs = self.identify_kind()?;
|
let kind_slugs = self.identify_kind()?;
|
||||||
if kind_slugs.is_empty() {
|
if kind_slugs.is_empty() {
|
||||||
if self.is_enum {
|
if self.is_enum {
|
||||||
|
@ -17,7 +17,7 @@ use synstructure::{BindingInfo, VariantInfo};
|
|||||||
use super::error::invalid_attr;
|
use super::error::invalid_attr;
|
||||||
|
|
||||||
thread_local! {
|
thread_local! {
|
||||||
pub static CODE_IDENT_COUNT: RefCell<u32> = RefCell::new(0);
|
pub(crate) static CODE_IDENT_COUNT: RefCell<u32> = RefCell::new(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an ident of the form `__code_N` where `N` is incremented once with every call.
|
/// Returns an ident of the form `__code_N` where `N` is incremented once with every call.
|
||||||
@ -208,7 +208,7 @@ impl<'ty> FieldInnerTy<'ty> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn span(&self) -> proc_macro2::Span {
|
pub(crate) fn span(&self) -> proc_macro2::Span {
|
||||||
match self {
|
match self {
|
||||||
FieldInnerTy::Option(ty) | FieldInnerTy::Vec(ty) | FieldInnerTy::Plain(ty) => ty.span(),
|
FieldInnerTy::Option(ty) | FieldInnerTy::Vec(ty) | FieldInnerTy::Plain(ty) => ty.span(),
|
||||||
}
|
}
|
||||||
@ -537,7 +537,7 @@ impl fmt::Display for SuggestionKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SuggestionKind {
|
impl SuggestionKind {
|
||||||
pub fn to_suggestion_style(&self) -> TokenStream {
|
pub(crate) fn to_suggestion_style(&self) -> TokenStream {
|
||||||
match self {
|
match self {
|
||||||
SuggestionKind::Normal => {
|
SuggestionKind::Normal => {
|
||||||
quote! { rustc_errors::SuggestionStyle::ShowCode }
|
quote! { rustc_errors::SuggestionStyle::ShowCode }
|
||||||
|
@ -38,7 +38,9 @@ fn parse_attributes(field: &syn::Field) -> Attributes {
|
|||||||
attrs
|
attrs
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hash_stable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
|
pub(crate) fn hash_stable_generic_derive(
|
||||||
|
mut s: synstructure::Structure<'_>,
|
||||||
|
) -> proc_macro2::TokenStream {
|
||||||
let generic: syn::GenericParam = parse_quote!(__CTX);
|
let generic: syn::GenericParam = parse_quote!(__CTX);
|
||||||
s.add_bounds(synstructure::AddBounds::Generics);
|
s.add_bounds(synstructure::AddBounds::Generics);
|
||||||
s.add_impl_generic(generic);
|
s.add_impl_generic(generic);
|
||||||
@ -81,7 +83,7 @@ pub fn hash_stable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_ma
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hash_stable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
|
pub(crate) fn hash_stable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
|
||||||
let generic: syn::GenericParam = parse_quote!('__ctx);
|
let generic: syn::GenericParam = parse_quote!('__ctx);
|
||||||
s.add_bounds(synstructure::AddBounds::Generics);
|
s.add_bounds(synstructure::AddBounds::Generics);
|
||||||
s.add_impl_generic(generic);
|
s.add_impl_generic(generic);
|
||||||
|
Loading…
Reference in New Issue
Block a user