diff --git a/crates/ruff_python_formatter/src/generated.rs b/crates/ruff_python_formatter/src/generated.rs index dfa93b8961ac3..30b5bb122ae9e 100644 --- a/crates/ruff_python_formatter/src/generated.rs +++ b/crates/ruff_python_formatter/src/generated.rs @@ -2978,3 +2978,103 @@ impl<'ast> IntoFormat> for ast::TypeParamParamSpec { ) } } + +impl FormatRule> for crate::other::f_string::FormatFString { + #[inline] + fn fmt(&self, node: &ast::FString, f: &mut PyFormatter) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl<'ast> AsFormat> for ast::FString { + type Format<'a> = FormatRefWithRule< + 'a, + ast::FString, + crate::other::f_string::FormatFString, + PyFormatContext<'ast>, + >; + fn format(&self) -> Self::Format<'_> { + FormatRefWithRule::new(self, crate::other::f_string::FormatFString::default()) + } +} +impl<'ast> IntoFormat> for ast::FString { + type Format = FormatOwnedWithRule< + ast::FString, + crate::other::f_string::FormatFString, + PyFormatContext<'ast>, + >; + fn into_format(self) -> Self::Format { + FormatOwnedWithRule::new(self, crate::other::f_string::FormatFString::default()) + } +} + +impl FormatRule> + for crate::other::string_literal::FormatStringLiteral +{ + #[inline] + fn fmt(&self, node: &ast::StringLiteral, f: &mut PyFormatter) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl<'ast> AsFormat> for ast::StringLiteral { + type Format<'a> = FormatRefWithRule< + 'a, + ast::StringLiteral, + crate::other::string_literal::FormatStringLiteral, + PyFormatContext<'ast>, + >; + fn format(&self) -> Self::Format<'_> { + FormatRefWithRule::new( + self, + crate::other::string_literal::FormatStringLiteral::default(), + ) + } +} +impl<'ast> IntoFormat> for ast::StringLiteral { + type Format = FormatOwnedWithRule< + ast::StringLiteral, + crate::other::string_literal::FormatStringLiteral, + PyFormatContext<'ast>, + >; + fn into_format(self) -> Self::Format { + FormatOwnedWithRule::new( + self, + crate::other::string_literal::FormatStringLiteral::default(), + ) + } +} + +impl FormatRule> + for crate::other::bytes_literal::FormatBytesLiteral +{ + #[inline] + fn fmt(&self, node: &ast::BytesLiteral, f: &mut PyFormatter) -> FormatResult<()> { + FormatNodeRule::::fmt(self, node, f) + } +} +impl<'ast> AsFormat> for ast::BytesLiteral { + type Format<'a> = FormatRefWithRule< + 'a, + ast::BytesLiteral, + crate::other::bytes_literal::FormatBytesLiteral, + PyFormatContext<'ast>, + >; + fn format(&self) -> Self::Format<'_> { + FormatRefWithRule::new( + self, + crate::other::bytes_literal::FormatBytesLiteral::default(), + ) + } +} +impl<'ast> IntoFormat> for ast::BytesLiteral { + type Format = FormatOwnedWithRule< + ast::BytesLiteral, + crate::other::bytes_literal::FormatBytesLiteral, + PyFormatContext<'ast>, + >; + fn into_format(self) -> Self::Format { + FormatOwnedWithRule::new( + self, + crate::other::bytes_literal::FormatBytesLiteral::default(), + ) + } +} diff --git a/crates/ruff_python_formatter/src/other/bytes_literal.rs b/crates/ruff_python_formatter/src/other/bytes_literal.rs new file mode 100644 index 0000000000000..55117241f8598 --- /dev/null +++ b/crates/ruff_python_formatter/src/other/bytes_literal.rs @@ -0,0 +1,12 @@ +use ruff_python_ast::BytesLiteral; + +use crate::prelude::*; + +#[derive(Default)] +pub struct FormatBytesLiteral; + +impl FormatNodeRule for FormatBytesLiteral { + fn fmt_fields(&self, _item: &BytesLiteral, _f: &mut PyFormatter) -> FormatResult<()> { + unreachable!("Handled inside of `FormatExprBytesLiteral`"); + } +} diff --git a/crates/ruff_python_formatter/src/other/f_string.rs b/crates/ruff_python_formatter/src/other/f_string.rs new file mode 100644 index 0000000000000..e08254aba7511 --- /dev/null +++ b/crates/ruff_python_formatter/src/other/f_string.rs @@ -0,0 +1,12 @@ +use ruff_python_ast::FString; + +use crate::prelude::*; + +#[derive(Default)] +pub struct FormatFString; + +impl FormatNodeRule for FormatFString { + fn fmt_fields(&self, _item: &FString, _f: &mut PyFormatter) -> FormatResult<()> { + unreachable!("Handled inside of `FormatExprFString`"); + } +} diff --git a/crates/ruff_python_formatter/src/other/mod.rs b/crates/ruff_python_formatter/src/other/mod.rs index e7eb28ae7f4fd..c980a14c0fe09 100644 --- a/crates/ruff_python_formatter/src/other/mod.rs +++ b/crates/ruff_python_formatter/src/other/mod.rs @@ -1,14 +1,17 @@ pub(crate) mod alias; pub(crate) mod arguments; +pub(crate) mod bytes_literal; pub(crate) mod commas; pub(crate) mod comprehension; pub(crate) mod decorator; pub(crate) mod elif_else_clause; pub(crate) mod except_handler_except_handler; +pub(crate) mod f_string; pub(crate) mod identifier; pub(crate) mod keyword; pub(crate) mod match_case; pub(crate) mod parameter; pub(crate) mod parameter_with_default; pub(crate) mod parameters; +pub(crate) mod string_literal; pub(crate) mod with_item; diff --git a/crates/ruff_python_formatter/src/other/string_literal.rs b/crates/ruff_python_formatter/src/other/string_literal.rs new file mode 100644 index 0000000000000..291552db73a1d --- /dev/null +++ b/crates/ruff_python_formatter/src/other/string_literal.rs @@ -0,0 +1,12 @@ +use ruff_python_ast::StringLiteral; + +use crate::prelude::*; + +#[derive(Default)] +pub struct FormatStringLiteral; + +impl FormatNodeRule for FormatStringLiteral { + fn fmt_fields(&self, _item: &StringLiteral, _f: &mut PyFormatter) -> FormatResult<()> { + unreachable!("Handled inside of `FormatExprStringLiteral`"); + } +}