Skip to content

Check whether the next_node is else-less if in get_return_block #124917

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

Merged
merged 3 commits into from
May 20, 2024
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_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ impl<'hir> Map<'hir> {
Node::Block(Block { expr: None, .. }) => return None,
// The current node is not the tail expression of its parent.
Node::Block(Block { expr: Some(e), .. }) if hir_id != e.hir_id => return None,
Node::Block(Block { expr: Some(e), ..}) if matches!(e.kind, ExprKind::If(_, _, None)) => return None,
_ => {}
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/return/tail-expr-if-as-return.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
if true {
"" //~ ERROR mismatched types [E0308]
}
}
12 changes: 12 additions & 0 deletions tests/ui/return/tail-expr-if-as-return.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0308]: mismatched types
--> $DIR/tail-expr-if-as-return.rs:3:9
|
LL | / if true {
LL | | ""
| | ^^ expected `()`, found `&str`
LL | | }
| |_____- expected this to be `()`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
Loading