From e28e73729698a985556239a578ae1325cdb3fb73 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Mon, 27 May 2024 21:22:13 +0530 Subject: [PATCH] Update `FStringElements` to deref to a slice (#11570) Ref: https://github.com/astral-sh/ruff/pull/11400#discussion_r1615600354 --- crates/ruff_python_ast/src/nodes.rs | 2 +- crates/ruff_python_parser/src/parser/expression.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/ruff_python_ast/src/nodes.rs b/crates/ruff_python_ast/src/nodes.rs index be96f89450c4d..a2fce003ee90f 100644 --- a/crates/ruff_python_ast/src/nodes.rs +++ b/crates/ruff_python_ast/src/nodes.rs @@ -1580,7 +1580,7 @@ impl<'a> IntoIterator for &'a mut FStringElements { } impl Deref for FStringElements { - type Target = Vec; + type Target = [FStringElement]; fn deref(&self) -> &Self::Target { &self.0 diff --git a/crates/ruff_python_parser/src/parser/expression.rs b/crates/ruff_python_parser/src/parser/expression.rs index c512b22999f7b..fbb836c7597ca 100644 --- a/crates/ruff_python_parser/src/parser/expression.rs +++ b/crates/ruff_python_parser/src/parser/expression.rs @@ -1298,7 +1298,7 @@ impl<'src> Parser<'src> { /// /// If the parser isn't positioned at a `{` or `FStringMiddle` token. fn parse_fstring_elements(&mut self) -> FStringElements { - let mut elements = FStringElements::default(); + let mut elements = vec![]; self.parse_list(RecoveryContextKind::FStringElements, |parser| { let element = match parser.current_token_kind() { @@ -1348,7 +1348,7 @@ impl<'src> Parser<'src> { elements.push(element); }); - elements + FStringElements::from(elements) } /// Parses a f-string expression element.