Skip to content

Commit 269f399

Browse files
authored
Rollup merge of #82308 - estebank:issue-82290, r=lcnr
Lower condition of `if` expression before it's "then" block Fix #82290, fix #82250.
2 parents 8e67fe5 + f0637e4 commit 269f399

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
347347
) -> hir::ExprKind<'hir> {
348348
macro_rules! make_if {
349349
($opt:expr) => {{
350+
let cond = self.lower_expr(cond);
350351
let then_expr = self.lower_block_expr(then);
351-
hir::ExprKind::If(self.lower_expr(cond), self.arena.alloc(then_expr), $opt)
352+
hir::ExprKind::If(cond, self.arena.alloc(then_expr), $opt)
352353
}};
353354
}
354355
if let Some(rslt) = else_opt {

src/test/ui/pattern/issue-82290.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![feature(let_chains)] //~ WARN the feature `let_chains` is incomplete
2+
3+
fn main() {
4+
if true && let x = 1 { //~ ERROR `let` expressions are not supported here
5+
let _ = x;
6+
}
7+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: `let` expressions are not supported here
2+
--> $DIR/issue-82290.rs:4:16
3+
|
4+
LL | if true && let x = 1 {
5+
| ^^^^^^^^^
6+
|
7+
= note: only supported directly in conditions of `if`- and `while`-expressions
8+
= note: as well as when nested within `&&` and parenthesis in those conditions
9+
10+
warning: the feature `let_chains` is incomplete and may not be safe to use and/or cause compiler crashes
11+
--> $DIR/issue-82290.rs:1:12
12+
|
13+
LL | #![feature(let_chains)]
14+
| ^^^^^^^^^^
15+
|
16+
= note: `#[warn(incomplete_features)]` on by default
17+
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
18+
19+
error: aborting due to previous error; 1 warning emitted
20+

0 commit comments

Comments
 (0)