Skip to content

Commit 802d8c5

Browse files
committed
Point at type argument suggesting adding Copy constraint
1 parent 97bc38e commit 802d8c5

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/librustc_mir/borrow_check/error_reporting.rs

+11
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,17 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
217217
break;
218218
}
219219
}
220+
if let ty::TyKind::Param(param_ty) = ty.sty {
221+
let tcx = self.infcx.tcx;
222+
let generics = tcx.generics_of(self.mir_def_id);
223+
let def_id = generics.type_param(&param_ty, tcx).def_id;
224+
if let Some(sp) = tcx.hir().span_if_local(def_id) {
225+
err.span_label(
226+
sp,
227+
"consider adding a `Copy` constraint to this type argument",
228+
);
229+
}
230+
}
220231
if note {
221232
err.note(&format!(
222233
"move occurs because {} has type `{}`, \

src/test/ui/borrowck/two-phase-nonrecv-autoref.nll.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ LL | f(f(10));
1010
error[E0382]: use of moved value: `*f`
1111
--> $DIR/two-phase-nonrecv-autoref.rs:69:11
1212
|
13+
LL | fn twice_ten_so<F: FnOnce(i32) -> i32>(f: Box<F>) {
14+
| - consider adding a `Copy` constraint to this type argument
1315
LL | f(f(10));
1416
| - ^ value used here after move
1517
| |

src/test/ui/issues/issue-34721.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0382]: use of moved value: `x`
22
--> $DIR/issue-34721.rs:27:9
33
|
44
LL | pub fn baz<T: Foo>(x: T) -> T {
5-
| - move occurs because `x` has type `T`, which does not implement the `Copy` trait
5+
| - - move occurs because `x` has type `T`, which does not implement the `Copy` trait
6+
| |
7+
| consider adding a `Copy` constraint to this type argument
68
LL | if 0 == 1 {
79
LL | bar::bar(x.zero())
810
| - value moved here

0 commit comments

Comments
 (0)