Skip to content

Commit 6922c68

Browse files
authored
Clean up redundant Cow usage in variables scopes (#831)
* Clean up redundant Cow usage in variables scopes * clippy
1 parent dfd2442 commit 6922c68

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

librubyfmt/src/parser_state.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,15 @@ pub struct ParserState<'src> {
6767
formatting_context: Vec<FormattingContext>,
6868
insert_user_newlines: bool,
6969
spaces_after_last_newline: ColNumber,
70-
scopes: Vec<Vec<Cow<'src, str>>>,
70+
scopes: Vec<Vec<&'src str>>,
7171
/// Whether we're currently rendering inside a squiggly heredoc's content.
7272
/// Used to mark nested non-squiggly heredocs so they don't get incorrect indentation.
7373
inside_squiggly_heredoc: bool,
7474
}
7575

7676
impl<'src> ParserState<'src> {
7777
pub(crate) fn scope_has_variable(&self, s: &str) -> bool {
78-
self.scopes
79-
.last()
80-
.expect("it's never empty")
81-
.iter()
82-
.any(|e| e == s)
78+
self.scopes.last().expect("it's never empty").contains(&s)
8379
}
8480
pub(crate) fn new_scope<F>(&mut self, f: F)
8581
where
@@ -89,11 +85,8 @@ impl<'src> ParserState<'src> {
8985
f(self);
9086
self.scopes.pop();
9187
}
92-
pub(crate) fn bind_variable(&mut self, s: impl Into<Cow<'src, str>>) {
93-
self.scopes
94-
.last_mut()
95-
.expect("it's never empty")
96-
.push(s.into());
88+
pub(crate) fn bind_variable(&mut self, s: &'src str) {
89+
self.scopes.last_mut().expect("it's never empty").push(s);
9790
}
9891
pub(crate) fn push_heredoc_content<F>(
9992
&mut self,

0 commit comments

Comments
 (0)