Skip to content

Suggest removing semicolon at the end of non-unit function #21838

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

Closed
jody-frankowski opened this issue Feb 1, 2015 · 8 comments
Closed

Suggest removing semicolon at the end of non-unit function #21838

jody-frankowski opened this issue Feb 1, 2015 · 8 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jody-frankowski
Copy link

fn add(a: i32, b: i32) -> i64 {
    a + b;
}

With this code, rustc doesn't print a message such as:

help: consider removing this semicolon:
a + b;

It only prints

error: not all control paths return a value [E0269]

rustc 1.0.0-nightly (c5961ad06 2015-01-28 21:49:38 +0000)
binary: rustc
commit-hash: c5961ad06d45689b44ff305c15d6ec7ec65755a9
commit-date: 2015-01-28 21:49:38 +0000
host: x86_64-unknown-linux-gnu
release: 1.0.0-nightly
@nagisa
Copy link
Member

nagisa commented Feb 1, 2015

Removing the semicolon would cause a type error, therefore the compiler is correct not printing the help message.

EDIT: pointing out which branches don’t return a value might be useful though.

@jody-frankowski
Copy link
Author

It's two errors at once.
The help message is helpful for beginners, and is tightly related to the E0269 error. So I don't see why it shouldn't be printed when there is a E0269 error.

@kmcallister kmcallister added the A-diagnostics Area: Messages for errors, warnings, and lints label Feb 2, 2015
@kmcallister kmcallister changed the title Rustc doesn't print a help message when there is a mismatch return type Suggest removing semicolon at the end of non-unit function Feb 2, 2015
@frewsxcv
Copy link
Member

frewsxcv commented Feb 3, 2015

Another option: only suggest removing the semicolon if the expression before the semicolon matches the return type of the function.

@nagisa
Copy link
Member

nagisa commented Feb 3, 2015

@frewsxcv
Copy link
Member

frewsxcv commented Feb 3, 2015

Ah nevermind then

@nagisa
Copy link
Member

nagisa commented Sep 30, 2015

I got bit today by a more complex example:

src/lex.rs:151:5: 189:6 error: not all control paths return a value [E0269]
src/lex.rs:151     fn lex_number(&mut self) -> Option<LiteralToken<'source>> {
src/lex.rs:152         self.source.chars().next().and_then(|d| {
src/lex.rs:153             if let '0'...'9' = d {
src/lex.rs:154                 let number = self.source.char_indices()
src/lex.rs:155                     .filter(|x| // Filter out convenience underscores
src/lex.rs:156                         x.1 != '_'
               ...
src/lex.rs:151:5: 189:6 help: run `rustc --explain E0269` to see a detailed explanation
error: aborting due to previous error

which happened because I accidentally a semicolon after a pretty big and_then. The span is pretty confusing in a sense that it suggests the error is somewhere in the filter. It also did not suggest removing the semicolon, even though the types were correct.

@steveklabnik
Copy link
Member

Triage: no change, other than the new error format.

@steveklabnik steveklabnik added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum
Copy link
Member

Closing in favor of collective issue for this general problem: #41897.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants