diff --git a/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs b/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs index a0f126fb2cb..252b31e4d3c 100644 --- a/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs @@ -240,7 +240,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let tcx = self.infcx.tcx; let generics = tcx.generics_of(self.mir_def_id); let param = generics.type_param(¶m_ty, tcx); - if let Some(generics) = tcx.hir().get_generics(self.mir_def_id) { + if let Some(generics) = + tcx.hir().get_generics(tcx.closure_base_def_id(self.mir_def_id)) { suggest_constraining_type_param( generics, &mut err, diff --git a/src/test/ui/closures/issue-67123.rs b/src/test/ui/closures/issue-67123.rs new file mode 100644 index 00000000000..014c530e6d7 --- /dev/null +++ b/src/test/ui/closures/issue-67123.rs @@ -0,0 +1,5 @@ +fn foo(t: T) { + || { t; t; }; //~ ERROR: use of moved value +} + +fn main() {} diff --git a/src/test/ui/closures/issue-67123.stderr b/src/test/ui/closures/issue-67123.stderr new file mode 100644 index 00000000000..b2e875b8010 --- /dev/null +++ b/src/test/ui/closures/issue-67123.stderr @@ -0,0 +1,15 @@ +error[E0382]: use of moved value: `t` + --> $DIR/issue-67123.rs:2:13 + | +LL | fn foo(t: T) { + | - help: consider restricting this bound: `T: Copy` +LL | || { t; t; }; + | - ^ value used here after move + | | + | value moved here + | + = note: move occurs because `t` has type `T`, which does not implement the `Copy` trait + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0382`.