Skip to content

Commit 16acd49

Browse files
Remove some unused pub functions (#11576)
## Summary I left anything in `red-knot`, any `with_` methods, etc.
1 parent 3989cb8 commit 16acd49

File tree

14 files changed

+7
-495
lines changed

14 files changed

+7
-495
lines changed

Cargo.lock

-38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ filetime = { version = "0.2.23" }
6262
glob = { version = "0.3.1" }
6363
globset = { version = "0.4.14" }
6464
hashbrown = "0.14.3"
65-
hexf-parse = { version = "0.2.1" }
6665
ignore = { version = "0.4.22" }
6766
imara-diff = { version = "0.1.5" }
6867
imperative = { version = "1.0.4" }
@@ -76,12 +75,11 @@ is-wsl = { version = "0.4.0" }
7675
itertools = { version = "0.12.1" }
7776
js-sys = { version = "0.3.69" }
7877
jod-thread = { version = "0.1.2" }
79-
lexical-parse-float = { version = "0.8.0", features = ["format"] }
8078
libc = { version = "0.2.153" }
8179
libcst = { version = "1.1.0", default-features = false }
8280
log = { version = "0.4.17" }
8381
lsp-server = { version = "0.7.6" }
84-
lsp-types = { git="https://github.com/astral-sh/lsp-types.git", rev = "3512a9f", features = ["proposed"] }
82+
lsp-types = { git = "https://github.com/astral-sh/lsp-types.git", rev = "3512a9f", features = ["proposed"] }
8583
matchit = { version = "0.8.1" }
8684
memchr = { version = "2.7.1" }
8785
mimalloc = { version = "0.1.39" }

crates/ruff_formatter/src/lib.rs

-9
Original file line numberDiff line numberDiff line change
@@ -553,11 +553,6 @@ impl PrintedRange {
553553
pub fn source_range(&self) -> TextRange {
554554
self.source_range
555555
}
556-
557-
#[must_use]
558-
pub fn with_code(self, code: String) -> Self {
559-
Self { code, ..self }
560-
}
561556
}
562557

563558
/// Public return type of the formatter
@@ -780,10 +775,6 @@ where
780775
self.item = item;
781776
self
782777
}
783-
784-
pub fn into_item(self) -> T {
785-
self.item
786-
}
787778
}
788779

789780
impl<T, R, C> Format<C> for FormatOwnedWithRule<T, R, C>

crates/ruff_linter/src/directives.rs

-16
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,6 @@ pub struct IsortDirectives {
4646
pub skip_file: bool,
4747
}
4848

49-
impl IsortDirectives {
50-
pub fn is_excluded(&self, offset: TextSize) -> bool {
51-
for range in &self.exclusions {
52-
if range.contains(offset) {
53-
return true;
54-
}
55-
56-
if range.start() > offset {
57-
break;
58-
}
59-
}
60-
61-
false
62-
}
63-
}
64-
6549
pub struct Directives {
6650
pub noqa_line_for: NoqaMapping,
6751
pub isort: IsortDirectives,

crates/ruff_linter/src/rules/isort/categorize.rs

-20
Original file line numberDiff line numberDiff line change
@@ -383,26 +383,6 @@ impl KnownModules {
383383
Some((section, reason))
384384
}
385385

386-
/// Return the list of modules that are known to be of a given type.
387-
pub fn modules_for_known_type(
388-
&self,
389-
import_type: ImportType,
390-
) -> impl Iterator<Item = &glob::Pattern> {
391-
self.known
392-
.iter()
393-
.filter_map(move |(module, known_section)| {
394-
if let ImportSection::Known(section) = known_section {
395-
if *section == import_type {
396-
Some(module)
397-
} else {
398-
None
399-
}
400-
} else {
401-
None
402-
}
403-
})
404-
}
405-
406386
/// Return the list of user-defined modules, indexed by section.
407387
pub fn user_defined(&self) -> FxHashMap<&str, Vec<&glob::Pattern>> {
408388
let mut user_defined: FxHashMap<&str, Vec<&glob::Pattern>> = FxHashMap::default();

crates/ruff_python_ast/src/name.rs

-4
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ impl<'a> QualifiedName<'a> {
5959
matches!(self.segments(), ["", ..])
6060
}
6161

62-
pub fn is_user_defined(&self) -> bool {
63-
!self.is_builtin()
64-
}
65-
6662
/// If the call path is dot-prefixed, it's an unresolved relative import.
6763
/// Ex) `[".foo", "bar"]` -> `".foo.bar"`
6864
pub fn is_unresolved_import(&self) -> bool {

crates/ruff_python_ast/src/nodes.rs

-14
Original file line numberDiff line numberDiff line change
@@ -3729,20 +3729,6 @@ impl fmt::Display for IpyEscapeKind {
37293729
}
37303730

37313731
impl IpyEscapeKind {
3732-
/// Returns the length of the escape kind token.
3733-
pub fn prefix_len(self) -> TextSize {
3734-
let len = match self {
3735-
IpyEscapeKind::Shell
3736-
| IpyEscapeKind::Magic
3737-
| IpyEscapeKind::Help
3738-
| IpyEscapeKind::Quote
3739-
| IpyEscapeKind::Quote2
3740-
| IpyEscapeKind::Paren => 1,
3741-
IpyEscapeKind::ShCap | IpyEscapeKind::Magic2 | IpyEscapeKind::Help2 => 2,
3742-
};
3743-
len.into()
3744-
}
3745-
37463732
/// Returns `true` if the escape kind is help i.e., `?` or `??`.
37473733
pub const fn is_help(self) -> bool {
37483734
matches!(self, IpyEscapeKind::Help | IpyEscapeKind::Help2)

crates/ruff_python_ast/src/traversal.rs

-12
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,3 @@ pub fn next_sibling<'a>(stmt: &'a Stmt, suite: &'a Suite) -> Option<&'a Stmt> {
7979
}
8080
None
8181
}
82-
83-
/// Given a [`Stmt`] and its containing [`Suite`], return the previous [`Stmt`] in the [`Suite`].
84-
pub fn prev_sibling<'a>(stmt: &'a Stmt, suite: &'a Suite) -> Option<&'a Stmt> {
85-
let mut prev = None;
86-
for sibling in suite {
87-
if sibling == stmt {
88-
return prev;
89-
}
90-
prev = Some(sibling);
91-
}
92-
None
93-
}

crates/ruff_python_literal/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ doctest = false
1818
ruff_python_ast = { workspace = true }
1919

2020
bitflags = { workspace = true }
21-
hexf-parse = { workspace = true }
2221
itertools = { workspace = true }
23-
lexical-parse-float = { workspace = true, features = ["format"] }
2422
unic-ucd-category = { workspace = true }
2523

2624
[dev-dependencies]

crates/ruff_python_literal/src/cformat.rs

+2-51
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
//! Implementation of Printf-Style string formatting
22
//! as per the [Python Docs](https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting).
3-
use bitflags::bitflags;
43
use std::{
54
fmt,
65
iter::{Enumerate, Peekable},
76
str::FromStr,
87
};
98

9+
use bitflags::bitflags;
10+
1011
use crate::Case;
1112

1213
#[derive(Debug, PartialEq)]
@@ -96,19 +97,6 @@ bitflags! {
9697
}
9798
}
9899

99-
impl CConversionFlags {
100-
#[inline]
101-
pub fn sign_string(&self) -> &'static str {
102-
if self.contains(CConversionFlags::SIGN_CHAR) {
103-
"+"
104-
} else if self.contains(CConversionFlags::BLANK_SIGN) {
105-
" "
106-
} else {
107-
""
108-
}
109-
}
110-
}
111-
112100
#[derive(Debug, PartialEq)]
113101
pub enum CFormatQuantity {
114102
Amount(usize),
@@ -337,44 +325,12 @@ pub enum CFormatPart<T> {
337325
Spec(CFormatSpec),
338326
}
339327

340-
impl<T> CFormatPart<T> {
341-
#[inline]
342-
pub fn is_specifier(&self) -> bool {
343-
matches!(self, CFormatPart::Spec(_))
344-
}
345-
346-
#[inline]
347-
pub fn has_key(&self) -> bool {
348-
match self {
349-
CFormatPart::Spec(s) => s.mapping_key.is_some(),
350-
CFormatPart::Literal(_) => false,
351-
}
352-
}
353-
}
354-
355328
#[derive(Debug, PartialEq)]
356329
pub struct CFormatStrOrBytes<S> {
357330
parts: Vec<(usize, CFormatPart<S>)>,
358331
}
359332

360333
impl<S> CFormatStrOrBytes<S> {
361-
pub fn check_specifiers(&self) -> Option<(usize, bool)> {
362-
let mut count = 0;
363-
let mut mapping_required = false;
364-
for (_, part) in &self.parts {
365-
if part.is_specifier() {
366-
let has_key = part.has_key();
367-
if count == 0 {
368-
mapping_required = has_key;
369-
} else if mapping_required != has_key {
370-
return None;
371-
}
372-
count += 1;
373-
}
374-
}
375-
Some((count, mapping_required))
376-
}
377-
378334
#[inline]
379335
pub fn iter(&self) -> impl Iterator<Item = &(usize, CFormatPart<S>)> {
380336
self.parts.iter()
@@ -430,11 +386,6 @@ impl CFormatBytes {
430386
}
431387
Ok(Self { parts })
432388
}
433-
434-
pub fn parse_from_bytes(bytes: &[u8]) -> Result<Self, CFormatError> {
435-
let mut iter = bytes.iter().copied().enumerate().peekable();
436-
Self::parse(&mut iter)
437-
}
438389
}
439390

440391
pub type CFormatString = CFormatStrOrBytes<String>;

crates/ruff_python_literal/src/escape.rs

-21
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ pub struct UnicodeEscape<'a> {
5050
}
5151

5252
impl<'a> UnicodeEscape<'a> {
53-
#[inline]
54-
pub fn with_forced_quote(source: &'a str, quote: Quote) -> Self {
55-
let layout = EscapeLayout { quote, len: None };
56-
Self { source, layout }
57-
}
5853
#[inline]
5954
pub fn with_preferred_quote(source: &'a str, quote: Quote) -> Self {
6055
let layout = Self::repr_layout(source, quote);
@@ -240,11 +235,6 @@ impl<'a> AsciiEscape<'a> {
240235
Self { source, layout }
241236
}
242237
#[inline]
243-
pub fn with_forced_quote(source: &'a [u8], quote: Quote) -> Self {
244-
let layout = EscapeLayout { quote, len: None };
245-
Self { source, layout }
246-
}
247-
#[inline]
248238
pub fn with_preferred_quote(source: &'a [u8], quote: Quote) -> Self {
249239
let layout = Self::repr_layout(source, quote);
250240
Self { source, layout }
@@ -271,17 +261,6 @@ impl AsciiEscape<'_> {
271261
})
272262
}
273263

274-
#[allow(
275-
clippy::cast_possible_wrap,
276-
clippy::cast_possible_truncation,
277-
clippy::cast_sign_loss
278-
)]
279-
pub fn named_repr_layout(source: &[u8], name: &str) -> EscapeLayout {
280-
Self::output_layout_with_checker(source, Quote::Single, name.len() + 2 + 3, |a, b| {
281-
Some((a as isize).checked_add(b as isize)? as usize)
282-
})
283-
}
284-
285264
fn output_layout_with_checker(
286265
source: &[u8],
287266
preferred_quote: Quote,

0 commit comments

Comments
 (0)