Skip to content

Commit 67a7b7a

Browse files
authored
Rollup merge of #71894 - mibac138:semicolon-not-always-helpful, r=estebank
Suggest removing semicolon in last expression only if it's type is known Fixes #67971 Is there a syntax for explicitly checking if a note doesn't exist in test output? Something like `//~ !NOTE ...` I believe r? @estebank deals with diagnostics.
2 parents a49d2b7 + ca72352 commit 67a7b7a

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

src/librustc_typeck/check/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -5387,7 +5387,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
53875387
_ => return None,
53885388
};
53895389
let last_expr_ty = self.node_ty(last_expr.hir_id);
5390-
if self.can_sub(self.param_env, last_expr_ty, expected_ty).is_err() {
5390+
if matches!(last_expr_ty.kind, ty::Error)
5391+
|| self.can_sub(self.param_env, last_expr_ty, expected_ty).is_err()
5392+
{
53915393
return None;
53925394
}
53935395
let original_span = original_sp(last_stmt.span, blk.span);

src/test/ui/issues/issue-43162.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ LL | fn foo() -> bool {
1717
| --- ^^^^ expected `bool`, found `()`
1818
| |
1919
| implicitly returns `()` as its body has no tail or `return` expression
20-
LL |
21-
LL | break true;
22-
| - help: consider removing this semicolon
2320

2421
error: aborting due to 3 previous errors
2522

src/test/ui/typeck/issue-67971.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
struct S {}
2+
3+
fn foo(ctx: &mut S) -> String { //~ ERROR mismatched types
4+
// Don't suggest to remove semicolon as it won't fix anything
5+
ctx.sleep = 0;
6+
//~^ ERROR no field `sleep` on type `&mut S`
7+
}
8+
9+
fn main() {}

src/test/ui/typeck/issue-67971.stderr

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0609]: no field `sleep` on type `&mut S`
2+
--> $DIR/issue-67971.rs:5:9
3+
|
4+
LL | ctx.sleep = 0;
5+
| ^^^^^ unknown field
6+
7+
error[E0308]: mismatched types
8+
--> $DIR/issue-67971.rs:3:24
9+
|
10+
LL | fn foo(ctx: &mut S) -> String {
11+
| --- ^^^^^^ expected struct `std::string::String`, found `()`
12+
| |
13+
| implicitly returns `()` as its body has no tail or `return` expression
14+
15+
error: aborting due to 2 previous errors
16+
17+
Some errors have detailed explanations: E0308, E0609.
18+
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)