mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-10 14:02:57 +00:00
Do not resolve labels across function boundary
This commit is contained in:
parent
5ba6102657
commit
9449161aea
@ -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,
|
||||
|
21
src/test/compile-fail/resolve-label.rs
Normal file
21
src/test/compile-fail/resolve-label.rs
Normal 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() {}
|
Loading…
Reference in New Issue
Block a user