Commit 42d082f
authored
Fix clippy warnings in generated server Rust code (#4425)
## Summary
Updates the Rust server codegen to generate more idiomatic code that
passes clippy lints without warnings.
## Existing Clippy Warnings
Currently `:codegen-server-test:test` results in the following:
```
error: redundant closure
--> rest_json/rust-server-codegen/src/output.rs:2533:21
|
2533 | || ::std::collections::HashMap::new(),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `::std::collections::HashMap::new`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
```
and:
```
error: redundant closure
--> json_rpc10/rust-server-codegen/src/input.rs:1005:17
|
1005 | |v| crate::constrained::MaybeConstrained::Constrained(v),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `crate::constrained::MaybeConstrained::Constrained`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
```
## Changes
- Use `unwrap_or_default` instead of `unwrap_or_else(Vec::new)` and
`unwrap_or_else(HashMap::new)`
- Generate closures only when transformation is actually needed (avoid
redundant closures)
## Fixes
This resolves clippy warnings in generated code:
- `clippy::redundant-closure` - Unnecessary closures that can be
replaced with function references
- Suboptimal use of `unwrap_or_else` with default constructors1 parent bfe50e2 commit 42d082f
2 files changed
Lines changed: 51 additions & 29 deletions
File tree
- codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators
Lines changed: 20 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
347 | 347 | | |
348 | 348 | | |
349 | 349 | | |
350 | | - | |
351 | | - | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
352 | 360 | | |
353 | 361 | | |
354 | | - | |
355 | | - | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
356 | 372 | | |
357 | 373 | | |
358 | 374 | | |
| |||
Lines changed: 31 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
| 87 | + | |
88 | 88 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | 89 | | |
96 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
97 | 95 | | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | 96 | | |
113 | | - | |
114 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
115 | 121 | | |
116 | 122 | | |
117 | 123 | | |
| |||
120 | 126 | | |
121 | 127 | | |
122 | 128 | | |
123 | | - | |
| 129 | + | |
124 | 130 | | |
125 | 131 | | |
126 | 132 | | |
| |||
0 commit comments