Skip to content

Commit e862148

Browse files
committed
Make "no implicit copies" diagnostics controllable through lint settings. Closes #2503.
1 parent 6396e2c commit e862148

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

src/rustc/middle/kind.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import util::ppaux::{ty_to_str, tys_to_str};
99
import syntax::print::pprust::expr_to_str;
1010
import freevars::freevar_entry;
1111
import dvec::extensions;
12-
import lint::non_implicitly_copyable_typarams;
12+
import lint::{non_implicitly_copyable_typarams,implicit_copies};
1313

1414
// Kind analysis pass.
1515
//
@@ -83,42 +83,43 @@ fn check_crate(tcx: ty::ctxt,
8383
tcx.sess.abort_if_errors();
8484
}
8585

86-
type check_fn = fn@(ctx, option<@freevar_entry>, bool, ty::t, sp: span);
86+
type check_fn = fn@(ctx, node_id, option<@freevar_entry>,
87+
bool, ty::t, sp: span);
8788

8889
// Yields the appropriate function to check the kind of closed over
8990
// variables. `id` is the node_id for some expression that creates the
9091
// closure.
9192
fn with_appropriate_checker(cx: ctx, id: node_id, b: fn(check_fn)) {
92-
fn check_for_uniq(cx: ctx, fv: option<@freevar_entry>, is_move: bool,
93-
var_t: ty::t, sp: span) {
93+
fn check_for_uniq(cx: ctx, id: node_id, fv: option<@freevar_entry>,
94+
is_move: bool, var_t: ty::t, sp: span) {
9495
// all captured data must be sendable, regardless of whether it is
9596
// moved in or copied in
9697
check_send(cx, var_t, sp);
9798

9899
// copied in data must be copyable, but moved in data can be anything
99100
let is_implicit = fv.is_some();
100-
if !is_move { check_copy(cx, var_t, sp, is_implicit); }
101+
if !is_move { check_copy(cx, id, var_t, sp, is_implicit); }
101102

102103
// check that only immutable variables are implicitly copied in
103104
for fv.each { |fv|
104105
check_imm_free_var(cx, fv.def, fv.span);
105106
}
106107
}
107108

108-
fn check_for_box(cx: ctx, fv: option<@freevar_entry>, is_move: bool,
109-
var_t: ty::t, sp: span) {
109+
fn check_for_box(cx: ctx, id: node_id, fv: option<@freevar_entry>,
110+
is_move: bool, var_t: ty::t, sp: span) {
110111
// copied in data must be copyable, but moved in data can be anything
111112
let is_implicit = fv.is_some();
112-
if !is_move { check_copy(cx, var_t, sp, is_implicit); }
113+
if !is_move { check_copy(cx, id, var_t, sp, is_implicit); }
113114

114115
// check that only immutable variables are implicitly copied in
115116
for fv.each { |fv|
116117
check_imm_free_var(cx, fv.def, fv.span);
117118
}
118119
}
119120

120-
fn check_for_block(cx: ctx, fv: option<@freevar_entry>, _is_move: bool,
121-
_var_t: ty::t, sp: span) {
121+
fn check_for_block(cx: ctx, _id: node_id, fv: option<@freevar_entry>,
122+
_is_move: bool, _var_t: ty::t, sp: span) {
122123
// only restriction: no capture clauses (we would have to take
123124
// ownership of the moved/copied in data).
124125
if fv.is_none() {
@@ -128,8 +129,8 @@ fn with_appropriate_checker(cx: ctx, id: node_id, b: fn(check_fn)) {
128129
}
129130
}
130131

131-
fn check_for_bare(cx: ctx, _fv: option<@freevar_entry>, _is_move: bool,
132-
_var_t: ty::t, sp: span) {
132+
fn check_for_bare(cx: ctx, _id: node_id, _fv: option<@freevar_entry>,
133+
_is_move: bool,_var_t: ty::t, sp: span) {
133134
cx.tcx.sess.span_err(sp, "attempted dynamic environment capture");
134135
}
135136

@@ -165,7 +166,7 @@ fn check_fn(fk: visit::fn_kind, decl: fn_decl, body: blk, sp: span,
165166
let cap_def = cx.tcx.def_map.get(cap_item.id);
166167
let cap_def_id = ast_util::def_id_of_def(cap_def).node;
167168
let ty = ty::node_id_to_type(cx.tcx, cap_def_id);
168-
chk(cx, none, cap_item.is_move, ty, cap_item.span);
169+
chk(cx, fn_id, none, cap_item.is_move, ty, cap_item.span);
169170
cap_def_id
170171
};
171172

@@ -187,7 +188,7 @@ fn check_fn(fk: visit::fn_kind, decl: fn_decl, body: blk, sp: span,
187188
};
188189

189190
let ty = ty::node_id_to_type(cx.tcx, id);
190-
chk(cx, some(fv), is_move, ty, fv.span);
191+
chk(cx, fn_id, some(fv), is_move, ty, fv.span);
191192
}
192193
}
193194

@@ -377,7 +378,7 @@ fn check_copy_ex(cx: ctx, ex: @expr, implicit_copy: bool) {
377378
!cx.last_use_map.contains_key(ex.id) &&
378379
!is_nullary_variant(cx, ex) {
379380
let ty = ty::expr_ty(cx.tcx, ex);
380-
check_copy(cx, ty, ex.span, implicit_copy);
381+
check_copy(cx, ex.id, ty, ex.span, implicit_copy);
381382
}
382383
}
383384

@@ -410,12 +411,14 @@ fn check_imm_free_var(cx: ctx, def: def, sp: span) {
410411
}
411412
}
412413

413-
fn check_copy(cx: ctx, ty: ty::t, sp: span, implicit_copy: bool) {
414+
fn check_copy(cx: ctx, id: node_id, ty: ty::t, sp: span,
415+
implicit_copy: bool) {
414416
let k = ty::type_kind(cx.tcx, ty);
415417
if !ty::kind_can_be_copied(k) {
416418
cx.tcx.sess.span_err(sp, "copying a noncopyable value");
417419
} else if implicit_copy && !ty::kind_can_be_implicitly_copied(k) {
418-
cx.tcx.sess.span_warn(
420+
cx.tcx.sess.span_lint(
421+
implicit_copies, id, cx.current_item,
419422
sp,
420423
"implicitly copying a non-implicitly-copyable value");
421424
}

src/rustc/middle/lint.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ enum lint {
4646
unrecognized_warning,
4747
non_implicitly_copyable_typarams,
4848
vecs_not_implicitly_copyable,
49+
implicit_copies,
4950
}
5051

5152
// This is pretty unfortunate. We really want some sort of "deriving Enum"
@@ -60,6 +61,7 @@ fn int_to_lint(i: int) -> lint {
6061
5 { unrecognized_warning }
6162
6 { non_implicitly_copyable_typarams }
6263
7 { vecs_not_implicitly_copyable }
64+
8 { implicit_copies }
6365
}
6466
}
6567

@@ -118,6 +120,11 @@ fn get_lint_dict() -> lint_dict {
118120
@{lint: vecs_not_implicitly_copyable,
119121
desc: "make vecs and strs not implicitly copyable\
120122
('err' is ignored; only checked at top level",
123+
default: warn}),
124+
125+
("implicit_copies",
126+
@{lint: implicit_copies,
127+
desc: "implicit copies of non implicitly copyable data",
121128
default: warn})
122129

123130
];

0 commit comments

Comments
 (0)