Skip to content

Warn on unreachable_pub#7762

Merged
youknowone merged 15 commits into
RustPython:mainfrom
ShaharNaveh:warn-unreachble-pub
May 4, 2026
Merged

Warn on unreachable_pub#7762
youknowone merged 15 commits into
RustPython:mainfrom
ShaharNaveh:warn-unreachble-pub

Conversation

@ShaharNaveh
Copy link
Copy Markdown
Contributor

@ShaharNaveh ShaharNaveh commented May 2, 2026

How is this not enabled by default? 😕

Summary by CodeRabbit

  • Chores
    • Enabled a workspace lint to warn about unnecessary public exports.
    • Reduced and reorganized internal API visibility across many modules to shrink the exported surface; no functional or user-facing behavior changes.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 2, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Added a workspace Rust lint and performed a repository-wide visibility tightening: many pub items converted to pub(crate) or pub(super), with a few mod declarations made pub mod. No functional logic was changed.

Changes

Visibility & Linting Sweep

Layer / File(s) Summary
Lint Configuration
Cargo.toml
Inserted unreachable_pub = "warn" under [workspace.lints.rust].
Module exports / constants
crates/vm/src/stdlib/_symtable.rs, crates/vm/src/stdlib/_stat.rs, crates/vm/src/stdlib/_ast.rs, crates/stdlib/src/openssl/ssl_data_31.rs, crates/stdlib/src/ssl/oid.rs
Numerous module-level constants and static maps changed from pub to pub(super)/pub(crate).
Top-level module visibility
crates/vm/src/stdlib/sys.rs, crates/vm/src/readline.rs, crates/host_env/src/select.rs, crates/stdlib/src/array.rs, crates/vm/src/stdlib/time.rs
Several mod declarations toggled to pub mod (exposing modules) or unchanged module visibility adjusted.
Crate-wide API surface (std/ssl/compression/ctypes/etc.)
crates/stdlib/src/..., crates/vm/src/stdlib/_ctypes{,/*}, crates/stdlib/src/ssl/{compat,cert,error,oid}.rs, crates/stdlib/src/compression.rs
Many stdlib types, helper structs, traits, enums, errors, and functions had visibility narrowed from pub to pub(crate)/pub(super) (including SSL, compression, hashlib, json machinery, mmap, pyexpat, lzma, faulthandler, _io, _signal, _sre, _stat, _thread, monitoring).
VM core internals & helpers
crates/vm/src/{anystr.rs,bytes_inner.rs,codecs.rs,intern.rs,dict_inner.rs,object/*,method.rs,...}
Core helpers, traits, type aliases, dict internals, codec contexts, intern pool, object helpers, and related methods/functions changed pubpub(crate)/pub(super).
Builtins & initializers
crates/vm/src/builtins/**
Numerous builtin init functions, iterator types, helper structs, and related constructors were made crate- or module-private (pub(crate)/pub(super)).
Codegen, derive, JIT & tests
crates/codegen/src/..., crates/derive-impl/src/..., crates/jit/src/instructions.rs, crates/jit/tests/common.rs
Internal codegen/derive helpers and JIT interfaces/tests had visibility reduced (pubpub(crate)/pub(super)).
Small internal reductions
various .../*.rs
Many other single-file visibility reductions (e.g., FormatCode::arg_count, OSErrorBuilder methods, PySSLCertificate, tokenizer iter args, etc.).
Tests / Docs
none changed
No behavioral changes, tests, or documentation content were modified in this diff.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • youknowone
  • coolreader18

Poem

"I nibble lints with twitching nose,
I tuck away what daylight shows.
With tiny paws I close each gate,
Keep crates snug, and codemate great. 🐇"

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (5)
crates/vm/src/stdlib/_stat.rs (2)

229-249: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Windows-specific constants still use pub visibility.

These Windows-specific items retain pub visibility while all other platform-agnostic constants were changed to pub(super). This will trigger unreachable_pub warnings when building on Windows. The lint likely wasn't caught because you ran cargo clippy on a non-Windows platform.

Proposed fix
 #[cfg(windows)]
 #[pyattr]
-pub use windows_sys::Win32::Storage::FileSystem::{
+pub(super) use windows_sys::Win32::Storage::FileSystem::{
     FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_COMPRESSED, FILE_ATTRIBUTE_DEVICE,
     FILE_ATTRIBUTE_DIRECTORY, FILE_ATTRIBUTE_ENCRYPTED, FILE_ATTRIBUTE_HIDDEN,
     FILE_ATTRIBUTE_INTEGRITY_STREAM, FILE_ATTRIBUTE_NO_SCRUB_DATA, FILE_ATTRIBUTE_NORMAL,
     FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, FILE_ATTRIBUTE_OFFLINE, FILE_ATTRIBUTE_READONLY,
     FILE_ATTRIBUTE_REPARSE_POINT, FILE_ATTRIBUTE_SPARSE_FILE, FILE_ATTRIBUTE_SYSTEM,
     FILE_ATTRIBUTE_TEMPORARY, FILE_ATTRIBUTE_VIRTUAL,
 };

 // Windows reparse point tags
 #[cfg(windows)]
 #[pyattr]
-pub const IO_REPARSE_TAG_SYMLINK: u32 = 0xA000000C;
+pub(super) const IO_REPARSE_TAG_SYMLINK: u32 = 0xA000000C;
 #[cfg(windows)]
 #[pyattr]
-pub const IO_REPARSE_TAG_MOUNT_POINT: u32 = 0xA0000003;
+pub(super) const IO_REPARSE_TAG_MOUNT_POINT: u32 = 0xA0000003;
 #[cfg(windows)]
 #[pyattr]
-pub const IO_REPARSE_TAG_APPEXECLINK: u32 = 0x8000001B;
+pub(super) const IO_REPARSE_TAG_APPEXECLINK: u32 = 0x8000001B;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/vm/src/stdlib/_stat.rs` around lines 229 - 249, The Windows-specific
exported items and constants (the re-exported FILE_ATTRIBUTE_* group and the
IO_REPARSE_TAG_* constants) are still declared pub and should match the
platform-agnostic change to restrict visibility; change their visibility from
pub to pub(super) for the windows-specific #[pyattr] block and for the three
consts IO_REPARSE_TAG_SYMLINK, IO_REPARSE_TAG_MOUNT_POINT, and
IO_REPARSE_TAG_APPEXECLINK so they no longer trigger unreachable_pub warnings
when building on Windows.

340-346: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

macOS-specific constants also retain pub visibility.

Similarly, these macOS-specific constants will trigger unreachable_pub warnings when building on macOS.

Proposed fix
 #[cfg(target_os = "macos")]
 #[pyattr]
-pub const SF_SUPPORTED: u32 = 0x009f0000;
+pub(super) const SF_SUPPORTED: u32 = 0x009f0000;

 #[cfg(target_os = "macos")]
 #[pyattr]
-pub const SF_SYNTHETIC: u32 = 0xc0000000;
+pub(super) const SF_SYNTHETIC: u32 = 0xc0000000;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/vm/src/stdlib/_stat.rs` around lines 340 - 346, The two macOS-only
constants SF_SUPPORTED and SF_SYNTHETIC are declared pub and cause
unreachable_pub warnings; make them private by removing the pub modifier (keep
the existing #[cfg(target_os = "macos")] and #[pyattr] attributes) so change
"pub const SF_SUPPORTED" and "pub const SF_SYNTHETIC" to "const SF_SUPPORTED"
and "const SF_SYNTHETIC".
crates/vm/src/stdlib/_signal.rs (1)

75-81: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Incomplete unreachable_pub fix: non-unix/non-windows stubs remain pub.

The unix equivalents of SIG_DFL, SIG_IGN, and SIG_ERR were correctly narrowed to pub(crate) (Lines 60, 66), but the #[cfg(not(unix))] counterparts (Lines 75–81) still carry pub. Likewise, the #[cfg(not(any(unix, windows)))] stub of signal (Lines 200–206) remains pub while the unix/windows version was changed to pub(crate). All of these sit inside pub(crate) mod _signal, so unreachable_pub will still fire on non-unix/non-windows targets (e.g., WASM).

🔧 Proposed fix
 #[cfg(not(unix))]
 #[pyattr]
-pub const SIG_DFL: sighandler_t = 0;
+pub(crate) const SIG_DFL: sighandler_t = 0;
 #[cfg(not(unix))]
 #[pyattr]
-pub const SIG_IGN: sighandler_t = 1;
+pub(crate) const SIG_IGN: sighandler_t = 1;
 #[cfg(not(unix))]
 #[allow(dead_code)]
-pub const SIG_ERR: sighandler_t = -1 as _;
+pub(crate) const SIG_ERR: sighandler_t = -1 as _;
 #[cfg(not(any(unix, windows)))]
 #[pyfunction]
-pub fn signal(
+pub(crate) fn signal(
     _signalnum: i32,
     _handler: PyObjectRef,
     vm: &VirtualMachine,
 ) -> PyResult<Option<PyObjectRef>> {

Also applies to: 200-206

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/vm/src/stdlib/_signal.rs` around lines 75 - 81, The
non-unix/non-windows stubs for signal symbols are still declared public, causing
unreachable_pub warnings; change the visibility of SIG_DFL, SIG_IGN, and SIG_ERR
in the #[cfg(not(unix))] block to pub(crate) (matching the unix variants) and
likewise change the #[cfg(not(any(unix, windows)))] stub of the signal function
to pub(crate) so all declarations inside pub(crate) mod _signal have consistent,
non-public visibility; update the declarations for the symbols SIG_DFL, SIG_IGN,
SIG_ERR and the signal function accordingly.
crates/vm/src/getpath.rs (1)

46-66: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Windows mod platform items still use bare pub, which will re-trigger unreachable_pub on Windows builds.

The non-Windows mod platform (lines 15–43) was correctly updated to pub(super), but the #[cfg(windows)] variant (lines 46–66) still exposes all items as plain pub. Since mod platform is a private module in both cfg branches, the Windows items are equally unreachable from outside this file, and the newly-enabled unreachable_pub = "warn" lint will fire when building on Windows.

🛠️ Proposed fix
 #[cfg(windows)]
 mod platform {
     use crate::version;
 
-    pub const BUILDDIR_TXT: &str = "pybuilddir.txt";
-    pub const BUILD_LANDMARK: &str = "Modules\\Setup.local";
-    pub const VENV_LANDMARK: &str = "pyvenv.cfg";
-    pub const BUILDSTDLIB_LANDMARK: &str = "Lib\\os.py";
-    pub const STDLIB_SUBDIR: &str = "Lib";
+    pub(super) const BUILDDIR_TXT: &str = "pybuilddir.txt";
+    pub(super) const BUILD_LANDMARK: &str = "Modules\\Setup.local";
+    pub(super) const VENV_LANDMARK: &str = "pyvenv.cfg";
+    pub(super) const BUILDSTDLIB_LANDMARK: &str = "Lib\\os.py";
+    pub(super) const STDLIB_SUBDIR: &str = "Lib";
 
-    pub fn stdlib_landmarks() -> [String; 2] {
+    pub(super) fn stdlib_landmarks() -> [String; 2] {
         ["Lib\\os.py".into(), "Lib\\os.pyc".into()]
     }
 
-    pub fn platstdlib_landmark() -> String {
+    pub(super) fn platstdlib_landmark() -> String {
         "DLLs".into()
     }
 
-    pub fn zip_landmark() -> String {
+    pub(super) fn zip_landmark() -> String {
         format!("python{}{}.zip", version::MAJOR, version::MINOR)
     }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/vm/src/getpath.rs` around lines 46 - 66, The Windows-specific mod
platform currently exposes items with plain pub which triggers unreachable_pub;
change the visibility of all public items in the #[cfg(windows)] platform module
to pub(super) (i.e., BUILDDIR_TXT, BUILD_LANDMARK, VENV_LANDMARK,
BUILDSTDLIB_LANDMARK, STDLIB_SUBDIR and the functions stdlib_landmarks,
platstdlib_landmark, zip_landmark) so they mirror the non-Windows branch and
remain reachable only within the parent module.
crates/stdlib/src/ssl/cert.rs (1)

1262-1281: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

validate_cert_key_match() never validates the key pair.

This returns Ok(()) for any non-empty cert chain plus any parseable private key; it never compares the certificate’s public key to the private key. So mismatched cert/key pairs are only caught later, despite the helper name and docs claiming they were validated here. Either perform the public-key check in this helper or rename/document it as a private-key sanity check instead.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/stdlib/src/ssl/cert.rs` around lines 1262 - 1281, The helper
validate_cert_key_match currently only checks the private key parses
(any_supported_type) and doesn't verify the cert's public key matches the
private key; update it to actually compare keys: parse the first certificate's
public key (from CertificateDer<'_>) and derive the public key from private_key
(via any_supported_type or the signing key API), then compare their raw
public-key bytes (or use rustls/ring APIs to verify equality) and return
Err(...) if they differ; reference validate_cert_key_match, CertificateDer,
PrivateKeyDer, and any_supported_type (or use CertifiedKey creation) so the
function fails on mismatched pairs, or if you prefer not to change behavior,
rename/document validate_cert_key_match to reflect it only checks private-key
parseability.
🧹 Nitpick comments (1)
crates/host_env/src/select.rs (1)

5-5: ⚡ Quick win

Avoid exposing platform as public API unless this is intentional.

Making platform public exports unsafe, low-level OS bindings as part of the crate interface. If this was only for lint cleanup, prefer crate-local visibility.

Proposed adjustment
-#[cfg(unix)]
-pub mod platform {
+#[cfg(unix)]
+pub(crate) mod platform {
...
-#[cfg(windows)]
-pub mod platform {
+#[cfg(windows)]
+pub(crate) mod platform {
...
-#[cfg(target_os = "wasi")]
-pub mod platform {
+#[cfg(target_os = "wasi")]
+pub(crate) mod platform {

Also applies to: 16-16, 52-52

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/host_env/src/select.rs` at line 5, The module `platform` is
unnecessarily exported; remove `pub` so the low-level OS bindings are
crate-private (change `pub mod platform` to `mod platform`) to avoid leaking
unsafe internals in the public API, and apply the same visibility change for any
other `pub mod platform` occurrences (e.g., the other declarations found in this
file) so all platform bindings remain crate-local; update any internal
references to use the now-private module path if needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/vm/src/builtins/type.rs`:
- Line 411: The public API exposes the crate-private type PyAttributes which
triggers private_in_public; to fix, make visibility consistent: either change
the type alias PyAttributes to pub type PyAttributes = ... so it can be used in
public signatures, or keep PyAttributes as pub(crate) and change the three
methods on PyType (new_heap, new_static, and get_attributes) from pub to
pub(crate). Locate the type alias named PyAttributes and the methods new_heap,
new_static, and get_attributes in the PyType impl and apply one of these two
consistent-visibility fixes so the compiler lint is satisfied.

---

Outside diff comments:
In `@crates/stdlib/src/ssl/cert.rs`:
- Around line 1262-1281: The helper validate_cert_key_match currently only
checks the private key parses (any_supported_type) and doesn't verify the cert's
public key matches the private key; update it to actually compare keys: parse
the first certificate's public key (from CertificateDer<'_>) and derive the
public key from private_key (via any_supported_type or the signing key API),
then compare their raw public-key bytes (or use rustls/ring APIs to verify
equality) and return Err(...) if they differ; reference validate_cert_key_match,
CertificateDer, PrivateKeyDer, and any_supported_type (or use CertifiedKey
creation) so the function fails on mismatched pairs, or if you prefer not to
change behavior, rename/document validate_cert_key_match to reflect it only
checks private-key parseability.

In `@crates/vm/src/getpath.rs`:
- Around line 46-66: The Windows-specific mod platform currently exposes items
with plain pub which triggers unreachable_pub; change the visibility of all
public items in the #[cfg(windows)] platform module to pub(super) (i.e.,
BUILDDIR_TXT, BUILD_LANDMARK, VENV_LANDMARK, BUILDSTDLIB_LANDMARK, STDLIB_SUBDIR
and the functions stdlib_landmarks, platstdlib_landmark, zip_landmark) so they
mirror the non-Windows branch and remain reachable only within the parent
module.

In `@crates/vm/src/stdlib/_signal.rs`:
- Around line 75-81: The non-unix/non-windows stubs for signal symbols are still
declared public, causing unreachable_pub warnings; change the visibility of
SIG_DFL, SIG_IGN, and SIG_ERR in the #[cfg(not(unix))] block to pub(crate)
(matching the unix variants) and likewise change the #[cfg(not(any(unix,
windows)))] stub of the signal function to pub(crate) so all declarations inside
pub(crate) mod _signal have consistent, non-public visibility; update the
declarations for the symbols SIG_DFL, SIG_IGN, SIG_ERR and the signal function
accordingly.

In `@crates/vm/src/stdlib/_stat.rs`:
- Around line 229-249: The Windows-specific exported items and constants (the
re-exported FILE_ATTRIBUTE_* group and the IO_REPARSE_TAG_* constants) are still
declared pub and should match the platform-agnostic change to restrict
visibility; change their visibility from pub to pub(super) for the
windows-specific #[pyattr] block and for the three consts
IO_REPARSE_TAG_SYMLINK, IO_REPARSE_TAG_MOUNT_POINT, and
IO_REPARSE_TAG_APPEXECLINK so they no longer trigger unreachable_pub warnings
when building on Windows.
- Around line 340-346: The two macOS-only constants SF_SUPPORTED and
SF_SYNTHETIC are declared pub and cause unreachable_pub warnings; make them
private by removing the pub modifier (keep the existing #[cfg(target_os =
"macos")] and #[pyattr] attributes) so change "pub const SF_SUPPORTED" and "pub
const SF_SYNTHETIC" to "const SF_SUPPORTED" and "const SF_SYNTHETIC".

---

Nitpick comments:
In `@crates/host_env/src/select.rs`:
- Line 5: The module `platform` is unnecessarily exported; remove `pub` so the
low-level OS bindings are crate-private (change `pub mod platform` to `mod
platform`) to avoid leaking unsafe internals in the public API, and apply the
same visibility change for any other `pub mod platform` occurrences (e.g., the
other declarations found in this file) so all platform bindings remain
crate-local; update any internal references to use the now-private module path
if needed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: b2de1c61-f0f8-482f-8dd8-210842562825

📥 Commits

Reviewing files that changed from the base of the PR and between 926d69b and c8cebdd.

📒 Files selected for processing (106)
  • Cargo.toml
  • crates/codegen/src/symboltable.rs
  • crates/codegen/src/unparse.rs
  • crates/derive-impl/src/compile_bytecode.rs
  • crates/derive-impl/src/error.rs
  • crates/derive-impl/src/from_args.rs
  • crates/derive-impl/src/pymodule.rs
  • crates/derive-impl/src/pystructseq.rs
  • crates/derive-impl/src/util.rs
  • crates/host_env/src/select.rs
  • crates/stdlib/src/_tokenize.rs
  • crates/stdlib/src/array.rs
  • crates/stdlib/src/compression.rs
  • crates/stdlib/src/faulthandler.rs
  • crates/stdlib/src/hashlib.rs
  • crates/stdlib/src/json/machinery.rs
  • crates/stdlib/src/mmap.rs
  • crates/stdlib/src/openssl/ssl_data_31.rs
  • crates/stdlib/src/pyexpat.rs
  • crates/stdlib/src/select.rs
  • crates/stdlib/src/ssl.rs
  • crates/stdlib/src/ssl/cert.rs
  • crates/stdlib/src/ssl/compat.rs
  • crates/stdlib/src/ssl/error.rs
  • crates/stdlib/src/ssl/oid.rs
  • crates/stdlib/src/unicodedata.rs
  • crates/vm/src/anystr.rs
  • crates/vm/src/buffer.rs
  • crates/vm/src/builtins/asyncgenerator.rs
  • crates/vm/src/builtins/builtin_func.rs
  • crates/vm/src/builtins/bytearray.rs
  • crates/vm/src/builtins/bytes.rs
  • crates/vm/src/builtins/capsule.rs
  • crates/vm/src/builtins/code.rs
  • crates/vm/src/builtins/complex.rs
  • crates/vm/src/builtins/coroutine.rs
  • crates/vm/src/builtins/descriptor.rs
  • crates/vm/src/builtins/dict.rs
  • crates/vm/src/builtins/enumerate.rs
  • crates/vm/src/builtins/filter.rs
  • crates/vm/src/builtins/float.rs
  • crates/vm/src/builtins/frame.rs
  • crates/vm/src/builtins/function.rs
  • crates/vm/src/builtins/generator.rs
  • crates/vm/src/builtins/genericalias.rs
  • crates/vm/src/builtins/int.rs
  • crates/vm/src/builtins/interpolation.rs
  • crates/vm/src/builtins/list.rs
  • crates/vm/src/builtins/map.rs
  • crates/vm/src/builtins/mappingproxy.rs
  • crates/vm/src/builtins/memory.rs
  • crates/vm/src/builtins/module.rs
  • crates/vm/src/builtins/namespace.rs
  • crates/vm/src/builtins/object.rs
  • crates/vm/src/builtins/range.rs
  • crates/vm/src/builtins/set.rs
  • crates/vm/src/builtins/singletons.rs
  • crates/vm/src/builtins/slice.rs
  • crates/vm/src/builtins/staticmethod.rs
  • crates/vm/src/builtins/str.rs
  • crates/vm/src/builtins/super.rs
  • crates/vm/src/builtins/template.rs
  • crates/vm/src/builtins/traceback.rs
  • crates/vm/src/builtins/type.rs
  • crates/vm/src/builtins/union.rs
  • crates/vm/src/builtins/weakproxy.rs
  • crates/vm/src/builtins/weakref.rs
  • crates/vm/src/builtins/zip.rs
  • crates/vm/src/bytes_inner.rs
  • crates/vm/src/codecs.rs
  • crates/vm/src/coroutine.rs
  • crates/vm/src/dict_inner.rs
  • crates/vm/src/exceptions.rs
  • crates/vm/src/function/getset.rs
  • crates/vm/src/getpath.rs
  • crates/vm/src/intern.rs
  • crates/vm/src/object/core.rs
  • crates/vm/src/object/traverse_object.rs
  • crates/vm/src/ospath.rs
  • crates/vm/src/readline.rs
  • crates/vm/src/stdlib/_ast.rs
  • crates/vm/src/stdlib/_ast/pyast.rs
  • crates/vm/src/stdlib/_ctypes.rs
  • crates/vm/src/stdlib/_ctypes/array.rs
  • crates/vm/src/stdlib/_ctypes/base.rs
  • crates/vm/src/stdlib/_ctypes/function.rs
  • crates/vm/src/stdlib/_ctypes/library.rs
  • crates/vm/src/stdlib/_ctypes/pointer.rs
  • crates/vm/src/stdlib/_ctypes/simple.rs
  • crates/vm/src/stdlib/_ctypes/structure.rs
  • crates/vm/src/stdlib/_ctypes/union.rs
  • crates/vm/src/stdlib/_functools.rs
  • crates/vm/src/stdlib/_imp.rs
  • crates/vm/src/stdlib/_io.rs
  • crates/vm/src/stdlib/_signal.rs
  • crates/vm/src/stdlib/_sre.rs
  • crates/vm/src/stdlib/_stat.rs
  • crates/vm/src/stdlib/_symtable.rs
  • crates/vm/src/stdlib/_thread.rs
  • crates/vm/src/stdlib/_typing.rs
  • crates/vm/src/stdlib/builtins.rs
  • crates/vm/src/stdlib/os.rs
  • crates/vm/src/stdlib/sys.rs
  • crates/vm/src/stdlib/sys/monitoring.rs
  • crates/vm/src/stdlib/time.rs
  • crates/vm/src/vm/method.rs

/// that maintains order and is compatible with the standard HashMap This is probably
/// faster and only supports strings as keys.
pub type PyAttributes = IndexMap<&'static PyStrInterned, PyObjectRef, ahash::RandomState>;
pub(crate) type PyAttributes = IndexMap<&'static PyStrInterned, PyObjectRef, ahash::RandomState>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# 1. Check how (and whether) the builtins::type module is re-exported at the vm crate root
rg -n "pub.*builtins|pub use.*type" crates/vm/src/lib.rs

# 2. Look for public re-exports of PyAttributes or the three affected methods
rg -n "PyAttributes|new_heap|new_static|get_attributes" crates/vm/src/lib.rs

# 3. Check if the builtins module itself is pub or pub(crate)
rg -n "mod builtins" crates/vm/src/lib.rs crates/vm/src/

# 4. Confirm whether any crate outside vm references PyAttributes
rg -rn "PyAttributes" --type rust --glob "!crates/vm/*"

Repository: RustPython/RustPython

Length of output: 269


Fix visibility inconsistency: pub(crate) PyAttributes type cannot be used in public method signatures.

Line 411 narrows PyAttributes to pub(crate), but three methods in the same PyType struct remain pub and expose this private type:

  • new_heap (line 528): parameter attrs: PyAttributes
  • new_static (line 749): parameter attrs: PyAttributes
  • get_attributes (line 1157): return type -> PyAttributes

Since builtins module is re-exported as pub mod at the crate root (crates/vm/src/lib.rs:46), these pub methods are part of the public API. Exposing a private type in their signatures triggers Rust's private_in_public lint and prevents compilation.

Either make PyAttributes public again or narrow those three methods to pub(crate) to match the visibility of the type they expose.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/vm/src/builtins/type.rs` at line 411, The public API exposes the
crate-private type PyAttributes which triggers private_in_public; to fix, make
visibility consistent: either change the type alias PyAttributes to pub type
PyAttributes = ... so it can be used in public signatures, or keep PyAttributes
as pub(crate) and change the three methods on PyType (new_heap, new_static, and
get_attributes) from pub to pub(crate). Locate the type alias named PyAttributes
and the methods new_heap, new_static, and get_attributes in the PyType impl and
apply one of these two consistent-visibility fixes so the compiler lint is
satisfied.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/vm/src/readline.rs`:
- Line 22: The modules basic_readline and rustyline_readline are currently
declared public which unnecessarily exposes backend internals; make these
modules private (remove the pub modifier) and then tighten the visibility of the
inner Readline types and their methods to pub(super) or pub(crate) as
appropriate so only the outer wrapper API can access them; update any uses in
the outer wrapper to match the new visibility (e.g., reference the types via the
parent module) and ensure any items truly needed externally retain only the
minimal pub(super)/pub(crate) visibility.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: b3e6e9dc-ce58-4631-bfb7-1741e35dee6f

📥 Commits

Reviewing files that changed from the base of the PR and between c8cebdd and 332ab91.

📒 Files selected for processing (2)
  • crates/vm/src/builtins/dict.rs
  • crates/vm/src/readline.rs
✅ Files skipped from review due to trivial changes (1)
  • crates/vm/src/builtins/dict.rs

Comment thread crates/vm/src/readline.rs

#[allow(unused)]
mod basic_readline {
pub mod basic_readline {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Avoid exposing backend modules publicly to satisfy unreachable_pub.

Making basic_readline and rustyline_readline public widens the crate API with backend-specific internals. Prefer keeping these modules private and tightening inner visibility (pub(super)/pub(crate)) for only what the outer wrapper needs.

Suggested direction
-#[allow(unused)]
-pub mod basic_readline {
+#[allow(unused)]
+mod basic_readline {
 #[cfg(not(target_arch = "wasm32"))]
-pub mod rustyline_readline {
+mod rustyline_readline {

Then reduce inner Readline type/method visibility to pub(super) (or pub(crate) where needed) instead of exposing modules.

Also applies to: 69-69

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/vm/src/readline.rs` at line 22, The modules basic_readline and
rustyline_readline are currently declared public which unnecessarily exposes
backend internals; make these modules private (remove the pub modifier) and then
tighten the visibility of the inner Readline types and their methods to
pub(super) or pub(crate) as appropriate so only the outer wrapper API can access
them; update any uses in the outer wrapper to match the new visibility (e.g.,
reference the types via the parent module) and ensure any items truly needed
externally retain only the minimal pub(super)/pub(crate) visibility.

@youknowone youknowone enabled auto-merge (squash) May 2, 2026 15:16
@ShaharNaveh
Copy link
Copy Markdown
Contributor Author

@youknowone can you please approve this PR? it will be auto-merged

@youknowone youknowone merged commit eb99a8e into RustPython:main May 4, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants