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
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Climb the HIR tree to see if the current `Expr` is part of a `break;` statement.
let Some(
hir::Node::Stmt(hir::Stmt { kind: hir::StmtKind::Semi(&ref p), .. })
| hir::Node::Block(hir::Block { expr: Some(&ref p), .. })
| hir::Node::Expr(&ref p),
) = self.tcx.hir().find(parent_id)
else {
Expand Down
7 changes: 6 additions & 1 deletion tests/ui/issues/issue-27042.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ LL | | while true { break }; // but here we cite the whole loop
error[E0308]: mismatched types
--> $DIR/issue-27042.rs:6:16
|
LL | let _: i32 =
| - expected because of this assignment
LL | 'a: // in this case, the citation is just the `break`:
LL | loop { break };
| ^^^^^ expected `i32`, found `()`
| ---- ^^^^^ expected `i32`, found `()`
| |
| this loop is expected to be of type `i32`
|
help: give it a value of the expected type
|
Expand Down
15 changes: 12 additions & 3 deletions tests/ui/loops/loop-labeled-break-value.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ error[E0308]: mismatched types
--> $DIR/loop-labeled-break-value.rs:3:29
|
LL | let _: i32 = loop { break };
| ^^^^^ expected `i32`, found `()`
| - ---- ^^^^^ expected `i32`, found `()`
| | |
| | this loop is expected to be of type `i32`
| expected because of this assignment
|
help: give it a value of the expected type
|
Expand All @@ -13,7 +16,10 @@ error[E0308]: mismatched types
--> $DIR/loop-labeled-break-value.rs:6:37
|
LL | let _: i32 = 'inner: loop { break 'inner };
| ^^^^^^^^^^^^ expected `i32`, found `()`
| - ---- ^^^^^^^^^^^^ expected `i32`, found `()`
| | |
| | this loop is expected to be of type `i32`
| expected because of this assignment
|
help: give it a value of the expected type
|
Expand All @@ -24,7 +30,10 @@ error[E0308]: mismatched types
--> $DIR/loop-labeled-break-value.rs:9:45
|
LL | let _: i32 = 'inner2: loop { loop { break 'inner2 } };
| ^^^^^^^^^^^^^ expected `i32`, found `()`
| - ---- ^^^^^^^^^^^^^ expected `i32`, found `()`
| | |
| | this loop is expected to be of type `i32`
| expected because of this assignment
|
help: give it a value of the expected type
|
Expand Down
5 changes: 4 additions & 1 deletion tests/ui/loops/loop-properly-diverging-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ error[E0308]: mismatched types
--> $DIR/loop-properly-diverging-2.rs:2:23
|
LL | let x: i32 = loop { break };
| ^^^^^ expected `i32`, found `()`
| - ---- ^^^^^ expected `i32`, found `()`
| | |
| | this loop is expected to be of type `i32`
| expected because of this assignment
|
help: give it a value of the expected type
|
Expand Down