Only bug on self-not-mapped-to-def if no previous errors were present. Close #6642.

This commit is contained in:
Ben Blum 2013-08-21 18:57:07 -04:00
parent 598072afa4
commit 0081961c57
2 changed files with 28 additions and 3 deletions

View File

@ -4812,9 +4812,13 @@ impl Resolver {
DontAllowCapturingSelf) {
Some(dl_def(def)) => return Some(def),
_ => {
self.session.span_bug(span,
"self wasn't mapped to a \
def?!")
if self.session.has_errors() {
// May happen inside a nested fn item, cf #6642.
return None;
} else {
self.session.span_bug(span,
"self wasn't mapped to a def?!")
}
}
}
}

View File

@ -0,0 +1,21 @@
// Copyright 2013 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.
struct A;
impl A {
fn m(&self) {
fn x() {
self.m()
//~^ ERROR can't capture dynamic environment in a fn item
//~^^ ERROR `self` is not allowed in this context
}
}
}
fn main() {}