From 0cc26b205855118491c2825fd79ba30e09ac2755 Mon Sep 17 00:00:00 2001 From: Nick Hamann Date: Wed, 24 Jun 2015 19:25:04 -0500 Subject: [PATCH 1/2] Use correct type for "use of moved value" error with closures. Fixes #24357 --- src/librustc_borrowck/borrowck/mod.rs | 2 +- src/test/compile-fail/issue-24357.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/issue-24357.rs diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 6369621779c..ec92c2ed05a 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -734,7 +734,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { has type `{}`, which is {}", ol, moved_lp_msg, - expr_ty, + moved_lp.ty, suggestion)); self.tcx.sess.fileline_help(expr_span, help); } diff --git a/src/test/compile-fail/issue-24357.rs b/src/test/compile-fail/issue-24357.rs new file mode 100644 index 00000000000..f193a07b85a --- /dev/null +++ b/src/test/compile-fail/issue-24357.rs @@ -0,0 +1,18 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct NoCopy; +fn main() { + let x = NoCopy; + let f = move || { let y = x; }; + //~^ NOTE `x` moved into closure environment here because it has type `NoCopy` + let z = x; + //~^ ERROR use of moved value: `x` +} From db9af26d762e15b7f96194145d7b1c17328db021 Mon Sep 17 00:00:00 2001 From: Nick Hamann Date: Wed, 24 Jun 2015 19:29:53 -0500 Subject: [PATCH 2/2] Add a regression test for #18119. Closes #18119 --- src/test/compile-fail/issue-18119.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/test/compile-fail/issue-18119.rs diff --git a/src/test/compile-fail/issue-18119.rs b/src/test/compile-fail/issue-18119.rs new file mode 100644 index 00000000000..1270b094534 --- /dev/null +++ b/src/test/compile-fail/issue-18119.rs @@ -0,0 +1,22 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +const X: u8 = 1; +static Y: u8 = 1; +fn foo() {} + +impl X {} +//~^ ERROR use of undeclared type name `X` +impl Y {} +//~^ ERROR use of undeclared type name `Y` +impl foo {} +//~^ ERROR use of undeclared type name `foo` + +fn main() {}