-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 ```
r? @nrc (rust_highfive has picked a reviewer for you, use r? to override) |
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). |
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 |
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 |
I'm new to the language and the optional |
☔ The latest upstream changes (presumably #39485) made this pull request unmergeable. Please resolve the merge conflicts. |
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.