Skip to content

Commit ccf9050

Browse files
committed
Don't recurse down closures for duplicate-label checking
1 parent b5dad7d commit ccf9050

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/librustc/middle/resolve_lifetime.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,12 @@ fn extract_labels<'v, 'a>(ctxt: &mut LifetimeContext<'a>, b: &'v ast::Block) {
372372

373373
impl<'v, 'a> Visitor<'v> for GatherLabels<'a> {
374374
fn visit_expr(&mut self, ex: &'v ast::Expr) {
375+
// do not recurse into closures defined in the block
376+
// since they are treated as separate fns from the POV of
377+
// labels_in_fn
378+
if let ast::ExprClosure(..) = ex.node {
379+
return
380+
}
375381
if let Some(label) = expression_label(ex) {
376382
for &(prior, prior_span) in &self.labels_in_fn[..] {
377383
// FIXME (#24278): non-hygienic comparison

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2015 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 main() {
12+
|| {
13+
'label: loop {
14+
}
15+
};
16+
}

0 commit comments

Comments
 (0)