about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBen Blum <bblum@andrew.cmu.edu>2013-08-21 18:57:07 -0400
committerBen Blum <bblum@andrew.cmu.edu>2013-08-21 19:22:57 -0400
commit0081961c57494162d9f2d19265175af95fbdd8d7 (patch)
treede4523bd023f9ba7c0fe96941a1bd3ab3e1a300b
parent598072afa46d3c4fca7659c49ef3c9dc9f85787e (diff)
Only bug on self-not-mapped-to-def if no previous errors were present. Close #6642.
-rw-r--r--src/librustc/middle/resolve.rs10
-rw-r--r--src/test/compile-fail/issue-6642.rs21
2 files changed, 28 insertions, 3 deletions
diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs
index 9654bf3fc01..4a21c0307f2 100644
--- a/src/librustc/middle/resolve.rs
+++ b/src/librustc/middle/resolve.rs
@@ -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?!")
+                            }
                         }
                     }
                 }
diff --git a/src/test/compile-fail/issue-6642.rs b/src/test/compile-fail/issue-6642.rs
new file mode 100644
index 00000000000..bffca995b8e
--- /dev/null
+++ b/src/test/compile-fail/issue-6642.rs
@@ -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() {}