From 41caad126730a36bd7fb09ee13fffafc47d97d93 Mon Sep 17 00:00:00 2001 From: Evan Rittenhouse Date: Tue, 15 Aug 2023 22:52:19 -0500 Subject: [PATCH] Compiler panic? --- .../test/fixtures/ruff/statement/match.py | 11 +++++++++++ .../src/pattern/pattern_match_value.rs | 14 ++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/match.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/match.py index 48e84e98e3eb03..728684ef4d4d1f 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/match.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/match.py @@ -141,3 +141,14 @@ def foo(): no_comments ): pass + +match pattern_comments: + case value: + pass + # leading comment + case value1: + pass + case value2: # trailing + pass + case value3: + pass diff --git a/crates/ruff_python_formatter/src/pattern/pattern_match_value.rs b/crates/ruff_python_formatter/src/pattern/pattern_match_value.rs index 8e824e8fe4396a..733d6b9f7f1f0a 100644 --- a/crates/ruff_python_formatter/src/pattern/pattern_match_value.rs +++ b/crates/ruff_python_formatter/src/pattern/pattern_match_value.rs @@ -1,19 +1,17 @@ use ruff_formatter::{write, Buffer, FormatResult}; use ruff_python_ast::PatternMatchValue; -use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter}; +use crate::{AsFormat, FormatNodeRule, PyFormatter}; #[derive(Default)] pub struct FormatPatternMatchValue; impl FormatNodeRule for FormatPatternMatchValue { fn fmt_fields(&self, item: &PatternMatchValue, f: &mut PyFormatter) -> FormatResult<()> { - write!( - f, - [not_yet_implemented_custom_text( - "\"NOT_YET_IMPLEMENTED_PatternMatchValue\"", - item - )] - ) + let PatternMatchValue { value, .. } = item; + + let formatted = value.format(); + + write!(f, [formatted]) } }