From cc323d8637c36a8762bebaedad98cc916f4fcc1f Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Thu, 21 Jun 2012 17:41:40 -0700 Subject: [PATCH] Make liveness print out a proper error message for moves out of a self field This was a call to span_bug() before. I'm not sure about the other cases, but the test case shows that the `vk_self` case can certainly arise with a bad program, so it should be a span_err() thing and not a span_bug() thing. Closes #2590 --- src/rustc/middle/liveness.rs | 9 ++++++++- src/test/compile-fail/issue-2590.rs | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/issue-2590.rs diff --git a/src/rustc/middle/liveness.rs b/src/rustc/middle/liveness.rs index cc8b0383e36..9ad4009c513 100644 --- a/src/rustc/middle/liveness.rs +++ b/src/rustc/middle/liveness.rs @@ -1669,7 +1669,14 @@ impl check_methods for @liveness { #fmt["illegal move from field `%s`", *name]); ret; } - vk_local(*) | vk_self | vk_implicit_ret { + vk_self { + self.tcx.sess.span_err( + move_span, + "illegal move from self (cannot move out of a field of \ + self)"); + ret; + } + vk_local(*) | vk_implicit_ret { self.tcx.sess.span_bug( move_span, #fmt["illegal reader (%?) for `%?`", diff --git a/src/test/compile-fail/issue-2590.rs b/src/test/compile-fail/issue-2590.rs new file mode 100644 index 00000000000..c27fee9f8a8 --- /dev/null +++ b/src/test/compile-fail/issue-2590.rs @@ -0,0 +1,13 @@ +import dvec::dvec; + +type parser = { + tokens: dvec, +}; + +impl parser for parser { + fn parse() -> [mut int] { + dvec::unwrap(self.tokens) //! ERROR illegal move from self + } +} + +fn main() {}