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