Files
rust/tests/ui/pattern/struct-pattern-with-missing-fields-resolve-error.stderr
Jonathan Brouwer 07d9787382 Rollup merge of #161180 - GTimothy:detect_missing_binding_available-suggestion, r=mu001999
Detect missing binding available: add a MaybeIncorrect suggestion

When suggesting that a missing binding is available in a pattern but not used, if it is behind a `..` suggest a MaybeIncorrect fix replacing `..` with `{binding}, ..`

This suggestion could be a `tool_only_suggestion`, or a `span_suggestion_hidden`. Other types of suggestions seem a bit too verbose for this simple case.
The `tool_only_suggestion` (first commit) does not add any suggestion in stderr, the `span_suggestion_hidden` (second commit) shows a minimal help line.

This work was extracted from PR https://github.com/rust-lang/rust/pull/156239.
2026-08-25 18:00:07 +02:00

43 lines
1.4 KiB
Plaintext

error: expected `,`
--> $DIR/struct-pattern-with-missing-fields-resolve-error.rs:16:31
|
LL | if let Website { url, Some(title) } = website {
| ------- ^
| |
| while parsing the fields for this pattern
error[E0425]: cannot find value `title` in this scope
--> $DIR/struct-pattern-with-missing-fields-resolve-error.rs:22:30
|
LL | if let Website { url, .. } = website {
| ------------------- this pattern doesn't include `title`, which is available in `Website`
LL | println!("[{}]({})", title, url);
| ^^^^^ not found in this scope
|
help: include `title` in the pattern
|
LL | if let Website { url, title, .. } = website {
| ++++++
error[E0425]: cannot find value `a` in this scope
--> $DIR/struct-pattern-with-missing-fields-resolve-error.rs:28:20
|
LL | if let Foo::Bar { .. } = x {
| --------------- this pattern doesn't include `a`, which is available in `Bar`
LL | println!("{a}");
| ^ not found in this scope
|
help: include `a` in the pattern
|
LL | if let Foo::Bar { a, .. } = x {
| ++
help: a local variable with a similar name exists
|
LL - println!("{a}");
LL + println!("{x}");
|
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0425`.