diff options
| author | yukang <moorekang@gmail.com> | 2022-10-27 14:43:15 +0800 |
|---|---|---|
| committer | yukang <moorekang@gmail.com> | 2022-11-08 14:10:04 +0800 |
| commit | 667b15bb0ebb36683a2de31cff68ad2b5b0d3f57 (patch) | |
| tree | 82d85b103a002b71b3d436135ce3df209f2ad482 /src/test/ui | |
| parent | 57d3c58ed6e0faf89a62411f96c000ffc9fd3937 (diff) | |
| download | rust-667b15bb0ebb36683a2de31cff68ad2b5b0d3f57.tar.gz rust-667b15bb0ebb36683a2de31cff68ad2b5b0d3f57.zip | |
fix #103587, Recover from common if let syntax mistakes/typos
Diffstat (limited to 'src/test/ui')
| -rw-r--r-- | src/test/ui/inference/issue-103587.rs | 12 | ||||
| -rw-r--r-- | src/test/ui/inference/issue-103587.stderr | 40 | ||||
| -rw-r--r-- | src/test/ui/suggestions/if-let-typo.stderr | 15 |
3 files changed, 67 insertions, 0 deletions
diff --git a/src/test/ui/inference/issue-103587.rs b/src/test/ui/inference/issue-103587.rs new file mode 100644 index 00000000000..11536f9f4cc --- /dev/null +++ b/src/test/ui/inference/issue-103587.rs @@ -0,0 +1,12 @@ +fn main() { + let x = Some(123); + + if let Some(_) == x {} + //~^ ERROR expected `=`, found `==` + + if Some(_) = x {} + //~^ ERROR mismatched types + + if None = x { } + //~^ ERROR mismatched types +} diff --git a/src/test/ui/inference/issue-103587.stderr b/src/test/ui/inference/issue-103587.stderr new file mode 100644 index 00000000000..b373fbfbb94 --- /dev/null +++ b/src/test/ui/inference/issue-103587.stderr @@ -0,0 +1,40 @@ +error: expected `=`, found `==` + --> $DIR/issue-103587.rs:4:20 + | +LL | if let Some(_) == x {} + | ^^ + | +help: consider using `=` here + | +LL | if let Some(_) = x {} + | ~ + +error[E0308]: mismatched types + --> $DIR/issue-103587.rs:7:8 + | +LL | if Some(_) = x {} + | ^^^^^^^^^^^ expected `bool`, found `()` + | +help: consider adding `let` + | +LL | if let Some(_) = x {} + | +++ + +error[E0308]: mismatched types + --> $DIR/issue-103587.rs:10:8 + | +LL | if None = x { } + | ^^^^^^^^ expected `bool`, found `()` + | +help: you might have meant to use pattern matching + | +LL | if let None = x { } + | +++ +help: you might have meant to compare for equality + | +LL | if None == x { } + | + + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/suggestions/if-let-typo.stderr b/src/test/ui/suggestions/if-let-typo.stderr index 3d9ac40ec36..02148b7f7ad 100644 --- a/src/test/ui/suggestions/if-let-typo.stderr +++ b/src/test/ui/suggestions/if-let-typo.stderr @@ -25,12 +25,22 @@ error[E0308]: mismatched types | LL | if Some(x) = foo {} | ^^^^^^^^^^^^^ expected `bool`, found `()` + | +help: consider adding `let` + | +LL | if let Some(x) = foo {} + | +++ error[E0308]: mismatched types --> $DIR/if-let-typo.rs:6:8 | LL | if Some(foo) = bar {} | ^^^^^^^^^^^^^^^ expected `bool`, found `()` + | +help: consider adding `let` + | +LL | if let Some(foo) = bar {} + | +++ error[E0308]: mismatched types --> $DIR/if-let-typo.rs:7:8 @@ -51,6 +61,11 @@ error[E0308]: mismatched types | LL | if Some(3) = foo {} | ^^^^^^^^^^^^^ expected `bool`, found `()` + | +help: consider adding `let` + | +LL | if let Some(3) = foo {} + | +++ error: aborting due to 7 previous errors |
