Skip to content

Commit 01a6c71

Browse files
committed
Make vecs/strs not implicitly copyable by default, but make it configurable. Closes #2450.
1 parent a405ff9 commit 01a6c71

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

src/rustc/middle/lint.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import std::map::{map,hashmap,int_hash,hash_from_strs};
88
import std::smallintmap::{map,smallintmap};
99
import io::writer_util;
1010
import syntax::print::pprust::expr_to_str;
11-
1211
export lint, ctypes, unused_imports;
1312
export level, ignore, warn, error;
14-
export lookup_lint, lint_dict, get_lint_dict, get_warning_settings_level;
13+
export lookup_lint, lint_dict, get_lint_dict;
14+
export get_warning_level, get_warning_settings_level;
1515
export check_crate, build_settings_crate, mk_warning_settings;
1616
export warning_settings;
1717

@@ -45,6 +45,7 @@ enum lint {
4545
old_vecs,
4646
unrecognized_warning,
4747
non_implicitly_copyable_typarams,
48+
vecs_not_implicitly_copyable,
4849
}
4950

5051
// This is pretty unfortunate. We really want some sort of "deriving Enum"
@@ -58,6 +59,7 @@ fn int_to_lint(i: int) -> lint {
5859
4 { old_vecs }
5960
5 { unrecognized_warning }
6061
6 { non_implicitly_copyable_typarams }
62+
7 { vecs_not_implicitly_copyable }
6163
}
6264
}
6365

@@ -110,6 +112,12 @@ fn get_lint_dict() -> lint_dict {
110112
("non_implicitly_copyable_typarams",
111113
@{lint: non_implicitly_copyable_typarams,
112114
desc: "passing non implicitly copyable types as copy type params",
115+
default: warn}),
116+
117+
("vecs_not_implicitly_copyable",
118+
@{lint: vecs_not_implicitly_copyable,
119+
desc: "make vecs and strs not implicitly copyable\
120+
('err' is ignored; only checked at top level",
113121
default: warn})
114122

115123
];

src/rustc/middle/ty.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import util::ppaux::region_to_str;
1515
import util::ppaux::vstore_to_str;
1616
import util::ppaux::{ty_to_str, tys_to_str, ty_constr_to_str};
1717
import syntax::print::pprust::*;
18-
18+
import middle::lint::{get_warning_level, vecs_not_implicitly_copyable,
19+
ignore};
1920
export ty_vid, region_vid, vid;
2021
export br_hashmap;
2122
export is_instantiable;
@@ -218,6 +219,7 @@ type ctxt =
218219
@{diag: syntax::diagnostic::span_handler,
219220
interner: hashmap<intern_key, t_box>,
220221
mut next_id: uint,
222+
vecs_implicitly_copyable: bool,
221223
cstore: metadata::cstore::cstore,
222224
sess: session::session,
223225
def_map: resolve::def_map,
@@ -497,9 +499,13 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
497499
hash_type_structure(k.struct) +
498500
option::map_default(k.o_def_id, 0u, ast_util::hash_def)
499501
}, {|&&a, &&b| a == b});
502+
let vecs_implicitly_copyable =
503+
get_warning_level(s.warning_settings.default_settings,
504+
vecs_not_implicitly_copyable) == ignore;
500505
@{diag: s.diagnostic(),
501506
interner: interner,
502507
mut next_id: 0u,
508+
vecs_implicitly_copyable: vecs_implicitly_copyable,
503509
cstore: s.cstore,
504510
sess: s,
505511
def_map: dm,
@@ -1459,8 +1465,12 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
14591465
// Scalar and unique types are sendable
14601466
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
14611467
ty_ptr(_) { kind_implicitly_sendable() | kind_const() }
1462-
// FIXME: this *shouldn't* be implicitly copyable (#2450)
1463-
ty_str { kind_implicitly_sendable() | kind_const() }
1468+
// Implicit copyability of strs is configurable
1469+
ty_str {
1470+
if cx.vecs_implicitly_copyable {
1471+
kind_implicitly_sendable() | kind_const()
1472+
} else { kind_sendable() | kind_const() }
1473+
}
14641474
ty_fn(f) { proto_kind(f.proto) }
14651475

14661476
// Those with refcounts raise noncopyable to copyable,
@@ -1485,8 +1495,13 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
14851495
ty_uniq(tm) {
14861496
remove_implicit(remove_const(type_kind(cx, tm.ty), tm))
14871497
}
1488-
// FIXME: Vectors *shouldn't* be implicitly copyable but are (#2450)
1489-
ty_vec(tm) { remove_const(mutable_type_kind(cx, tm), tm) }
1498+
// Implicit copyability of vecs is configurable
1499+
ty_vec(tm) {
1500+
let k = if cx.vecs_implicitly_copyable {
1501+
mutable_type_kind(cx, tm)
1502+
} else { remove_implicit(type_kind(cx, tm.ty)) };
1503+
remove_const(k, tm)
1504+
}
14901505

14911506
// Slice and refcounted evecs are copyable; uniques and interiors
14921507
// depend on the their contained type, but aren't implicitly copyable.

0 commit comments

Comments
 (0)