Skip to content

Commit 9449161

Browse files
committed
Do not resolve labels across function boundary
1 parent 5ba6102 commit 9449161

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

src/librustc_resolve/lib.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3934,6 +3934,30 @@ impl<'a> Resolver<'a> {
39343934
None
39353935
}
39363936

3937+
fn search_label(&self, name: Name) -> Option<DefLike> {
3938+
for rib in self.label_ribs.iter().rev() {
3939+
match rib.kind {
3940+
NormalRibKind => {
3941+
// Continue
3942+
}
3943+
_ => {
3944+
// Do not resolve labels across function boundary
3945+
return None
3946+
}
3947+
}
3948+
let result = rib.bindings.get(&name).cloned();
3949+
match result {
3950+
Some(_) => {
3951+
return result
3952+
}
3953+
None => {
3954+
// Continue
3955+
}
3956+
}
3957+
}
3958+
None
3959+
}
3960+
39373961
fn resolve_crate(&mut self, krate: &ast::Crate) {
39383962
debug!("(resolving crate) starting");
39393963

@@ -5752,8 +5776,7 @@ impl<'a> Resolver<'a> {
57525776

57535777
ExprBreak(Some(label)) | ExprAgain(Some(label)) => {
57545778
let renamed = mtwt::resolve(label);
5755-
match self.search_ribs(self.label_ribs[],
5756-
renamed, expr.span) {
5779+
match self.search_label(renamed) {
57575780
None => {
57585781
self.resolve_error(
57595782
expr.span,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 f() {
12+
'l: loop {
13+
fn g() {
14+
loop {
15+
break 'l; //~ ERROR use of undeclared label
16+
}
17+
}
18+
}
19+
}
20+
21+
fn main() {}

0 commit comments

Comments
 (0)