Skip to content

Commit 0081961

Browse files
committed
Only bug on self-not-mapped-to-def if no previous errors were present. Close rust-lang#6642.
1 parent 598072a commit 0081961

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/librustc/middle/resolve.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4812,9 +4812,13 @@ impl Resolver {
48124812
DontAllowCapturingSelf) {
48134813
Some(dl_def(def)) => return Some(def),
48144814
_ => {
4815-
self.session.span_bug(span,
4816-
"self wasn't mapped to a \
4817-
def?!")
4815+
if self.session.has_errors() {
4816+
// May happen inside a nested fn item, cf #6642.
4817+
return None;
4818+
} else {
4819+
self.session.span_bug(span,
4820+
"self wasn't mapped to a def?!")
4821+
}
48184822
}
48194823
}
48204824
}

src/test/compile-fail/issue-6642.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2013 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+
struct A;
12+
impl A {
13+
fn m(&self) {
14+
fn x() {
15+
self.m()
16+
//~^ ERROR can't capture dynamic environment in a fn item
17+
//~^^ ERROR `self` is not allowed in this context
18+
}
19+
}
20+
}
21+
fn main() {}

0 commit comments

Comments
 (0)