Uh oh!
There was an error while loading. Please reload this page.
Detect missing ; on methods with return type () - #39231
Conversation
On a given file `foo.rs`:
```rust
fn foo() {
return 1;
}
fn bar() {
3
}
fn main() {
3
}
```
Provide the following output:
```bash
error[E0308]: mismatched types
--> foo.rs:2:12
|
2 | return 1;
| ^ expected (), found integral variable
|
= note: expected type `()`
= note: found type `{integer}`
error[E0308]: mismatched types
--> foo.rs:6:5
|
5 | fn bar() {
| - possibly return type `{integer}` missing here
6 | 3
| ^- consider adding a semicolon here
| |
| expected (), found integral variable
|
= note: expected type `()`
= note: found type `{integer}`
error[E0308]: mismatched types
--> foo.rs:10:5
|
10 | 3
| ^- consider adding a semicolon here
| |
| expected (), found integral variable
|
= note: expected type `()`
= note: found type `{integer}`
error: aborting due to 3 previous errors
```rust-highfive
commented
Jan 21, 2017
r? @nrc (rust_highfive has picked a reviewer for you, use r? to override) |
estebank
commented
Jan 21, 2017
nrc
commented
Jan 24, 2017
I agree with @brson and @nikomatsakis on the previous PR that adding a semicolon is likely to be incorrect more often than it is correct. OTOH, significant semicolons are a novel feature of Rust so perhaps this is more useful for newcomers than I might think. cc @rust-lang/compiler and @jonathandturner what do the rest of you think? And r? @eddyb because he reviewed this PR last time around. (I also don't think this fully addresses #25133, it seems to be a partial fix). |
dotdash
commented
Jan 24, 2017
I agree with the previous discussion, that without at least looking at the type of expression that causes the error, the hints can seem pretty nonsensical and rather confusing than helpful. At least when there is a literal of some kind, a plain variable or a constructor, I'd make more sense to me to only suggest to add a return type to the function. Also, why does |
nikomatsakis
commented
Jan 24, 2017
This definitely seems like an improvement, but I worry that we might overwhelm users a bit too. Something about "possibly return type In the case of Otherwise, perhaps something like "add a |
JordiPolo
commented
Jan 25, 2017
I'm new to the language and the optional |
bors
commented
Feb 17, 2017
☔ The latest upstream changes (presumably #39485) made this pull request unmergeable. Please resolve the merge conflicts. |
alexcrichton
commented
Apr 1, 2017
Closing due to inactivity, but feel free to resubmit with a rebase! |

On a given file
foo.rs:Provide the following output:
Fixes: #25133, #40891.
Previous discussion: #36409.