Commit 45609a9
committed
Auto merge of rust-lang#17571 - winstxnhdw:bool-to-enum-no-dupe, r=Veykril
feat: do not add new enum if it already exists
## Summary
This PR introduces a check for the existence of another enum within the current scope, and if it exist, we skip `add_enum_def`.
## Why?
Currently, when using the `bool_to_enum` assist more than once, it is possible to add multiple enum definitions. For example, the following snippet,
```rs
#[derive(PartialEq, Eq)]
enum Bool {
True,
False,
}
fn main() {
let a = Bool::True;
let b = true;
println!("Hello, world!");
}
```
will be transformed into,
```rs
#[derive(PartialEq, Eq)]
enum Bool {
True,
False,
}
#[derive(PartialEq, Eq)]
enum Bool {
True,
False,
}
fn main() {
let a = Bool::True;
let b = Bool::True;
println!("Hello, world!");
}
```
This can be annoying for users to clean up.File tree
1 file changed
+44
-3
lines changed- src/tools/rust-analyzer/crates/ide-assists/src/handlers
1 file changed
+44
-3
lines changedLines changed: 44 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| |||
461 | 461 | | |
462 | 462 | | |
463 | 463 | | |
464 | | - | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
465 | 478 | | |
466 | 479 | | |
467 | 480 | | |
| |||
472 | 485 | | |
473 | 486 | | |
474 | 487 | | |
475 | | - | |
476 | 488 | | |
477 | 489 | | |
478 | 490 | | |
479 | 491 | | |
480 | 492 | | |
481 | 493 | | |
482 | 494 | | |
| 495 | + | |
| 496 | + | |
483 | 497 | | |
484 | 498 | | |
485 | 499 | | |
| |||
553 | 567 | | |
554 | 568 | | |
555 | 569 | | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
556 | 597 | | |
557 | 598 | | |
558 | 599 | | |
| |||
0 commit comments