Auto merge of #18038 - roife:fix-issue-18034, r=Veykril

feat: generate names for tuple-struct in add-missing-match-arms

fix #18034.

This PR includes the following enhancement:

- Introduced a `NameGenerator` in `suggest_name`, which implements an automatic renaming algorithm to avoid name conflicts. Here are a few examples:

```rust
let mut generator = NameGenerator::new();
assert_eq!(generator.suggest_name("a"), "a");
assert_eq!(generator.suggest_name("a"), "a1");
assert_eq!(generator.suggest_name("a"), "a2");

assert_eq!(generator.suggest_name("b"), "b");
assert_eq!(generator.suggest_name("b"), "b1");
assert_eq!(generator.suggest_name("b2"), "b2");
assert_eq!(generator.suggest_name("b"), "b3");
assert_eq!(generator.suggest_name("b"), "b4");
assert_eq!(generator.suggest_name("b3"), "b5");
```

- Updated existing testcases in ide-assists for the new `NameGenerator` (only modified generated names).
- Generate names for tuple structs instead of using wildcard patterns in `add-missing-match-arms`.
This commit is contained in:
bors 2024-09-12 08:21:37 +00:00
commit a91ca0e2fc
6 changed files with 295 additions and 102 deletions

View file

@ -66,7 +66,7 @@ pub use rowan::{
TokenAtOffset, WalkEvent,
};
pub use rustc_lexer::unescape;
pub use smol_str::{format_smolstr, SmolStr, ToSmolStr};
pub use smol_str::{format_smolstr, SmolStr, SmolStrBuilder, ToSmolStr};
/// `Parse` is the result of the parsing: a syntax tree and a collection of
/// errors.