unhelpful suggestion: consider using a semicolon here
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
Code
fn f() -> Result<u8, ()> {
match true {
true => {},
_ => {g()?},
}
g()
}
fn g() -> Result<u8, ()> {unimplemented!()}
Current output
error[E0308]: mismatched types
--> src/lib.rs:4:15
|
2 | / match true {
3 | | true => {},
4 | | _ => {g()?},
| | ^^^^ expected `()`, found `u8`
5 | | }
| |_____- expected this to be `()`
|
help: consider using a semicolon here
|
4 | _ => {g()?;},
| +
help: consider using a semicolon here
|
5 | };
| +
For more information about this error, try `rustc --explain E0308`.
Desired output
This suggestion should not be be displayed because the first suggestion is the correct one. This second suggestion does not fix the compile error and makes the next compile error worse.
help: consider using a semicolon here
|
5 | };
| +
Rationale and extra context
If the second suggestion is applied, the code still doesn't compile. Even worse, it no longer suggests the first (correct) fix if the second one has been applied. This is the output after adding the semicolon on line 5:
Other cases
error[E0308]: `match` arms have incompatible types
--> src/lib.rs:4:15
|
2 | / match true {
3 | | true => {},
| | -- this is found to be of type `()`
4 | | _ => {g()?},
| | ^^^^ expected `()`, found `u8`
5 | | };
| |_____- `match` arms have incompatible types
For more information about this error, try `rustc --explain E0308`.
Rust Version
rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the diagnostic using the Rust code in src/lib.rs and the reported rustc 1.76.0 version. Then trace the compiler logic that emits the E0308 semicolon suggestions and add or adjust coverage for this match-expression case. Done means the incorrect second suggestion is no longer displayed while the valid inner semicolon suggestion remains.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100