Skip to content

Commit 39a780d

Browse files
committed
Auto merge of #27093 - Manishearth:closure-label-shadow, r=pnkfelix
Fixes #25343 To be honest I'm not sure if this is the right fix (I haven't yet fully understood the code), but it seems to work. I'll look closer at the code when I have some time, in the meantime if this is the right fix it would be nice to get verification from someone who does understand the code 😄 r? @pnkfelix
2 parents ee2d3bc + ccf9050 commit 39a780d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/librustc/middle/resolve_lifetime.rs

+6
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

+16
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)