Skip to content

Commit 29ea4ee

Browse files
committed
Auto merge of #30374 - durka:issue-30371, r=alexcrichton
Fixes #30371.
2 parents 3391630 + e0a5260 commit 29ea4ee

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/librustc_front/lowering.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1502,8 +1502,9 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {
15021502
hir::MatchSource::ForLoopDesugar,
15031503
None);
15041504

1505-
// `{ let result = ...; result }`
1506-
let result_ident = lctx.str_to_ident("result");
1505+
// `{ let _result = ...; _result }`
1506+
// underscore prevents an unused_variables lint if the head diverges
1507+
let result_ident = lctx.str_to_ident("_result");
15071508
let let_stmt = stmt_let(lctx, e.span, false, result_ident, match_expr, None);
15081509
let result = expr_ident(lctx, e.span, result_ident, None);
15091510
let block = block_all(lctx, e.span, hir_vec![let_stmt], Some(result));

src/test/run-pass/issue-30371.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![deny(unused_variables)]
12+
13+
fn main() {
14+
for _ in match return () {
15+
() => Some(0),
16+
} {}
17+
}
18+

0 commit comments

Comments
 (0)