diff --git a/crates/ruff_python_formatter/src/expression/expr_f_string.rs b/crates/ruff_python_formatter/src/expression/expr_f_string.rs index 8976f3801d061b..dd67fd1bea0afe 100644 --- a/crates/ruff_python_formatter/src/expression/expr_f_string.rs +++ b/crates/ruff_python_formatter/src/expression/expr_f_string.rs @@ -4,7 +4,7 @@ use ruff_text_size::TextSlice; use crate::expression::parentheses::{ in_parentheses_only_group, NeedsParentheses, OptionalParentheses, }; -use crate::other::f_string_part::FormatFStringPart; +use crate::other::f_string::FormatFString; use crate::prelude::*; use crate::string::implicit::FormatImplicitConcatenatedStringFlat; use crate::string::{implicit::FormatImplicitConcatenatedString, Quoting, StringLikeExtensions}; @@ -17,8 +17,11 @@ impl FormatNodeRule for FormatExprFString { let ExprFString { value, .. } = item; if let [f_string_part] = value.as_slice() { - FormatFStringPart::new(f_string_part, f_string_quoting(item, f.context().source())) - .fmt(f) + // SAFETY: A single string literal cannot be an f-string. This is guaranteed by the + // [`ruff_python_ast::FStringValue::single`] constructor. + let f_string = f_string_part.as_f_string().unwrap(); + + FormatFString::new(f_string, f_string_quoting(item, f.context().source())).fmt(f) } else { // Always join fstrings that aren't parenthesized and thus, are always on a single line. if !f.context().node_level().is_parenthesized() { diff --git a/crates/ruff_python_formatter/src/other/f_string_part.rs b/crates/ruff_python_formatter/src/other/f_string_part.rs deleted file mode 100644 index d33148aaccc44b..00000000000000 --- a/crates/ruff_python_formatter/src/other/f_string_part.rs +++ /dev/null @@ -1,38 +0,0 @@ -use ruff_python_ast::FStringPart; - -use crate::other::f_string::FormatFString; -use crate::other::string_literal::StringLiteralKind; -use crate::prelude::*; -use crate::string::Quoting; - -/// Formats an f-string part which is either a string literal or an f-string. -/// -/// This delegates the actual formatting to the appropriate formatter. -pub(crate) struct FormatFStringPart<'a> { - part: &'a FStringPart, - /// The quoting to be used for all the f-string parts. This is determined by - /// the parent node (f-string expression) and is required to format all parts - /// correctly. - quoting: Quoting, -} - -impl<'a> FormatFStringPart<'a> { - pub(crate) fn new(part: &'a FStringPart, quoting: Quoting) -> Self { - Self { part, quoting } - } -} - -impl Format> for FormatFStringPart<'_> { - fn fmt(&self, f: &mut PyFormatter) -> FormatResult<()> { - match self.part { - #[allow(deprecated)] - FStringPart::Literal(string_literal) => string_literal - .format() - .with_options(StringLiteralKind::InImplicitlyConcatenatedFString( - self.quoting, - )) - .fmt(f), - FStringPart::FString(f_string) => FormatFString::new(f_string, self.quoting).fmt(f), - } - } -} diff --git a/crates/ruff_python_formatter/src/other/mod.rs b/crates/ruff_python_formatter/src/other/mod.rs index 2aace837913c4f..b55b1a70f6e594 100644 --- a/crates/ruff_python_formatter/src/other/mod.rs +++ b/crates/ruff_python_formatter/src/other/mod.rs @@ -8,7 +8,6 @@ pub(crate) mod elif_else_clause; pub(crate) mod except_handler_except_handler; pub(crate) mod f_string; pub(crate) mod f_string_element; -pub(crate) mod f_string_part; pub(crate) mod identifier; pub(crate) mod keyword; pub(crate) mod match_case;