-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Do not discern between statements with and without semicolon after lowering to HIR #61753
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4851,7 +4851,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
// Don't do all the complex logic below for `DeclItem`. | ||
match stmt.node { | ||
hir::StmtKind::Item(..) => return, | ||
hir::StmtKind::Local(..) | hir::StmtKind::Expr(..) | hir::StmtKind::Semi(..) => {} | ||
hir::StmtKind::Local(..) | hir::StmtKind::Expr(..) => {} | ||
} | ||
|
||
self.warn_if_unreachable(stmt.hir_id, stmt.span, "statement"); | ||
|
@@ -4869,10 +4869,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
// Ignore for now. | ||
hir::StmtKind::Item(_) => {} | ||
hir::StmtKind::Expr(ref expr) => { | ||
// Check with expected type of `()`. | ||
self.check_expr_has_type_or_error(&expr, self.tcx.mk_unit()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (T-Lang: N.B. this removes the expectation that { core::default::Default::default() }
1; may stop compiling (crater will find out). We could add inference defaulting to |
||
} | ||
hir::StmtKind::Semi(ref expr) => { | ||
self.check_expr(&expr); | ||
} | ||
} | ||
|
@@ -5289,7 +5285,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
// taking the `;` off is enough to fix the error. | ||
let last_stmt = blk.stmts.last()?; | ||
let last_expr = match last_stmt.node { | ||
hir::StmtKind::Semi(ref e) => e, | ||
hir::StmtKind::Expr(ref e) => e, | ||
_ => return None, | ||
}; | ||
let last_expr_ty = self.node_ty(last_expr.hir_id); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
// run-pass | ||
fn main() { | ||
// Check that the tail statement in the body unifies with something | ||
for _ in 0..3 { | ||
unsafe { std::mem::uninitialized() } | ||
unsafe { std::mem::uninitialized() } //~ ERROR type annotations needed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
// Check that the tail statement in the body can be unit | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
error[E0282]: type annotations needed | ||
--> $DIR/for-loop-has-unit-body.rs:4:18 | ||
| | ||
LL | unsafe { std::mem::uninitialized() } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for `T` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0282`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
// compile-pass | ||
|
||
fn main() { | ||
for x in 0..3 { | ||
x //~ ERROR mismatched types | ||
x | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.