diff --git a/Cargo.lock b/Cargo.lock index ec542070a5d62..35d0f9e877123 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2367,7 +2367,6 @@ dependencies = [ "clap", "countme", "insta", - "is-macro", "itertools", "memchr", "once_cell", diff --git a/crates/ruff_python_formatter/Cargo.toml b/crates/ruff_python_formatter/Cargo.toml index 1aae33a9edc0b..8e7a3b55ad648 100644 --- a/crates/ruff_python_formatter/Cargo.toml +++ b/crates/ruff_python_formatter/Cargo.toml @@ -23,7 +23,6 @@ anyhow = { workspace = true } bitflags = { workspace = true } clap = { workspace = true } countme = "3.0.1" -is-macro = { workspace = true } itertools = { workspace = true } memchr = { workspace = true } once_cell = { workspace = true } diff --git a/crates/ruff_python_formatter/src/expression/mod.rs b/crates/ruff_python_formatter/src/expression/mod.rs index 39af5b79e9e37..413b732a531ce 100644 --- a/crates/ruff_python_formatter/src/expression/mod.rs +++ b/crates/ruff_python_formatter/src/expression/mod.rs @@ -388,10 +388,10 @@ fn can_omit_optional_parentheses(expr: &Expr, context: &PyFormatContext) -> bool // Only use the layout if the first or last expression has parentheses of some sort, and // those parentheses are non-empty. let first_parenthesized = visitor.first.is_some_and(|first| { - has_parentheses(first, context).is_some_and(|parentheses| parentheses.is_non_empty()) + has_parentheses(first, context).is_some_and(OwnParentheses::is_non_empty) }); let last_parenthesized = visitor.last.is_some_and(|last| { - has_parentheses(last, context).is_some_and(|parentheses| parentheses.is_non_empty()) + has_parentheses(last, context).is_some_and(OwnParentheses::is_non_empty) }); first_parenthesized || last_parenthesized } @@ -706,7 +706,7 @@ impl CallChainLayout { } } -#[derive(Debug, Copy, Clone, PartialEq, Eq, is_macro::Is)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub(crate) enum OwnParentheses { /// The node has parentheses, but they are empty (e.g., `[]` or `f()`). Empty, @@ -714,6 +714,12 @@ pub(crate) enum OwnParentheses { NonEmpty, } +impl OwnParentheses { + const fn is_non_empty(self) -> bool { + matches!(self, OwnParentheses::NonEmpty) + } +} + /// Returns the [`OwnParentheses`] value for a given [`Expr`], to indicate whether it has its /// own parentheses or is itself parenthesized. ///