Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ wasm-bindgen = "0.2.106"
unsafe_code = "allow"
unsafe_op_in_unsafe_fn = "deny"
elided_lifetimes_in_paths = "warn"
unreachable_pub = "warn"

[workspace.lints.clippy]
alloc_instead_of_core = "warn"
Expand Down
16 changes: 8 additions & 8 deletions crates/codegen/src/symboltable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ type SymbolMap = IndexMap<String, Symbol>;
mod stack {
use alloc::vec::Vec;
use core::ptr::NonNull;
pub struct StackStack<T> {
pub(super) struct StackStack<T> {
v: Vec<NonNull<T>>,
}
impl<T> Default for StackStack<T> {
Expand All @@ -403,7 +403,7 @@ mod stack {
/// Appends a reference to this stack for the duration of the function `f`. When `f`
/// returns, the reference will be popped off the stack.
#[cfg(feature = "std")]
pub fn with_append<F, R>(&mut self, x: &mut T, f: F) -> R
pub(super) fn with_append<F, R>(&mut self, x: &mut T, f: F) -> R
where
F: FnOnce(&mut Self) -> R,
{
Expand All @@ -428,10 +428,10 @@ mod stack {
result
}

pub fn iter(&self) -> impl DoubleEndedIterator<Item = &T> + '_ {
pub(super) fn iter(&self) -> impl DoubleEndedIterator<Item = &T> + '_ {
self.as_ref().iter().copied()
}
pub fn iter_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut T> + '_ {
pub(super) fn iter_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut T> + '_ {
self.as_mut().iter_mut().map(|x| &mut **x)
}
// pub fn top(&self) -> Option<&T> {
Expand All @@ -440,18 +440,18 @@ mod stack {
// pub fn top_mut(&mut self) -> Option<&mut T> {
// self.as_mut().last_mut().map(|x| &mut **x)
// }
pub fn len(&self) -> usize {
pub(super) fn len(&self) -> usize {
self.v.len()
}
pub fn is_empty(&self) -> bool {
pub(super) fn is_empty(&self) -> bool {
self.len() == 0
}

pub fn as_ref(&self) -> &[&T] {
pub(super) fn as_ref(&self) -> &[&T] {
unsafe { &*(self.v.as_slice() as *const [NonNull<T>] as *const [&T]) }
}

pub fn as_mut(&mut self) -> &mut [&mut T] {
pub(super) fn as_mut(&mut self) -> &mut [&mut T] {
unsafe { &mut *(self.v.as_mut_slice() as *mut [NonNull<T>] as *mut [&mut T]) }
}
}
Expand Down
12 changes: 7 additions & 5 deletions crates/codegen/src/unparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@ use ruff_text_size::Ranged;
use rustpython_compiler_core::SourceFile;
use rustpython_literal::escape::{AsciiEscape, UnicodeEscape};

mod precedence {
pub(crate) mod precedence {
macro_rules! precedence {
($($op:ident,)*) => {
precedence!(@0, $($op,)*);
};
(@$i:expr, $op1:ident, $($op:ident,)*) => {
pub const $op1: u8 = $i;
pub(crate) const $op1: u8 = $i;
precedence!(@$i + 1, $($op,)*);
};
(@$i:expr,) => {};
}

precedence!(
TUPLE, TEST, OR, AND, NOT, CMP, // "EXPR" =
BOR, BXOR, BAND, SHIFT, ARITH, TERM, FACTOR, POWER, AWAIT, ATOM,
);
pub const EXPR: u8 = BOR;

pub(crate) const EXPR: u8 = BOR;
}

struct Unparser<'a, 'b, 'c> {
Expand Down Expand Up @@ -653,13 +655,13 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
}
}

pub struct UnparseExpr<'a> {
pub(crate) struct UnparseExpr<'a> {
expr: &'a ast::Expr,
source: &'a SourceFile,
}

impl<'a> UnparseExpr<'a> {
pub const fn new(expr: &'a ast::Expr, source: &'a SourceFile) -> Self {
pub(crate) const fn new(expr: &'a ast::Expr, source: &'a SourceFile) -> Self {
Self { expr, source }
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/derive-impl/src/compile_bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ struct PyCompileArgs {
crate_name: syn::Path,
}

pub fn impl_py_compile(
pub(crate) fn impl_py_compile(
input: TokenStream,
compiler: &dyn Compiler,
) -> Result<TokenStream, Diagnostic> {
Expand All @@ -356,7 +356,7 @@ pub fn impl_py_compile(
Ok(output)
}

pub fn impl_py_freeze(
pub(crate) fn impl_py_freeze(
input: TokenStream,
compiler: &dyn Compiler,
) -> Result<TokenStream, Diagnostic> {
Expand Down
10 changes: 5 additions & 5 deletions crates/derive-impl/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ macro_rules! bail_span {
// }

#[derive(Debug)]
pub struct Diagnostic {
pub(crate) struct Diagnostic {
inner: Repr,
}

Expand All @@ -75,7 +75,7 @@ enum Repr {
}

impl Diagnostic {
pub fn error<T: Into<String>>(text: T) -> Self {
pub(crate) fn error<T: Into<String>>(text: T) -> Self {
Self {
inner: Repr::Single {
text: text.into(),
Expand All @@ -93,7 +93,7 @@ impl Diagnostic {
}
}

pub fn from_vec(diagnostics: Vec<Self>) -> Result<(), Self> {
pub(crate) fn from_vec(diagnostics: Vec<Self>) -> Result<(), Self> {
if diagnostics.is_empty() {
Ok(())
} else {
Expand All @@ -103,7 +103,7 @@ impl Diagnostic {
}
}

pub fn panic(&self) -> ! {
pub(crate) fn panic(&self) -> ! {
match &self.inner {
Repr::Single { text, .. } => panic!("{}", text),
Repr::SynError(error) => panic!("{}", error),
Expand All @@ -120,7 +120,7 @@ impl From<Error> for Diagnostic {
}
}

pub fn extract_spans(node: &dyn ToTokens) -> Option<(Span, Span)> {
pub(crate) fn extract_spans(node: &dyn ToTokens) -> Option<(Span, Span)> {
let mut t = TokenStream::new();
node.to_tokens(&mut t);
let mut tokens = t.into_iter();
Expand Down
2 changes: 1 addition & 1 deletion crates/derive-impl/src/from_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ fn compute_arity_bounds(field_attrs: &[ArgAttribute]) -> (usize, usize) {
(min_arity, max_arity)
}

pub fn impl_from_args(input: DeriveInput) -> Result<TokenStream> {
pub(crate) fn impl_from_args(input: DeriveInput) -> Result<TokenStream> {
let (fields, field_attrs) = match input.data {
Data::Struct(syn::DataStruct { fields, .. }) => (
fields
Expand Down
2 changes: 1 addition & 1 deletion crates/derive-impl/src/pymodule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ struct ModuleContext {
errors: Vec<syn::Error>,
}

pub fn impl_pymodule(args: PyModuleArgs, module_item: Item) -> Result<TokenStream> {
pub(crate) fn impl_pymodule(args: PyModuleArgs, module_item: Item) -> Result<TokenStream> {
let PyModuleArgs { metas, with_items } = args;
let (doc, mut module_item) = match module_item {
Item::Mod(m) => (m.attrs.doc(), m),
Expand Down
6 changes: 3 additions & 3 deletions crates/derive-impl/src/pystructseq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ impl ItemMeta for PyStructSequenceMeta {
}

impl PyStructSequenceMeta {
pub fn class_name(&self) -> Result<Option<String>> {
pub(crate) fn class_name(&self) -> Result<Option<String>> {
const KEY: &str = "name";
let inner = self.inner();
if let Some((_, meta)) = inner.meta_map.get(KEY) {
Expand All @@ -456,7 +456,7 @@ impl PyStructSequenceMeta {
}
}

pub fn module(&self) -> Result<Option<String>> {
pub(crate) fn module(&self) -> Result<Option<String>> {
const KEY: &str = "module";
let inner = self.inner();
if let Some((_, meta)) = inner.meta_map.get(KEY) {
Expand Down Expand Up @@ -507,7 +507,7 @@ impl PyStructSequenceMeta {
}
}

pub fn no_attr(&self) -> Result<bool> {
pub(crate) fn no_attr(&self) -> Result<bool> {
self.inner()._bool("no_attr")
}
}
Expand Down
40 changes: 20 additions & 20 deletions crates/derive-impl/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub(crate) struct ItemNursery(Vec<NurseryItem>);
pub(crate) struct ValidatedItemNursery(ItemNursery);

impl ItemNursery {
pub fn add_item(
pub(crate) fn add_item(
&mut self,
attr_name: Ident,
py_names: Vec<String>,
Expand All @@ -56,7 +56,7 @@ impl ItemNursery {
Ok(())
}

pub fn validate(self) -> Result<ValidatedItemNursery> {
pub(crate) fn validate(self) -> Result<ValidatedItemNursery> {
let mut by_name: HashSet<(String, Vec<Attribute>)> = HashSet::new();
for item in &self.0 {
for py_name in &item.py_names {
Expand Down Expand Up @@ -118,7 +118,7 @@ pub(crate) struct ItemMetaInner {
}

impl ItemMetaInner {
pub fn from_nested<I>(
pub(crate) fn from_nested<I>(
item_ident: Ident,
meta_ident: Ident,
nested: I,
Expand Down Expand Up @@ -154,15 +154,15 @@ impl ItemMetaInner {
})
}

pub fn item_name(&self) -> String {
pub(crate) fn item_name(&self) -> String {
self.item_ident.to_string()
}

pub fn meta_name(&self) -> String {
pub(crate) fn meta_name(&self) -> String {
self.meta_ident.to_string()
}

pub fn _optional_str(&self, key: &str) -> Result<Option<String>> {
pub(crate) fn _optional_str(&self, key: &str) -> Result<Option<String>> {
let value = if let Some((_, meta)) = self.meta_map.get(key) {
let Meta::NameValue(syn::MetaNameValue {
value:
Expand All @@ -187,7 +187,7 @@ impl ItemMetaInner {
Ok(value)
}

pub fn _optional_path(&self, key: &str) -> Result<Option<syn::Path>> {
pub(crate) fn _optional_path(&self, key: &str) -> Result<Option<syn::Path>> {
let value = if let Some((_, meta)) = self.meta_map.get(key) {
let Meta::NameValue(syn::MetaNameValue { value, .. }) = meta else {
bail_span!(
Expand Down Expand Up @@ -216,11 +216,11 @@ impl ItemMetaInner {
Ok(value)
}

pub fn _has_key(&self, key: &str) -> Result<bool> {
pub(crate) fn _has_key(&self, key: &str) -> Result<bool> {
Ok(matches!(self.meta_map.get(key), Some((_, _))))
}

pub fn _bool(&self, key: &str) -> Result<bool> {
pub(crate) fn _bool(&self, key: &str) -> Result<bool> {
let value = if let Some((_, meta)) = self.meta_map.get(key) {
match meta {
Meta::NameValue(syn::MetaNameValue {
Expand All @@ -240,7 +240,7 @@ impl ItemMetaInner {
Ok(value)
}

pub fn _optional_list(
pub(crate) fn _optional_list(
&self,
key: &str,
) -> Result<Option<impl core::iter::Iterator<Item = &'_ NestedMeta>>> {
Expand Down Expand Up @@ -327,7 +327,7 @@ impl ItemMeta for ModuleItemMeta {
}

impl ModuleItemMeta {
pub fn sub(&self) -> Result<bool> {
pub(crate) fn sub(&self) -> Result<bool> {
self.inner()._bool("sub")
}
}
Expand Down Expand Up @@ -371,7 +371,7 @@ impl ItemMeta for ClassItemMeta {
}

impl ClassItemMeta {
pub fn class_name(&self) -> Result<String> {
pub(crate) fn class_name(&self) -> Result<String> {
const KEY: &str = "name";
let inner = self.inner();
if let Some((_, meta)) = inner.meta_map.get(KEY) {
Expand All @@ -396,23 +396,23 @@ impl ClassItemMeta {
)
}

pub fn ctx_name(&self) -> Result<Option<String>> {
pub(crate) fn ctx_name(&self) -> Result<Option<String>> {
self.inner()._optional_str("ctx")
}

pub fn base(&self) -> Result<Option<syn::Path>> {
pub(crate) fn base(&self) -> Result<Option<syn::Path>> {
self.inner()._optional_path("base")
}

pub fn unhashable(&self) -> Result<bool> {
pub(crate) fn unhashable(&self) -> Result<bool> {
self.inner()._bool("unhashable")
}

pub fn metaclass(&self) -> Result<Option<String>> {
pub(crate) fn metaclass(&self) -> Result<Option<String>> {
self.inner()._optional_str("metaclass")
}

pub fn module(&self) -> Result<Option<String>> {
pub(crate) fn module(&self) -> Result<Option<String>> {
const KEY: &str = "module";
let inner = self.inner();
let value = if let Some((_, meta)) = inner.meta_map.get(KEY) {
Expand Down Expand Up @@ -443,7 +443,7 @@ impl ClassItemMeta {
Ok(value)
}

pub fn impl_attrs(&self) -> Result<Option<String>> {
pub(crate) fn impl_attrs(&self) -> Result<Option<String>> {
self.inner()._optional_str("impl")
}

Expand Down Expand Up @@ -475,7 +475,7 @@ impl ItemMeta for ExceptionItemMeta {
}

impl ExceptionItemMeta {
pub fn class_name(&self) -> Result<String> {
pub(crate) fn class_name(&self) -> Result<String> {
const KEY: &str = "name";
let inner = self.inner();
if let Some((_, meta)) = inner.meta_map.get(KEY) {
Expand Down Expand Up @@ -511,7 +511,7 @@ impl ExceptionItemMeta {
)
}

pub fn has_impl(&self) -> Result<bool> {
pub(crate) fn has_impl(&self) -> Result<bool> {
self.inner()._bool("impl")
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/host_env/src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::mem::MaybeUninit;
use std::io;

#[cfg(unix)]
mod platform {
pub mod platform {
pub use libc::{FD_ISSET, FD_SET, FD_SETSIZE, FD_ZERO, fd_set, select, timeval};
pub use std::os::unix::io::RawFd;

Expand All @@ -13,7 +13,7 @@ mod platform {

#[allow(non_snake_case)]
#[cfg(windows)]
mod platform {
pub mod platform {
pub use WinSock::{FD_SET as fd_set, FD_SETSIZE, SOCKET as RawFd, TIMEVAL as timeval, select};
use windows_sys::Win32::Networking::WinSock;

Expand Down Expand Up @@ -49,7 +49,7 @@ mod platform {
}

#[cfg(target_os = "wasi")]
mod platform {
pub mod platform {
pub use libc::{FD_SETSIZE, timeval};
pub use std::os::fd::RawFd;

Expand Down
Loading
Loading