File tree Expand file tree Collapse file tree 1 file changed +52
-1
lines changed
crates/ide-assists/src/handlers Expand file tree Collapse file tree 1 file changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,10 @@ fn binders_in_pat(
16
16
IdentPat ( p) => {
17
17
let ident = p. name ( ) ?;
18
18
let ismut = p. ref_token ( ) . is_none ( ) && p. mut_token ( ) . is_some ( ) ;
19
- acc. push ( ( ident, ismut) ) ;
19
+ // check for const reference
20
+ if !( p. is_simple_ident ( ) && sem. resolve_bind_pat_to_const ( p) . is_some ( ) ) {
21
+ acc. push ( ( ident, ismut) ) ;
22
+ }
20
23
if let Some ( inner) = p. pat ( ) {
21
24
binders_in_pat ( acc, & inner, sem) ?;
22
25
}
@@ -244,6 +247,54 @@ fn main() {
244
247
) ;
245
248
}
246
249
250
+ #[ test]
251
+ fn convert_let_else_to_match_const_ref ( ) {
252
+ check_assist (
253
+ convert_let_else_to_match,
254
+ r"
255
+ enum Option<T> {
256
+ Some(T),
257
+ None,
258
+ }
259
+ use Option::*;
260
+ fn main() {
261
+ let None = f() el$0se { continue };
262
+ }" ,
263
+ r"
264
+ enum Option<T> {
265
+ Some(T),
266
+ None,
267
+ }
268
+ use Option::*;
269
+ fn main() {
270
+ match f() {
271
+ None => {}
272
+ _ => continue,
273
+ }
274
+ }" ,
275
+ ) ;
276
+ }
277
+
278
+ #[ test]
279
+ fn convert_let_else_to_match_const_ref_const ( ) {
280
+ check_assist (
281
+ convert_let_else_to_match,
282
+ r"
283
+ const NEG1: i32 = -1;
284
+ fn main() {
285
+ let NEG1 = f() el$0se { continue };
286
+ }" ,
287
+ r"
288
+ const NEG1: i32 = -1;
289
+ fn main() {
290
+ match f() {
291
+ NEG1 => {}
292
+ _ => continue,
293
+ }
294
+ }" ,
295
+ ) ;
296
+ }
297
+
247
298
#[ test]
248
299
fn convert_let_else_to_match_mut ( ) {
249
300
check_assist (
You can’t perform that action at this time.
0 commit comments