mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:47 +00:00
Disallow unreachable_pub
(#4314)
This commit is contained in:
parent
97802e7466
commit
c10a4535b9
444 changed files with 1376 additions and 1106 deletions
|
@ -3,7 +3,7 @@ use quote::{format_ident, quote};
|
|||
use syn::spanned::Spanned;
|
||||
use syn::{Data, DeriveInput, Error, Fields};
|
||||
|
||||
pub fn derive_cache_key(item: &DeriveInput) -> syn::Result<TokenStream> {
|
||||
pub(crate) fn derive_cache_key(item: &DeriveInput) -> syn::Result<TokenStream> {
|
||||
let fields = match &item.data {
|
||||
Data::Enum(item_enum) => {
|
||||
let arms = item_enum.variants.iter().enumerate().map(|(i, variant)| {
|
||||
|
|
|
@ -7,7 +7,7 @@ use syn::{
|
|||
Fields, Lit, LitStr, Path, PathArguments, PathSegment, Token, Type, TypePath,
|
||||
};
|
||||
|
||||
pub fn derive_impl(input: DeriveInput) -> syn::Result<proc_macro2::TokenStream> {
|
||||
pub(crate) fn derive_impl(input: DeriveInput) -> syn::Result<proc_macro2::TokenStream> {
|
||||
let DeriveInput { ident, data, .. } = input;
|
||||
|
||||
match data {
|
||||
|
|
|
@ -3,7 +3,7 @@ use quote::{quote, quote_spanned, ToTokens};
|
|||
use syn::spanned::Spanned;
|
||||
use syn::{Block, Expr, ItemFn, Stmt};
|
||||
|
||||
pub fn derive_message_formats(func: &ItemFn) -> proc_macro2::TokenStream {
|
||||
pub(crate) fn derive_message_formats(func: &ItemFn) -> proc_macro2::TokenStream {
|
||||
let mut strings = quote!();
|
||||
|
||||
if let Err(err) = parse_block(&func.block, &mut strings) {
|
||||
|
|
|
@ -10,7 +10,7 @@ use syn::{
|
|||
|
||||
use crate::rule_code_prefix::{get_prefix_ident, if_all_same};
|
||||
|
||||
pub fn map_codes(func: &ItemFn) -> syn::Result<TokenStream> {
|
||||
pub(crate) fn map_codes(func: &ItemFn) -> syn::Result<TokenStream> {
|
||||
let Some(last_stmt) = func.block.stmts.last() else {
|
||||
return Err(Error::new(func.block.span(), "expected body to end in an expression"));
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@ use quote::quote;
|
|||
use syn::parse::Parse;
|
||||
use syn::{Attribute, Ident, Path, Token};
|
||||
|
||||
pub fn register_rules(input: &Input) -> proc_macro2::TokenStream {
|
||||
pub(crate) fn register_rules(input: &Input) -> proc_macro2::TokenStream {
|
||||
let mut rule_variants = quote!();
|
||||
let mut rule_message_formats_match_arms = quote!();
|
||||
let mut rule_autofixable_match_arms = quote!();
|
||||
|
@ -74,7 +74,7 @@ pub fn register_rules(input: &Input) -> proc_macro2::TokenStream {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct Input {
|
||||
pub(crate) struct Input {
|
||||
entries: Vec<(Path, Ident, Vec<Attribute>)>,
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use proc_macro2::Span;
|
|||
use quote::quote;
|
||||
use syn::{Attribute, Ident};
|
||||
|
||||
pub fn get_prefix_ident(prefix: &str) -> Ident {
|
||||
pub(crate) fn get_prefix_ident(prefix: &str) -> Ident {
|
||||
let prefix = if prefix.as_bytes()[0].is_ascii_digit() {
|
||||
// Identifiers in Rust may not start with a number.
|
||||
format!("_{prefix}")
|
||||
|
@ -14,7 +14,7 @@ pub fn get_prefix_ident(prefix: &str) -> Ident {
|
|||
Ident::new(&prefix, Span::call_site())
|
||||
}
|
||||
|
||||
pub fn expand<'a>(
|
||||
pub(crate) fn expand<'a>(
|
||||
prefix_ident: &Ident,
|
||||
variants: impl Iterator<Item = (&'a str, &'a Vec<Attribute>)>,
|
||||
) -> proc_macro2::TokenStream {
|
||||
|
@ -106,7 +106,7 @@ fn attributes_for_prefix(
|
|||
|
||||
/// If all values in an iterator are the same, return that value. Otherwise,
|
||||
/// return `None`.
|
||||
pub fn if_all_same<T: PartialEq>(iter: impl Iterator<Item = T>) -> Option<T> {
|
||||
pub(crate) fn if_all_same<T: PartialEq>(iter: impl Iterator<Item = T>) -> Option<T> {
|
||||
let mut iter = iter.peekable();
|
||||
let first = iter.next()?;
|
||||
if iter.all(|x| x == first) {
|
||||
|
|
|
@ -5,7 +5,7 @@ use quote::quote;
|
|||
use syn::spanned::Spanned;
|
||||
use syn::{Attribute, Data, DataEnum, DeriveInput, Error, ExprLit, Lit, Meta, MetaNameValue};
|
||||
|
||||
pub fn derive_impl(input: DeriveInput) -> syn::Result<proc_macro2::TokenStream> {
|
||||
pub(crate) fn derive_impl(input: DeriveInput) -> syn::Result<proc_macro2::TokenStream> {
|
||||
let DeriveInput { ident, data: Data::Enum(DataEnum {
|
||||
variants, ..
|
||||
}), .. } = input else {
|
||||
|
|
|
@ -45,7 +45,7 @@ fn get_docs(attrs: &[Attribute]) -> Result<String> {
|
|||
Ok(explanation)
|
||||
}
|
||||
|
||||
pub fn violation(violation: &ItemStruct) -> Result<TokenStream> {
|
||||
pub(crate) fn violation(violation: &ItemStruct) -> Result<TokenStream> {
|
||||
let ident = &violation.ident;
|
||||
let explanation = get_docs(&violation.attrs)?;
|
||||
let violation = if explanation.trim().is_empty() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue