Skip to content

Commit 0cc26b2

Browse files
author
Nick Hamann
committed
Use correct type for "use of moved value" error with closures.
Fixes #24357
1 parent 21dd4e2 commit 0cc26b2

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
734734
has type `{}`, which is {}",
735735
ol,
736736
moved_lp_msg,
737-
expr_ty,
737+
moved_lp.ty,
738738
suggestion));
739739
self.tcx.sess.fileline_help(expr_span, help);
740740
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2015 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 NoCopy;
12+
fn main() {
13+
let x = NoCopy;
14+
let f = move || { let y = x; };
15+
//~^ NOTE `x` moved into closure environment here because it has type `NoCopy`
16+
let z = x;
17+
//~^ ERROR use of moved value: `x`
18+
}

0 commit comments

Comments
 (0)