Skip to content

Commit 76e747a

Browse files
committed
Use drain
1 parent 72c0a06 commit 76e747a

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

compiler/parser/src/string_parser.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
parser::parse_expression_located,
66
token::StringKind,
77
};
8-
use std::{iter, mem, str};
8+
use std::{iter, str};
99

1010
/// unicode_name2 does not expose `MAX_NAME_LENGTH`, so we replicate that constant here, fix #3798
1111
pub const MAX_UNICODE_NAME: usize = 88;
@@ -365,10 +365,9 @@ impl<'a> StringParser<'a> {
365365
'{' => {
366366
if !constant_piece.is_empty() {
367367
spec_constructor.push(self.expr(ExprKind::Constant {
368-
value: constant_piece.to_owned().into(),
368+
value: constant_piece.drain(..).collect::<String>().into(),
369369
kind: None,
370370
}));
371-
constant_piece.clear();
372371
}
373372
let parsed_expr = self.parse_fstring(nested + 1)?;
374373
spec_constructor.extend(parsed_expr);
@@ -385,10 +384,9 @@ impl<'a> StringParser<'a> {
385384
}
386385
if !constant_piece.is_empty() {
387386
spec_constructor.push(self.expr(ExprKind::Constant {
388-
value: constant_piece.to_owned().into(),
387+
value: constant_piece.drain(..).collect::<String>().into(),
389388
kind: None,
390389
}));
391-
constant_piece.clear();
392390
}
393391
Ok(spec_constructor)
394392
}
@@ -418,7 +416,7 @@ impl<'a> StringParser<'a> {
418416
}
419417
if !content.is_empty() {
420418
values.push(self.expr(ExprKind::Constant {
421-
value: mem::take(&mut content).into(),
419+
value: content.drain(..).collect::<String>().into(),
422420
kind: None,
423421
}));
424422
}

0 commit comments

Comments
 (0)