Skip to content

Commit eb99a8e

Browse files
authored
Warn on unreachable_pub (RustPython#7762)
1 parent acc167f commit eb99a8e

118 files changed

Lines changed: 962 additions & 819 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ jobs:
113113
uses: ./.github/actions/install-macos-deps
114114

115115
- name: run clippy
116-
run: cargo clippy ${{ env.CARGO_ARGS }} --workspace --all-targets ${{ env.WORKSPACE_EXCLUDES }} -- -Dwarnings
116+
run: cargo clippy --keep-going ${{ env.CARGO_ARGS }} --workspace --all-targets ${{ env.WORKSPACE_EXCLUDES }} -- -Dwarnings
117117

118118
- name: run rust tests
119119
run: cargo test --workspace ${{ env.WORKSPACE_EXCLUDES }} --verbose --features threading ${{ env.CARGO_ARGS }}
@@ -563,7 +563,7 @@ jobs:
563563
${{ runner.os }}-
564564
565565
- name: cargo clippy
566-
run: cargo clippy --manifest-path=crates/wasm/Cargo.toml -- -Dwarnings
566+
run: cargo clippy --keep-going --manifest-path=crates/wasm/Cargo.toml -- -Dwarnings
567567

568568
- name: install wasm-pack
569569
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ xml = "1.2"
294294
unsafe_code = "allow"
295295
unsafe_op_in_unsafe_fn = "deny"
296296
elided_lifetimes_in_paths = "warn"
297+
unreachable_pub = "warn"
297298

298299
[workspace.lints.clippy]
299300
alloc_instead_of_core = "warn"

crates/codegen/src/symboltable.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ type SymbolMap = IndexMap<String, Symbol>;
391391
mod stack {
392392
use alloc::vec::Vec;
393393
use core::ptr::NonNull;
394-
pub struct StackStack<T> {
394+
pub(super) struct StackStack<T> {
395395
v: Vec<NonNull<T>>,
396396
}
397397
impl<T> Default for StackStack<T> {
@@ -403,7 +403,7 @@ mod stack {
403403
/// Appends a reference to this stack for the duration of the function `f`. When `f`
404404
/// returns, the reference will be popped off the stack.
405405
#[cfg(feature = "std")]
406-
pub fn with_append<F, R>(&mut self, x: &mut T, f: F) -> R
406+
pub(super) fn with_append<F, R>(&mut self, x: &mut T, f: F) -> R
407407
where
408408
F: FnOnce(&mut Self) -> R,
409409
{
@@ -428,10 +428,10 @@ mod stack {
428428
result
429429
}
430430

431-
pub fn iter(&self) -> impl DoubleEndedIterator<Item = &T> + '_ {
431+
pub(super) fn iter(&self) -> impl DoubleEndedIterator<Item = &T> + '_ {
432432
self.as_ref().iter().copied()
433433
}
434-
pub fn iter_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut T> + '_ {
434+
pub(super) fn iter_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut T> + '_ {
435435
self.as_mut().iter_mut().map(|x| &mut **x)
436436
}
437437
// pub fn top(&self) -> Option<&T> {
@@ -440,18 +440,18 @@ mod stack {
440440
// pub fn top_mut(&mut self) -> Option<&mut T> {
441441
// self.as_mut().last_mut().map(|x| &mut **x)
442442
// }
443-
pub fn len(&self) -> usize {
443+
pub(super) fn len(&self) -> usize {
444444
self.v.len()
445445
}
446-
pub fn is_empty(&self) -> bool {
446+
pub(super) fn is_empty(&self) -> bool {
447447
self.len() == 0
448448
}
449449

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

454-
pub fn as_mut(&mut self) -> &mut [&mut T] {
454+
pub(super) fn as_mut(&mut self) -> &mut [&mut T] {
455455
unsafe { &mut *(self.v.as_mut_slice() as *mut [NonNull<T>] as *mut [&mut T]) }
456456
}
457457
}

crates/codegen/src/unparse.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,24 @@ use ruff_text_size::Ranged;
55
use rustpython_compiler_core::SourceFile;
66
use rustpython_literal::escape::{AsciiEscape, UnicodeEscape};
77

8-
mod precedence {
8+
pub(crate) mod precedence {
99
macro_rules! precedence {
1010
($($op:ident,)*) => {
1111
precedence!(@0, $($op,)*);
1212
};
1313
(@$i:expr, $op1:ident, $($op:ident,)*) => {
14-
pub const $op1: u8 = $i;
14+
pub(crate) const $op1: u8 = $i;
1515
precedence!(@$i + 1, $($op,)*);
1616
};
1717
(@$i:expr,) => {};
1818
}
19+
1920
precedence!(
2021
TUPLE, TEST, OR, AND, NOT, CMP, // "EXPR" =
2122
BOR, BXOR, BAND, SHIFT, ARITH, TERM, FACTOR, POWER, AWAIT, ATOM,
2223
);
23-
pub const EXPR: u8 = BOR;
24+
25+
pub(crate) const EXPR: u8 = BOR;
2426
}
2527

2628
struct Unparser<'a, 'b, 'c> {
@@ -653,13 +655,13 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
653655
}
654656
}
655657

656-
pub struct UnparseExpr<'a> {
658+
pub(crate) struct UnparseExpr<'a> {
657659
expr: &'a ast::Expr,
658660
source: &'a SourceFile,
659661
}
660662

661663
impl<'a> UnparseExpr<'a> {
662-
pub const fn new(expr: &'a ast::Expr, source: &'a SourceFile) -> Self {
664+
pub(crate) const fn new(expr: &'a ast::Expr, source: &'a SourceFile) -> Self {
663665
Self { expr, source }
664666
}
665667
}

crates/derive-impl/src/compile_bytecode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ struct PyCompileArgs {
335335
crate_name: syn::Path,
336336
}
337337

338-
pub fn impl_py_compile(
338+
pub(crate) fn impl_py_compile(
339339
input: TokenStream,
340340
compiler: &dyn Compiler,
341341
) -> Result<TokenStream, Diagnostic> {
@@ -356,7 +356,7 @@ pub fn impl_py_compile(
356356
Ok(output)
357357
}
358358

359-
pub fn impl_py_freeze(
359+
pub(crate) fn impl_py_freeze(
360360
input: TokenStream,
361361
compiler: &dyn Compiler,
362362
) -> Result<TokenStream, Diagnostic> {

crates/derive-impl/src/error.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ macro_rules! bail_span {
5858
// }
5959

6060
#[derive(Debug)]
61-
pub struct Diagnostic {
61+
pub(crate) struct Diagnostic {
6262
inner: Repr,
6363
}
6464

@@ -75,7 +75,7 @@ enum Repr {
7575
}
7676

7777
impl Diagnostic {
78-
pub fn error<T: Into<String>>(text: T) -> Self {
78+
pub(crate) fn error<T: Into<String>>(text: T) -> Self {
7979
Self {
8080
inner: Repr::Single {
8181
text: text.into(),
@@ -93,7 +93,7 @@ impl Diagnostic {
9393
}
9494
}
9595

96-
pub fn from_vec(diagnostics: Vec<Self>) -> Result<(), Self> {
96+
pub(crate) fn from_vec(diagnostics: Vec<Self>) -> Result<(), Self> {
9797
if diagnostics.is_empty() {
9898
Ok(())
9999
} else {
@@ -103,7 +103,7 @@ impl Diagnostic {
103103
}
104104
}
105105

106-
pub fn panic(&self) -> ! {
106+
pub(crate) fn panic(&self) -> ! {
107107
match &self.inner {
108108
Repr::Single { text, .. } => panic!("{}", text),
109109
Repr::SynError(error) => panic!("{}", error),
@@ -120,7 +120,7 @@ impl From<Error> for Diagnostic {
120120
}
121121
}
122122

123-
pub fn extract_spans(node: &dyn ToTokens) -> Option<(Span, Span)> {
123+
pub(crate) fn extract_spans(node: &dyn ToTokens) -> Option<(Span, Span)> {
124124
let mut t = TokenStream::new();
125125
node.to_tokens(&mut t);
126126
let mut tokens = t.into_iter();

crates/derive-impl/src/from_args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ fn compute_arity_bounds(field_attrs: &[ArgAttribute]) -> (usize, usize) {
220220
(min_arity, max_arity)
221221
}
222222

223-
pub fn impl_from_args(input: DeriveInput) -> Result<TokenStream> {
223+
pub(crate) fn impl_from_args(input: DeriveInput) -> Result<TokenStream> {
224224
let (fields, field_attrs) = match input.data {
225225
Data::Struct(syn::DataStruct { fields, .. }) => (
226226
fields

crates/derive-impl/src/pymodule.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ struct ModuleContext {
147147
errors: Vec<syn::Error>,
148148
}
149149

150-
pub fn impl_pymodule(args: PyModuleArgs, module_item: Item) -> Result<TokenStream> {
150+
pub(crate) fn impl_pymodule(args: PyModuleArgs, module_item: Item) -> Result<TokenStream> {
151151
let PyModuleArgs { metas, with_items } = args;
152152
let (doc, mut module_item) = match module_item {
153153
Item::Mod(m) => (m.attrs.doc(), m),

crates/derive-impl/src/pystructseq.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ impl ItemMeta for PyStructSequenceMeta {
432432
}
433433

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

459-
pub fn module(&self) -> Result<Option<String>> {
459+
pub(crate) fn module(&self) -> Result<Option<String>> {
460460
const KEY: &str = "module";
461461
let inner = self.inner();
462462
if let Some((_, meta)) = inner.meta_map.get(KEY) {
@@ -507,7 +507,7 @@ impl PyStructSequenceMeta {
507507
}
508508
}
509509

510-
pub fn no_attr(&self) -> Result<bool> {
510+
pub(crate) fn no_attr(&self) -> Result<bool> {
511511
self.inner()._bool("no_attr")
512512
}
513513
}

crates/derive-impl/src/util.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub(crate) struct ItemNursery(Vec<NurseryItem>);
3838
pub(crate) struct ValidatedItemNursery(ItemNursery);
3939

4040
impl ItemNursery {
41-
pub fn add_item(
41+
pub(crate) fn add_item(
4242
&mut self,
4343
attr_name: Ident,
4444
py_names: Vec<String>,
@@ -56,7 +56,7 @@ impl ItemNursery {
5656
Ok(())
5757
}
5858

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

120120
impl ItemMetaInner {
121-
pub fn from_nested<I>(
121+
pub(crate) fn from_nested<I>(
122122
item_ident: Ident,
123123
meta_ident: Ident,
124124
nested: I,
@@ -154,15 +154,15 @@ impl ItemMetaInner {
154154
})
155155
}
156156

157-
pub fn item_name(&self) -> String {
157+
pub(crate) fn item_name(&self) -> String {
158158
self.item_ident.to_string()
159159
}
160160

161-
pub fn meta_name(&self) -> String {
161+
pub(crate) fn meta_name(&self) -> String {
162162
self.meta_ident.to_string()
163163
}
164164

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

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

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

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

243-
pub fn _optional_list(
243+
pub(crate) fn _optional_list(
244244
&self,
245245
key: &str,
246246
) -> Result<Option<impl core::iter::Iterator<Item = &'_ NestedMeta>>> {
@@ -327,7 +327,7 @@ impl ItemMeta for ModuleItemMeta {
327327
}
328328

329329
impl ModuleItemMeta {
330-
pub fn sub(&self) -> Result<bool> {
330+
pub(crate) fn sub(&self) -> Result<bool> {
331331
self.inner()._bool("sub")
332332
}
333333
}
@@ -371,7 +371,7 @@ impl ItemMeta for ClassItemMeta {
371371
}
372372

373373
impl ClassItemMeta {
374-
pub fn class_name(&self) -> Result<String> {
374+
pub(crate) fn class_name(&self) -> Result<String> {
375375
const KEY: &str = "name";
376376
let inner = self.inner();
377377
if let Some((_, meta)) = inner.meta_map.get(KEY) {
@@ -396,23 +396,23 @@ impl ClassItemMeta {
396396
)
397397
}
398398

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

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

407-
pub fn unhashable(&self) -> Result<bool> {
407+
pub(crate) fn unhashable(&self) -> Result<bool> {
408408
self.inner()._bool("unhashable")
409409
}
410410

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

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

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

@@ -475,7 +475,7 @@ impl ItemMeta for ExceptionItemMeta {
475475
}
476476

477477
impl ExceptionItemMeta {
478-
pub fn class_name(&self) -> Result<String> {
478+
pub(crate) fn class_name(&self) -> Result<String> {
479479
const KEY: &str = "name";
480480
let inner = self.inner();
481481
if let Some((_, meta)) = inner.meta_map.get(KEY) {
@@ -511,7 +511,7 @@ impl ExceptionItemMeta {
511511
)
512512
}
513513

514-
pub fn has_impl(&self) -> Result<bool> {
514+
pub(crate) fn has_impl(&self) -> Result<bool> {
515515
self.inner()._bool("impl")
516516
}
517517
}

0 commit comments

Comments
 (0)