Do not resolve labels across function boundary

This commit is contained in:
Seo Sanghyeon 2014-12-26 20:08:00 +09:00
parent 5ba6102657
commit 9449161aea
2 changed files with 46 additions and 2 deletions

View File

@ -3934,6 +3934,30 @@ impl<'a> Resolver<'a> {
None
}
fn search_label(&self, name: Name) -> Option<DefLike> {
for rib in self.label_ribs.iter().rev() {
match rib.kind {
NormalRibKind => {
// Continue
}
_ => {
// Do not resolve labels across function boundary
return None
}
}
let result = rib.bindings.get(&name).cloned();
match result {
Some(_) => {
return result
}
None => {
// Continue
}
}
}
None
}
fn resolve_crate(&mut self, krate: &ast::Crate) {
debug!("(resolving crate) starting");
@ -5752,8 +5776,7 @@ impl<'a> Resolver<'a> {
ExprBreak(Some(label)) | ExprAgain(Some(label)) => {
let renamed = mtwt::resolve(label);
match self.search_ribs(self.label_ribs[],
renamed, expr.span) {
match self.search_label(renamed) {
None => {
self.resolve_error(
expr.span,

View File

@ -0,0 +1,21 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn f() {
'l: loop {
fn g() {
loop {
break 'l; //~ ERROR use of undeclared label
}
}
}
}
fn main() {}