Skip to content

Commit e945164

Browse files
committed
Always warn when implicitly copying a generic type
1 parent 38e86d7 commit e945164

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/comp/middle/alias.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -399,16 +399,15 @@ fn test_scope(cx: ctx, sc: scope, r: restrict, p: ast::path) {
399399
_ {}
400400
}
401401
if prob != valid && cant_copy(cx, r) {
402-
let msg =
403-
alt prob {
404-
overwritten(sp, wpt) {
405-
{span: sp, msg: "overwriting " + ast_util::path_name(wpt)}
406-
}
407-
val_taken(sp, vpt) {
408-
{span: sp,
409-
msg: "taking the value of " + ast_util::path_name(vpt)}
410-
}
411-
};
402+
let msg = alt prob {
403+
overwritten(sp, wpt) {
404+
{span: sp, msg: "overwriting " + ast_util::path_name(wpt)}
405+
}
406+
val_taken(sp, vpt) {
407+
{span: sp,
408+
msg: "taking the value of " + ast_util::path_name(vpt)}
409+
}
410+
};
412411
cx.tcx.sess.span_err(msg.span,
413412
msg.msg + " will invalidate reference " +
414413
ast_util::path_name(p) +
@@ -515,7 +514,7 @@ fn copy_is_expensive(tcx: ty::ctxt, ty: ty::t) -> bool {
515514
ty::ty_constr(t, _) | ty::ty_res(_, t, _) { score_ty(tcx, t) }
516515
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _, _) |
517516
ty::ty_obj(_) { 4u }
518-
ty::ty_str. | ty::ty_vec(_) { 50u }
517+
ty::ty_str. | ty::ty_vec(_) | ty::ty_param(_, _) { 50u }
519518
ty::ty_uniq(t) { 1u + score_ty(tcx, t) }
520519
ty::ty_tag(_, ts) | ty::ty_tup(ts) {
521520
let sum = 0u;
@@ -527,7 +526,6 @@ fn copy_is_expensive(tcx: ty::ctxt, ty: ty::t) -> bool {
527526
for f in fs { sum += score_ty(tcx, f.mt.ty); }
528527
sum
529528
}
530-
ty::ty_param(_, _) { 5u }
531529
};
532530
}
533531
ret score_ty(tcx, ty) > 8u;

0 commit comments

Comments
 (0)