Skip to content

Commit 73d31e3

Browse files
committed
Auto merge of #40242 - cramertj:fix-while-let-ribs-scope, r=petrochenkov
Fix missing WhileLet pattern scope Fix #40235
2 parents 231db97 + 75a35ef commit 73d31e3

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/librustc_resolve/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2897,8 +2897,10 @@ impl<'a> Resolver<'a> {
28972897
ExprKind::WhileLet(ref pattern, ref subexpression, ref block, label) => {
28982898
self.with_resolved_label(label, expr.id, |this| {
28992899
this.visit_expr(subexpression);
2900+
this.ribs[ValueNS].push(Rib::new(NormalRibKind));
29002901
this.resolve_pattern(pattern, PatternSource::WhileLet, &mut FxHashMap());
29012902
this.visit_block(block);
2903+
this.ribs[ValueNS].pop();
29022904
});
29032905
}
29042906

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

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2014 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+
fn foo() {}
12+
13+
fn main() {
14+
while let Some(foo) = Some(1) { break }
15+
foo();
16+
}

0 commit comments

Comments
 (0)