Skip to content
Merged
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
4 changes: 3 additions & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5387,7 +5387,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
_ => return None,
};
let last_expr_ty = self.node_ty(last_expr.hir_id);
if self.can_sub(self.param_env, last_expr_ty, expected_ty).is_err() {
if matches!(last_expr_ty.kind, ty::Error)
|| self.can_sub(self.param_env, last_expr_ty, expected_ty).is_err()
{
return None;
}
let original_span = original_sp(last_stmt.span, blk.span);
Expand Down
3 changes: 0 additions & 3 deletions src/test/ui/issues/issue-43162.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ LL | fn foo() -> bool {
| --- ^^^^ expected `bool`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
LL |
LL | break true;
| - help: consider removing this semicolon

error: aborting due to 3 previous errors

Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/typeck/issue-67971.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
struct S {}

fn foo(ctx: &mut S) -> String { //~ ERROR mismatched types
// Don't suggest to remove semicolon as it won't fix anything
ctx.sleep = 0;
//~^ ERROR no field `sleep` on type `&mut S`
}

fn main() {}
18 changes: 18 additions & 0 deletions src/test/ui/typeck/issue-67971.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0609]: no field `sleep` on type `&mut S`
--> $DIR/issue-67971.rs:5:9
|
LL | ctx.sleep = 0;
| ^^^^^ unknown field

error[E0308]: mismatched types
--> $DIR/issue-67971.rs:3:24
|
LL | fn foo(ctx: &mut S) -> String {
| --- ^^^^^^ expected struct `std::string::String`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0308, E0609.
For more information about an error, try `rustc --explain E0308`.