Skip to content

Commit 6822ec3

Browse files
committed
Treat bare vector and string literals as fixed length vecs. Closes #2922.
1 parent 7b2f475 commit 6822ec3

16 files changed

+26
-100
lines changed

src/rustc/middle/check_const.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ fn check_item(sess: session, ast_map: ast_map::map, def_map: resolve::def_map,
3838
fn check_pat(p: @pat, &&_is_const: bool, v: visit::vt<bool>) {
3939
fn is_str(e: @expr) -> bool {
4040
alt e.node {
41-
expr_lit(@{node: lit_str(_), _}) |
4241
expr_vstore(@{node: expr_lit(@{node: lit_str(_), _}), _},
4342
vstore_uniq) { true }
4443
_ { false }
4544
}
4645
}
4746
alt p.node {
48-
// Let through plain string literals here
47+
// Let through plain ~-string literals here
4948
pat_lit(a) { if !is_str(a) { v.visit_expr(a, true, v); } }
5049
pat_range(a, b) {
5150
if !is_str(a) { v.visit_expr(a, true, v); }

src/rustc/middle/lint.rs

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ enum lint {
4343
unused_imports,
4444
while_true,
4545
path_statement,
46-
old_vecs,
46+
implicit_copies,
4747
unrecognized_warning,
4848
non_implicitly_copyable_typarams,
4949
vecs_not_implicitly_copyable,
50-
implicit_copies,
51-
old_strs,
5250
}
5351

5452
// This is pretty unfortunate. We really want some sort of "deriving Enum"
@@ -59,12 +57,10 @@ fn int_to_lint(i: int) -> lint {
5957
1 { unused_imports }
6058
2 { while_true }
6159
3 { path_statement }
62-
4 { old_vecs }
60+
4 { implicit_copies }
6361
5 { unrecognized_warning }
6462
6 { non_implicitly_copyable_typarams }
6563
7 { vecs_not_implicitly_copyable }
66-
8 { implicit_copies }
67-
9 { old_strs }
6864
}
6965
}
7066

@@ -104,16 +100,6 @@ fn get_lint_dict() -> lint_dict {
104100
desc: ~"path statements with no effect",
105101
default: warn}),
106102

107-
(~"old_vecs",
108-
@{lint: old_vecs,
109-
desc: ~"old (deprecated) vectors",
110-
default: error}),
111-
112-
(~"old_strs",
113-
@{lint: old_strs,
114-
desc: ~"old (deprecated) strings",
115-
default: error}),
116-
117103
(~"unrecognized_warning",
118104
@{lint: unrecognized_warning,
119105
desc: ~"unrecognized warning attribute",
@@ -321,7 +307,6 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
321307
check_item_ctypes(cx, i);
322308
check_item_while_true(cx, i);
323309
check_item_path_statement(cx, i);
324-
check_item_old_vecs(cx, i);
325310
}
326311

327312
// Take a visitor, and modify it so that it will not proceed past subitems.
@@ -422,63 +407,6 @@ fn check_item_path_statement(cx: ty::ctxt, it: @ast::item) {
422407
visit::visit_item(it, (), visit);
423408
}
424409

425-
fn check_item_old_vecs(cx: ty::ctxt, it: @ast::item) {
426-
let uses_vstore = int_hash();
427-
428-
let visit = item_stopping_visitor(visit::mk_simple_visitor(@{
429-
430-
visit_expr:fn@(e: @ast::expr) {
431-
alt e.node {
432-
ast::expr_vec(_, _)
433-
if ! uses_vstore.contains_key(e.id) {
434-
cx.sess.span_lint(
435-
old_vecs, e.id, it.id,
436-
e.span, ~"deprecated vec expr");
437-
}
438-
ast::expr_lit(@{node: ast::lit_str(_), span:_})
439-
if ! uses_vstore.contains_key(e.id) {
440-
cx.sess.span_lint(
441-
old_strs, e.id, it.id,
442-
e.span, ~"deprecated str expr");
443-
}
444-
445-
ast::expr_vstore(@inner, _) {
446-
uses_vstore.insert(inner.id, true);
447-
}
448-
_ { }
449-
}
450-
},
451-
452-
visit_ty: fn@(t: @ast::ty) {
453-
alt t.node {
454-
ast::ty_vec(_)
455-
if ! uses_vstore.contains_key(t.id) {
456-
cx.sess.span_lint(
457-
old_vecs, t.id, it.id,
458-
t.span, ~"deprecated vec type");
459-
}
460-
ast::ty_path(@{span: _, global: _, idents: ids,
461-
rp: none, types: _}, _)
462-
if ids == ~[@~"str"] && (! uses_vstore.contains_key(t.id)) {
463-
cx.sess.span_lint(
464-
old_strs, t.id, it.id,
465-
t.span, ~"deprecated str type");
466-
}
467-
ast::ty_fixed_length(inner, _) |
468-
ast::ty_box({ty: inner, _}) |
469-
ast::ty_uniq({ty: inner, _}) |
470-
ast::ty_rptr(_, {ty: inner, _}) {
471-
uses_vstore.insert(inner.id, true);
472-
}
473-
_ { }
474-
}
475-
}
476-
477-
with *visit::default_simple_visitor()
478-
}));
479-
visit::visit_item(it, (), visit);
480-
}
481-
482410
fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
483411

484412
let v = visit::mk_simple_visitor(@{

src/rustc/middle/trans/alt.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ fn trans_opt(bcx: block, o: opt) -> opt_result {
4747
alt o {
4848
lit(l) {
4949
alt l.node {
50-
ast::expr_lit(@{node: ast::lit_str(s), _}) |
5150
ast::expr_vstore(@{node: ast::expr_lit(
5251
@{node: ast::lit_str(s), _}), _},
5352
ast::vstore_uniq) {

src/rustc/middle/trans/base.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,8 @@ fn trans_lit(cx: block, e: @ast::expr, lit: ast::lit, dest: dest) -> block {
14471447
let _icx = cx.insn_ctxt(~"trans_lit");
14481448
if dest == ignore { ret cx; }
14491449
alt lit.node {
1450-
ast::lit_str(s) { tvec::trans_estr(cx, s, ast::vstore_uniq, dest) }
1450+
ast::lit_str(s) { tvec::trans_estr(cx, s,
1451+
ast::vstore_fixed(none), dest) }
14511452
_ {
14521453
store_in_dest(cx, trans_crate_lit(cx.ccx(), e, lit), dest)
14531454
}
@@ -3542,7 +3543,8 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block {
35423543
ast::expr_vstore(e, v) { ret tvec::trans_vstore(bcx, e, v, dest); }
35433544
ast::expr_lit(lit) { ret trans_lit(bcx, e, *lit, dest); }
35443545
ast::expr_vec(args, _) {
3545-
ret tvec::trans_evec(bcx, args, ast::vstore_uniq, e.id, dest);
3546+
ret tvec::trans_evec(bcx, args, ast::vstore_fixed(none),
3547+
e.id, dest);
35463548
}
35473549
ast::expr_binary(op, lhs, rhs) {
35483550
ret trans_binary(bcx, op, lhs, rhs, dest, e);

src/rustc/middle/typeck/check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ fn check_lit(fcx: @fn_ctxt, lit: @ast::lit) -> ty::t {
611611
let tcx = fcx.ccx.tcx;
612612

613613
alt lit.node {
614-
ast::lit_str(_) { ty::mk_estr(tcx, ty::vstore_uniq) }
614+
ast::lit_str(s) { ty::mk_estr(tcx, ty::vstore_fixed(s.len())) }
615615
ast::lit_int(_, t) { ty::mk_mach_int(tcx, t) }
616616
ast::lit_uint(_, t) { ty::mk_mach_uint(tcx, t) }
617617
ast::lit_int_unsuffixed(_) {
@@ -1524,7 +1524,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
15241524
let t: ty::t = fcx.infcx.next_ty_var();
15251525
for args.each |e| { bot |= check_expr_with(fcx, e, t); }
15261526
let typ = ty::mk_evec(tcx, {ty: t, mutbl: mutbl},
1527-
ty::vstore_uniq);
1527+
ty::vstore_fixed(args.len()));
15281528
fcx.write_ty(id, typ);
15291529
}
15301530
ast::expr_tup(elts) {

src/test/compile-fail/alt-range-fail.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ fn main() {
99
};
1010

1111
alt "wow" {
12-
"wow" to "woow" { }
12+
"bar" to "foo" { }
1313
};
1414

1515
alt 5u {
1616
'c' to 100u { }
1717
_ { }
1818
};
19-
}
19+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// error-pattern:^ cannot be applied to type `~str`
22

3-
fn main() { let x = "a" ^ "b"; }
3+
fn main() { let x = ~"a" ^ ~"b"; }

src/test/compile-fail/issue-2063.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ enum t = @t; //~ ERROR this type cannot be instantiated
77
// the compiler to attempt autoderef and then
88
// try to resolve the method.
99
impl methods for t {
10-
fn to_str() -> ~str { "t" }
10+
fn to_str() -> ~str { ~"t" }
1111
}
1212

1313
fn new_t(x: t) {

src/test/compile-fail/minus-string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// error-pattern:cannot apply unary operator `-` to type `~str`
22

3-
fn main() { -"foo"; }
3+
fn main() { -~"foo"; }

src/test/compile-fail/missing-do.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
fn foo(f: fn()) { f() }
44

55
fn main() {
6-
"" || 42; //~ ERROR binary operation || cannot be applied to type `~str`
6+
~"" || 42; //~ ERROR binary operation || cannot be applied to type `~str`
77
foo || {}; //~ ERROR binary operation || cannot be applied to type `extern fn(fn())`
88
//~^ NOTE did you forget the 'do' keyword for the call?
99
}

src/test/compile-fail/mutable-huh-variance-vec1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn main() {
55
let v: ~[mut ~[int]] = ~[mut ~[0]];
66

77
fn f(&&v: ~[mut ~[const int]]) {
8-
v[0] = [mut 3]
8+
v[0] = ~[mut 3]
99
}
1010

1111
f(v); //~ ERROR (values differ in mutability)

src/test/compile-fail/mutable-huh-variance-vec2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn main() {
55
let v: ~[mut ~[mut int]] = ~[mut ~[mut 0]];
66

77
fn f(&&v: ~[mut ~[const int]]) {
8-
v[0] = [3]
8+
v[0] = ~[3]
99
}
1010

1111
f(v); //~ ERROR (values differ in mutability)

src/test/compile-fail/mutable-huh-variance-vec4.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ fn main() {
88
let x = ~[mut ~[mut 0]];
99

1010
fn f(&&v: ~[mut ~[int]]) {
11-
v[0] = [3]
11+
v[0] = ~[3]
1212
}
1313

1414
fn g(&&v: ~[const ~[const int]]) {
1515
}
1616

1717
fn h(&&v: ~[mut ~[mut int]]) {
18-
v[0] = [mut 3]
18+
v[0] = ~[mut 3]
1919
}
2020

2121
fn i(&&v: ~[mut ~[const int]]) {
22-
v[0] = [mut 3]
22+
v[0] = ~[mut 3]
2323
}
2424

2525
fn j(&&v: ~[~[const int]]) {

src/test/compile-fail/non-exhaustive-match-nested.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ enum u { c, d }
66
fn main() {
77
let x = a(c);
88
alt x {
9-
a(d) { fail "hello"; }
10-
b { fail "goodbye"; }
9+
a(d) { fail ~"hello"; }
10+
b { fail ~"goodbye"; }
1111
}
1212
}
1313

src/test/compile-fail/unsendable-class.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class foo {
88
}
99

1010
fn main() {
11-
let cat = "kitty";
11+
let cat = ~"kitty";
1212
let po = comm::port(); //~ ERROR missing `send`
1313
let ch = comm::chan(po); //~ ERROR missing `send`
1414
comm::send(ch, foo(42, @cat)); //~ ERROR missing `send`
15-
}
15+
}

src/test/run-pass/macro-by-example-2.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1+
// xfail-test
12
// I can't for the life of me manage to untangle all of the brackets
2-
// in this test. I am just suppessing the old_vec diagnostic. This
3-
// doesn't actually care what sort of vector it uses, so if we change
4-
// what vectors mean, it shouldn't mind...
5-
#[warn(no_old_vecs)];
3+
// in this test, so I am xfailing it...
64

75
fn main() {
86
#macro[[#zip_or_unzip[[x, ...], [y, ...]], [[x, y], ...]],

0 commit comments

Comments
 (0)