Avoid creating unused JoinedStr in FStringParser

This commit is contained in:
Charles Marsh 2022-08-19 10:47:37 -04:00
parent 53c48bf6b9
commit 2345bc895d
14 changed files with 598 additions and 775 deletions

View file

@ -34,19 +34,10 @@ pub fn parse_strings(values: Vec<(Location, (String, StringKind))>) -> Result<Ex
StringKind::Normal | StringKind::U => current.push(string),
StringKind::F => {
has_fstring = true;
let values = if let ExprKind::JoinedStr { values } =
parse_located_fstring(&string, location)
.map_err(|e| LexicalError {
location,
error: LexicalErrorType::FStringError(e.error),
})?
.node
{
values
} else {
unreachable!("parse_located_fstring returned a non-JoinedStr.")
};
for value in values {
for value in parse_located_fstring(&string, location).map_err(|e| LexicalError {
location,
error: LexicalErrorType::FStringError(e.error),
})? {
match value.node {
ExprKind::FormattedValue { .. } => {
if !current.is_empty() {