Skip to content

Commit

Permalink
Remove some unused pub functions (#11576)
Browse files Browse the repository at this point in the history
## Summary

I left anything in `red-knot`, any `with_` methods, etc.
  • Loading branch information
charliermarsh authored May 28, 2024
1 parent 3989cb8 commit 16acd49
Show file tree
Hide file tree
Showing 14 changed files with 7 additions and 495 deletions.
38 changes: 0 additions & 38 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ filetime = { version = "0.2.23" }
glob = { version = "0.3.1" }
globset = { version = "0.4.14" }
hashbrown = "0.14.3"
hexf-parse = { version = "0.2.1" }
ignore = { version = "0.4.22" }
imara-diff = { version = "0.1.5" }
imperative = { version = "1.0.4" }
Expand All @@ -76,12 +75,11 @@ is-wsl = { version = "0.4.0" }
itertools = { version = "0.12.1" }
js-sys = { version = "0.3.69" }
jod-thread = { version = "0.1.2" }
lexical-parse-float = { version = "0.8.0", features = ["format"] }
libc = { version = "0.2.153" }
libcst = { version = "1.1.0", default-features = false }
log = { version = "0.4.17" }
lsp-server = { version = "0.7.6" }
lsp-types = { git="https://github.com/astral-sh/lsp-types.git", rev = "3512a9f", features = ["proposed"] }
lsp-types = { git = "https://github.com/astral-sh/lsp-types.git", rev = "3512a9f", features = ["proposed"] }
matchit = { version = "0.8.1" }
memchr = { version = "2.7.1" }
mimalloc = { version = "0.1.39" }
Expand Down
9 changes: 0 additions & 9 deletions crates/ruff_formatter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,11 +553,6 @@ impl PrintedRange {
pub fn source_range(&self) -> TextRange {
self.source_range
}

#[must_use]
pub fn with_code(self, code: String) -> Self {
Self { code, ..self }
}
}

/// Public return type of the formatter
Expand Down Expand Up @@ -780,10 +775,6 @@ where
self.item = item;
self
}

pub fn into_item(self) -> T {
self.item
}
}

impl<T, R, C> Format<C> for FormatOwnedWithRule<T, R, C>
Expand Down
16 changes: 0 additions & 16 deletions crates/ruff_linter/src/directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,6 @@ pub struct IsortDirectives {
pub skip_file: bool,
}

impl IsortDirectives {
pub fn is_excluded(&self, offset: TextSize) -> bool {
for range in &self.exclusions {
if range.contains(offset) {
return true;
}

if range.start() > offset {
break;
}
}

false
}
}

pub struct Directives {
pub noqa_line_for: NoqaMapping,
pub isort: IsortDirectives,
Expand Down
20 changes: 0 additions & 20 deletions crates/ruff_linter/src/rules/isort/categorize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,26 +383,6 @@ impl KnownModules {
Some((section, reason))
}

/// Return the list of modules that are known to be of a given type.
pub fn modules_for_known_type(
&self,
import_type: ImportType,
) -> impl Iterator<Item = &glob::Pattern> {
self.known
.iter()
.filter_map(move |(module, known_section)| {
if let ImportSection::Known(section) = known_section {
if *section == import_type {
Some(module)
} else {
None
}
} else {
None
}
})
}

/// Return the list of user-defined modules, indexed by section.
pub fn user_defined(&self) -> FxHashMap<&str, Vec<&glob::Pattern>> {
let mut user_defined: FxHashMap<&str, Vec<&glob::Pattern>> = FxHashMap::default();
Expand Down
4 changes: 0 additions & 4 deletions crates/ruff_python_ast/src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ impl<'a> QualifiedName<'a> {
matches!(self.segments(), ["", ..])
}

pub fn is_user_defined(&self) -> bool {
!self.is_builtin()
}

/// If the call path is dot-prefixed, it's an unresolved relative import.
/// Ex) `[".foo", "bar"]` -> `".foo.bar"`
pub fn is_unresolved_import(&self) -> bool {
Expand Down
14 changes: 0 additions & 14 deletions crates/ruff_python_ast/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3729,20 +3729,6 @@ impl fmt::Display for IpyEscapeKind {
}

impl IpyEscapeKind {
/// Returns the length of the escape kind token.
pub fn prefix_len(self) -> TextSize {
let len = match self {
IpyEscapeKind::Shell
| IpyEscapeKind::Magic
| IpyEscapeKind::Help
| IpyEscapeKind::Quote
| IpyEscapeKind::Quote2
| IpyEscapeKind::Paren => 1,
IpyEscapeKind::ShCap | IpyEscapeKind::Magic2 | IpyEscapeKind::Help2 => 2,
};
len.into()
}

/// Returns `true` if the escape kind is help i.e., `?` or `??`.
pub const fn is_help(self) -> bool {
matches!(self, IpyEscapeKind::Help | IpyEscapeKind::Help2)
Expand Down
12 changes: 0 additions & 12 deletions crates/ruff_python_ast/src/traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,3 @@ pub fn next_sibling<'a>(stmt: &'a Stmt, suite: &'a Suite) -> Option<&'a Stmt> {
}
None
}

/// Given a [`Stmt`] and its containing [`Suite`], return the previous [`Stmt`] in the [`Suite`].
pub fn prev_sibling<'a>(stmt: &'a Stmt, suite: &'a Suite) -> Option<&'a Stmt> {
let mut prev = None;
for sibling in suite {
if sibling == stmt {
return prev;
}
prev = Some(sibling);
}
None
}
2 changes: 0 additions & 2 deletions crates/ruff_python_literal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ doctest = false
ruff_python_ast = { workspace = true }

bitflags = { workspace = true }
hexf-parse = { workspace = true }
itertools = { workspace = true }
lexical-parse-float = { workspace = true, features = ["format"] }
unic-ucd-category = { workspace = true }

[dev-dependencies]
Expand Down
53 changes: 2 additions & 51 deletions crates/ruff_python_literal/src/cformat.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//! Implementation of Printf-Style string formatting
//! as per the [Python Docs](https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting).
use bitflags::bitflags;
use std::{
fmt,
iter::{Enumerate, Peekable},
str::FromStr,
};

use bitflags::bitflags;

use crate::Case;

#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -96,19 +97,6 @@ bitflags! {
}
}

impl CConversionFlags {
#[inline]
pub fn sign_string(&self) -> &'static str {
if self.contains(CConversionFlags::SIGN_CHAR) {
"+"
} else if self.contains(CConversionFlags::BLANK_SIGN) {
" "
} else {
""
}
}
}

#[derive(Debug, PartialEq)]
pub enum CFormatQuantity {
Amount(usize),
Expand Down Expand Up @@ -337,44 +325,12 @@ pub enum CFormatPart<T> {
Spec(CFormatSpec),
}

impl<T> CFormatPart<T> {
#[inline]
pub fn is_specifier(&self) -> bool {
matches!(self, CFormatPart::Spec(_))
}

#[inline]
pub fn has_key(&self) -> bool {
match self {
CFormatPart::Spec(s) => s.mapping_key.is_some(),
CFormatPart::Literal(_) => false,
}
}
}

#[derive(Debug, PartialEq)]
pub struct CFormatStrOrBytes<S> {
parts: Vec<(usize, CFormatPart<S>)>,
}

impl<S> CFormatStrOrBytes<S> {
pub fn check_specifiers(&self) -> Option<(usize, bool)> {
let mut count = 0;
let mut mapping_required = false;
for (_, part) in &self.parts {
if part.is_specifier() {
let has_key = part.has_key();
if count == 0 {
mapping_required = has_key;
} else if mapping_required != has_key {
return None;
}
count += 1;
}
}
Some((count, mapping_required))
}

#[inline]
pub fn iter(&self) -> impl Iterator<Item = &(usize, CFormatPart<S>)> {
self.parts.iter()
Expand Down Expand Up @@ -430,11 +386,6 @@ impl CFormatBytes {
}
Ok(Self { parts })
}

pub fn parse_from_bytes(bytes: &[u8]) -> Result<Self, CFormatError> {
let mut iter = bytes.iter().copied().enumerate().peekable();
Self::parse(&mut iter)
}
}

pub type CFormatString = CFormatStrOrBytes<String>;
Expand Down
21 changes: 0 additions & 21 deletions crates/ruff_python_literal/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ pub struct UnicodeEscape<'a> {
}

impl<'a> UnicodeEscape<'a> {
#[inline]
pub fn with_forced_quote(source: &'a str, quote: Quote) -> Self {
let layout = EscapeLayout { quote, len: None };
Self { source, layout }
}
#[inline]
pub fn with_preferred_quote(source: &'a str, quote: Quote) -> Self {
let layout = Self::repr_layout(source, quote);
Expand Down Expand Up @@ -240,11 +235,6 @@ impl<'a> AsciiEscape<'a> {
Self { source, layout }
}
#[inline]
pub fn with_forced_quote(source: &'a [u8], quote: Quote) -> Self {
let layout = EscapeLayout { quote, len: None };
Self { source, layout }
}
#[inline]
pub fn with_preferred_quote(source: &'a [u8], quote: Quote) -> Self {
let layout = Self::repr_layout(source, quote);
Self { source, layout }
Expand All @@ -271,17 +261,6 @@ impl AsciiEscape<'_> {
})
}

#[allow(
clippy::cast_possible_wrap,
clippy::cast_possible_truncation,
clippy::cast_sign_loss
)]
pub fn named_repr_layout(source: &[u8], name: &str) -> EscapeLayout {
Self::output_layout_with_checker(source, Quote::Single, name.len() + 2 + 3, |a, b| {
Some((a as isize).checked_add(b as isize)? as usize)
})
}

fn output_layout_with_checker(
source: &[u8],
preferred_quote: Quote,
Expand Down
Loading

0 comments on commit 16acd49

Please sign in to comment.