@@ -29,17 +29,29 @@ pub fn parse_strings(
29
29
} ) ;
30
30
}
31
31
32
+ if values. len ( ) > 1 && cfg ! ( feature = "implicit-concat-as-joined-str" ) {
33
+ let mut exprs: Vec < Expr > = vec ! [ ] ;
34
+ for ( start, ( source, kind, triple_quoted) , end) in values {
35
+ let expr = parse_string ( & source, kind, triple_quoted, start, end) ?;
36
+ exprs. push ( expr) ;
37
+ }
38
+ return Ok ( Expr :: new (
39
+ initial_start,
40
+ last_end,
41
+ ExprKind :: JoinedStr { values : exprs } ,
42
+ ) ) ;
43
+ }
44
+
32
45
if has_bytes {
33
46
let mut content: Vec < u8 > = vec ! [ ] ;
34
47
for ( start, ( source, kind, triple_quoted) , end) in values {
35
- for value in parse_string ( & source, kind, triple_quoted, start, end) ? {
36
- match value. node {
37
- ExprKind :: Constant {
38
- value : Constant :: Bytes ( value) ,
39
- ..
40
- } => content. extend ( value) ,
41
- _ => unreachable ! ( "Unexpected non-bytes expression." ) ,
42
- }
48
+ let expr = parse_string ( & source, kind, triple_quoted, start, end) ?;
49
+ match expr. node {
50
+ ExprKind :: Constant {
51
+ value : Constant :: Bytes ( value) ,
52
+ ..
53
+ } => content. extend ( value) ,
54
+ _ => unreachable ! ( "Unexpected non-bytes expression." ) ,
43
55
}
44
56
}
45
57
return Ok ( Expr :: new (
@@ -55,14 +67,13 @@ pub fn parse_strings(
55
67
if !has_fstring {
56
68
let mut content: Vec < String > = vec ! [ ] ;
57
69
for ( start, ( source, kind, triple_quoted) , end) in values {
58
- for value in parse_string ( & source, kind, triple_quoted, start, end) ? {
59
- match value. node {
60
- ExprKind :: Constant {
61
- value : Constant :: Str ( value) ,
62
- ..
63
- } => content. push ( value) ,
64
- _ => unreachable ! ( "Unexpected non-string expression." ) ,
65
- }
70
+ let expr = parse_string ( & source, kind, triple_quoted, start, end) ?;
71
+ match expr. node {
72
+ ExprKind :: Constant {
73
+ value : Constant :: Str ( value) ,
74
+ ..
75
+ } => content. push ( value) ,
76
+ _ => unreachable ! ( "Unexpected non-string expression." ) ,
66
77
}
67
78
}
68
79
return Ok ( Expr :: new (
@@ -91,20 +102,30 @@ pub fn parse_strings(
91
102
} ;
92
103
93
104
for ( start, ( source, kind, triple_quoted) , end) in values {
94
- for value in parse_string ( & source, kind, triple_quoted, start, end) ? {
95
- match value. node {
96
- ExprKind :: FormattedValue { .. } => {
97
- if !current. is_empty ( ) {
98
- deduped. push ( take_current ( & mut current) ) ;
105
+ let expr = parse_string ( & source, kind, triple_quoted, start, end) ?;
106
+ match expr. node {
107
+ ExprKind :: Constant {
108
+ value : Constant :: Str ( value) ,
109
+ ..
110
+ } => current. push ( value) ,
111
+ ExprKind :: JoinedStr { values } => {
112
+ for value in values {
113
+ match value. node {
114
+ ExprKind :: Constant {
115
+ value : Constant :: Str ( value) ,
116
+ ..
117
+ } => current. push ( value) ,
118
+ ExprKind :: FormattedValue { .. } => {
119
+ if !current. is_empty ( ) {
120
+ deduped. push ( take_current ( & mut current) ) ;
121
+ }
122
+ deduped. push ( value)
123
+ }
124
+ _ => unreachable ! ( "Unexpected non-string expression." ) ,
99
125
}
100
- deduped. push ( value)
101
126
}
102
- ExprKind :: Constant {
103
- value : Constant :: Str ( value) ,
104
- ..
105
- } => current. push ( value) ,
106
- _ => unreachable ! ( "Unexpected non-string expression." ) ,
107
127
}
128
+ _ => unreachable ! ( "Unexpected non-string expression." ) ,
108
129
}
109
130
}
110
131
if !current. is_empty ( ) {
0 commit comments