diff options
| author | bors <bors@rust-lang.org> | 2024-04-21 16:09:17 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-04-21 16:09:17 +0000 |
| commit | 7a3ad0308ad32315da69d7d3be122c3788f19093 (patch) | |
| tree | 190b8bbf8b9eb7086596b1df16e2de56e8463ea0 /compiler/rustc_pattern_analysis/src/errors.rs | |
| parent | 23f19a2fb6b736cd71ac7f88bd6caa837416e1ac (diff) | |
| parent | 846f8046b0ac332620e72d7227c01676356854d2 (diff) | |
| download | rust-7a3ad0308ad32315da69d7d3be122c3788f19093.tar.gz rust-7a3ad0308ad32315da69d7d3be122c3788f19093.zip | |
Auto merge of #17115 - leviska:json_is_not_rust_better_names, r=Veykril
Try to generate more meaningful names in json converter
I just found out about rust-analyzer json converter, but I think it would be more convenient, if names were more useful, like using the names of the keys.
Let's look at some realistic arbitrary json:
```json
{
"user": {
"address": {
"street": "Main St",
"house": 3
},
"email": "example@example.com"
}
}
```
I think, new generated code is much easier to read and to edit, than the old:
```rust
// Old
struct Struct1{ house: i64, street: String }
struct Struct2{ address: Struct1, email: String }
struct Struct3{ user: Struct2 }
// New
struct Address1{ house: i64, street: String }
struct User1{ address: Address1, email: String }
struct Root1{ user: User1 }
```
Ideally, if we drop the numbers, I can see it being usable just as is (may be rename root)
```rust
struct Address{ house: i64, street: String }
struct User{ address: Address, email: String }
struct Root{ user: User }
```
Sadly, we can't just drop them, because there can be multiple fields (recursive) with the same name, and we can't just easily retroactively add numbers if the name has 2 instances due to parsing being single pass.
We could ignore the `1` and add number only if it's > 1, but I will leave this open to discussion and right now made it the simpler way
In sum, even with numbers, I think this PR still helps in readability
Diffstat (limited to 'compiler/rustc_pattern_analysis/src/errors.rs')
0 files changed, 0 insertions, 0 deletions
