Skip to content

rustc: Reorder error and note message to reduce confusion. #15431

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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/doc/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -895,13 +895,14 @@ fn add_one(x: int) -> int {
We would get an error:

```{ignore,notrust}
note: consider removing this semicolon:
x + 1;
^
error: not all control paths return a value
fn add_one(x: int) -> int {
x + 1;
}

note: consider removing this semicolon:
x + 1;
^
```

Remember our earlier discussions about semicolons and `()`? Our function claims
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,8 @@ impl<'a> Liveness<'a> {
},
_ => false
};
self.ir.tcx.sess.span_err(
sp, "not all control paths return a value");
if ends_with_stmt {
let last_stmt = body.stmts.last().unwrap();
let original_span = original_sp(last_stmt.span, sp);
Expand All @@ -1469,8 +1471,6 @@ impl<'a> Liveness<'a> {
self.ir.tcx.sess.span_note(
span_semicolon, "consider removing this semicolon:");
}
self.ir.tcx.sess.span_err(
sp, "not all control paths return a value");
}
}
}
Expand Down