diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-01-01 16:35:32 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-01 16:35:32 +1100 |
| commit | 65cb7c66d0277571f0412d29fd237ea038b8c389 (patch) | |
| tree | b462f6e4f9233e069af57c879972d613bb6d0c2e /tests | |
| parent | cf7d7f509679ef47e1ac1a2c99e696226c20235b (diff) | |
| parent | 2b2ea9e875dc9ae6c2d351078f1f43e533c9d780 (diff) | |
| download | rust-65cb7c66d0277571f0412d29fd237ea038b8c389.tar.gz rust-65cb7c66d0277571f0412d29fd237ea038b8c389.zip | |
Rollup merge of #134979 - estebank:default-lint-sugg, r=compiler-errors
Provide structured suggestion for `impl Default` of type where all fields have defaults
```
error: `Default` impl doesn't use the declared default field values
--> $DIR/manual-default-impl-could-be-derived.rs:28:1
|
LL | / impl Default for B {
LL | | fn default() -> Self {
LL | | B {
LL | | x: s(),
| | --- this field has a default value
LL | | y: 0,
| | - this field has a default value
... |
LL | | }
| |_^
|
help: to avoid divergence in behavior between `Struct { .. }` and `<Struct as Default>::default()`, derive the `Default`
|
LL ~ #[derive(Default)] struct B {
|
```
Note that above the structured suggestion also includes completely removing the manual `impl`, but the rendering doesn't.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/structs/manual-default-impl-could-be-derived.stderr | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/tests/ui/structs/manual-default-impl-could-be-derived.stderr b/tests/ui/structs/manual-default-impl-could-be-derived.stderr index e8f607fac7e..cf06d5418e1 100644 --- a/tests/ui/structs/manual-default-impl-could-be-derived.stderr +++ b/tests/ui/structs/manual-default-impl-could-be-derived.stderr @@ -31,7 +31,10 @@ LL | | y: 0, LL | | } | |_^ | - = help: to avoid divergence in behavior between `Struct { .. }` and `<Struct as Default>::default()`, derive the `Default` +help: to avoid divergence in behavior between `Struct { .. }` and `<Struct as Default>::default()`, derive the `Default` + | +LL ~ #[derive(Default)] struct B { + | error: `Default` impl doesn't use the declared default field values --> $DIR/manual-default-impl-could-be-derived.rs:43:1 |
