@@ -89,7 +89,7 @@ enum Type {
89
89
}
90
90
91
91
/// Recursively merge all the tuples and lists in the expression.
92
- fn concatenate_expressions ( expr : & Expr ) -> Option < ( Expr , Type ) > {
92
+ fn concatenate_expressions ( expr : & Expr , should_support_slices : bool ) -> Option < ( Expr , Type ) > {
93
93
let Expr :: BinOp ( ast:: ExprBinOp {
94
94
left,
95
95
op : Operator :: Add ,
@@ -101,18 +101,22 @@ fn concatenate_expressions(expr: &Expr) -> Option<(Expr, Type)> {
101
101
} ;
102
102
103
103
let new_left = match left. as_ref ( ) {
104
- Expr :: BinOp ( ast:: ExprBinOp { .. } ) => match concatenate_expressions ( left) {
105
- Some ( ( new_left, _) ) => new_left,
106
- None => * left. clone ( ) ,
107
- } ,
104
+ Expr :: BinOp ( ast:: ExprBinOp { .. } ) => {
105
+ match concatenate_expressions ( left, should_support_slices) {
106
+ Some ( ( new_left, _) ) => new_left,
107
+ None => * left. clone ( ) ,
108
+ }
109
+ }
108
110
_ => * left. clone ( ) ,
109
111
} ;
110
112
111
113
let new_right = match right. as_ref ( ) {
112
- Expr :: BinOp ( ast:: ExprBinOp { .. } ) => match concatenate_expressions ( right) {
113
- Some ( ( new_right, _) ) => new_right,
114
- None => * right. clone ( ) ,
115
- } ,
114
+ Expr :: BinOp ( ast:: ExprBinOp { .. } ) => {
115
+ match concatenate_expressions ( right, should_support_slices) {
116
+ Some ( ( new_right, _) ) => new_right,
117
+ None => * right. clone ( ) ,
118
+ }
119
+ }
116
120
_ => * right. clone ( ) ,
117
121
} ;
118
122
@@ -140,7 +144,9 @@ fn concatenate_expressions(expr: &Expr) -> Option<(Expr, Type)> {
140
144
make_splat_elts ( splat_element, other_elements, splat_at_left)
141
145
}
142
146
// Subscripts are also considered safe-ish to splat if the indexer is a slice.
143
- Expr :: Subscript ( ast:: ExprSubscript { slice, .. } ) if matches ! ( & * * slice, Expr :: Slice ( _) ) => {
147
+ Expr :: Subscript ( ast:: ExprSubscript { slice, .. } )
148
+ if should_support_slices && matches ! ( & * * slice, Expr :: Slice ( _) ) =>
149
+ {
144
150
make_splat_elts ( splat_element, other_elements, splat_at_left)
145
151
}
146
152
// If the splat element is itself a list/tuple, insert them in the other list/tuple.
@@ -185,7 +191,9 @@ pub(crate) fn collection_literal_concatenation(checker: &Checker, expr: &Expr) {
185
191
return ;
186
192
}
187
193
188
- let Some ( ( new_expr, type_) ) = concatenate_expressions ( expr) else {
194
+ let should_support_slices = checker. settings . preview . is_enabled ( ) ;
195
+
196
+ let Some ( ( new_expr, type_) ) = concatenate_expressions ( expr, should_support_slices) else {
189
197
return ;
190
198
} ;
191
199
0 commit comments