Skip to content
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

Lower condition of if expression before it's "then" block #82308

Merged
merged 1 commit into from
Feb 23, 2021
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
3 changes: 2 additions & 1 deletion compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
) -> hir::ExprKind<'hir> {
macro_rules! make_if {
($opt:expr) => {{
let cond = self.lower_expr(cond);
let then_expr = self.lower_block_expr(then);
hir::ExprKind::If(self.lower_expr(cond), self.arena.alloc(then_expr), $opt)
hir::ExprKind::If(cond, self.arena.alloc(then_expr), $opt)
}};
}
if let Some(rslt) = else_opt {
Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/pattern/issue-82290.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![feature(let_chains)] //~ WARN the feature `let_chains` is incomplete

fn main() {
if true && let x = 1 { //~ ERROR `let` expressions are not supported here
let _ = x;
}
}
20 changes: 20 additions & 0 deletions src/test/ui/pattern/issue-82290.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error: `let` expressions are not supported here
--> $DIR/issue-82290.rs:4:16
|
LL | if true && let x = 1 {
| ^^^^^^^^^
|
= note: only supported directly in conditions of `if`- and `while`-expressions
= note: as well as when nested within `&&` and parenthesis in those conditions

warning: the feature `let_chains` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/issue-82290.rs:1:12
|
LL | #![feature(let_chains)]
| ^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information

error: aborting due to previous error; 1 warning emitted