Treat bare vector and string literals as fixed length vecs. Closes #2922.
This commit is contained in:
parent
7b2f4755f3
commit
6822ec3eb4
16 changed files with 26 additions and 100 deletions
|
@ -38,14 +38,13 @@ fn check_item(sess: session, ast_map: ast_map::map, def_map: resolve::def_map,
|
|||
fn check_pat(p: @pat, &&_is_const: bool, v: visit::vt<bool>) {
|
||||
fn is_str(e: @expr) -> bool {
|
||||
alt e.node {
|
||||
expr_lit(@{node: lit_str(_), _}) |
|
||||
expr_vstore(@{node: expr_lit(@{node: lit_str(_), _}), _},
|
||||
vstore_uniq) { true }
|
||||
_ { false }
|
||||
}
|
||||
}
|
||||
alt p.node {
|
||||
// Let through plain string literals here
|
||||
// Let through plain ~-string literals here
|
||||
pat_lit(a) { if !is_str(a) { v.visit_expr(a, true, v); } }
|
||||
pat_range(a, b) {
|
||||
if !is_str(a) { v.visit_expr(a, true, v); }
|
||||
|
|
|
@ -43,12 +43,10 @@ enum lint {
|
|||
unused_imports,
|
||||
while_true,
|
||||
path_statement,
|
||||
old_vecs,
|
||||
implicit_copies,
|
||||
unrecognized_warning,
|
||||
non_implicitly_copyable_typarams,
|
||||
vecs_not_implicitly_copyable,
|
||||
implicit_copies,
|
||||
old_strs,
|
||||
}
|
||||
|
||||
// This is pretty unfortunate. We really want some sort of "deriving Enum"
|
||||
|
@ -59,12 +57,10 @@ fn int_to_lint(i: int) -> lint {
|
|||
1 { unused_imports }
|
||||
2 { while_true }
|
||||
3 { path_statement }
|
||||
4 { old_vecs }
|
||||
4 { implicit_copies }
|
||||
5 { unrecognized_warning }
|
||||
6 { non_implicitly_copyable_typarams }
|
||||
7 { vecs_not_implicitly_copyable }
|
||||
8 { implicit_copies }
|
||||
9 { old_strs }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,16 +100,6 @@ fn get_lint_dict() -> lint_dict {
|
|||
desc: ~"path statements with no effect",
|
||||
default: warn}),
|
||||
|
||||
(~"old_vecs",
|
||||
@{lint: old_vecs,
|
||||
desc: ~"old (deprecated) vectors",
|
||||
default: error}),
|
||||
|
||||
(~"old_strs",
|
||||
@{lint: old_strs,
|
||||
desc: ~"old (deprecated) strings",
|
||||
default: error}),
|
||||
|
||||
(~"unrecognized_warning",
|
||||
@{lint: unrecognized_warning,
|
||||
desc: ~"unrecognized warning attribute",
|
||||
|
@ -321,7 +307,6 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
|
|||
check_item_ctypes(cx, i);
|
||||
check_item_while_true(cx, i);
|
||||
check_item_path_statement(cx, i);
|
||||
check_item_old_vecs(cx, i);
|
||||
}
|
||||
|
||||
// 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) {
|
|||
visit::visit_item(it, (), visit);
|
||||
}
|
||||
|
||||
fn check_item_old_vecs(cx: ty::ctxt, it: @ast::item) {
|
||||
let uses_vstore = int_hash();
|
||||
|
||||
let visit = item_stopping_visitor(visit::mk_simple_visitor(@{
|
||||
|
||||
visit_expr:fn@(e: @ast::expr) {
|
||||
alt e.node {
|
||||
ast::expr_vec(_, _)
|
||||
if ! uses_vstore.contains_key(e.id) {
|
||||
cx.sess.span_lint(
|
||||
old_vecs, e.id, it.id,
|
||||
e.span, ~"deprecated vec expr");
|
||||
}
|
||||
ast::expr_lit(@{node: ast::lit_str(_), span:_})
|
||||
if ! uses_vstore.contains_key(e.id) {
|
||||
cx.sess.span_lint(
|
||||
old_strs, e.id, it.id,
|
||||
e.span, ~"deprecated str expr");
|
||||
}
|
||||
|
||||
ast::expr_vstore(@inner, _) {
|
||||
uses_vstore.insert(inner.id, true);
|
||||
}
|
||||
_ { }
|
||||
}
|
||||
},
|
||||
|
||||
visit_ty: fn@(t: @ast::ty) {
|
||||
alt t.node {
|
||||
ast::ty_vec(_)
|
||||
if ! uses_vstore.contains_key(t.id) {
|
||||
cx.sess.span_lint(
|
||||
old_vecs, t.id, it.id,
|
||||
t.span, ~"deprecated vec type");
|
||||
}
|
||||
ast::ty_path(@{span: _, global: _, idents: ids,
|
||||
rp: none, types: _}, _)
|
||||
if ids == ~[@~"str"] && (! uses_vstore.contains_key(t.id)) {
|
||||
cx.sess.span_lint(
|
||||
old_strs, t.id, it.id,
|
||||
t.span, ~"deprecated str type");
|
||||
}
|
||||
ast::ty_fixed_length(inner, _) |
|
||||
ast::ty_box({ty: inner, _}) |
|
||||
ast::ty_uniq({ty: inner, _}) |
|
||||
ast::ty_rptr(_, {ty: inner, _}) {
|
||||
uses_vstore.insert(inner.id, true);
|
||||
}
|
||||
_ { }
|
||||
}
|
||||
}
|
||||
|
||||
with *visit::default_simple_visitor()
|
||||
}));
|
||||
visit::visit_item(it, (), visit);
|
||||
}
|
||||
|
||||
fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
|
||||
|
||||
let v = visit::mk_simple_visitor(@{
|
||||
|
|
|
@ -47,7 +47,6 @@ fn trans_opt(bcx: block, o: opt) -> opt_result {
|
|||
alt o {
|
||||
lit(l) {
|
||||
alt l.node {
|
||||
ast::expr_lit(@{node: ast::lit_str(s), _}) |
|
||||
ast::expr_vstore(@{node: ast::expr_lit(
|
||||
@{node: ast::lit_str(s), _}), _},
|
||||
ast::vstore_uniq) {
|
||||
|
|
|
@ -1447,7 +1447,8 @@ fn trans_lit(cx: block, e: @ast::expr, lit: ast::lit, dest: dest) -> block {
|
|||
let _icx = cx.insn_ctxt(~"trans_lit");
|
||||
if dest == ignore { ret cx; }
|
||||
alt lit.node {
|
||||
ast::lit_str(s) { tvec::trans_estr(cx, s, ast::vstore_uniq, dest) }
|
||||
ast::lit_str(s) { tvec::trans_estr(cx, s,
|
||||
ast::vstore_fixed(none), dest) }
|
||||
_ {
|
||||
store_in_dest(cx, trans_crate_lit(cx.ccx(), e, lit), dest)
|
||||
}
|
||||
|
@ -3542,7 +3543,8 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block {
|
|||
ast::expr_vstore(e, v) { ret tvec::trans_vstore(bcx, e, v, dest); }
|
||||
ast::expr_lit(lit) { ret trans_lit(bcx, e, *lit, dest); }
|
||||
ast::expr_vec(args, _) {
|
||||
ret tvec::trans_evec(bcx, args, ast::vstore_uniq, e.id, dest);
|
||||
ret tvec::trans_evec(bcx, args, ast::vstore_fixed(none),
|
||||
e.id, dest);
|
||||
}
|
||||
ast::expr_binary(op, lhs, rhs) {
|
||||
ret trans_binary(bcx, op, lhs, rhs, dest, e);
|
||||
|
|
|
@ -611,7 +611,7 @@ fn check_lit(fcx: @fn_ctxt, lit: @ast::lit) -> ty::t {
|
|||
let tcx = fcx.ccx.tcx;
|
||||
|
||||
alt lit.node {
|
||||
ast::lit_str(_) { ty::mk_estr(tcx, ty::vstore_uniq) }
|
||||
ast::lit_str(s) { ty::mk_estr(tcx, ty::vstore_fixed(s.len())) }
|
||||
ast::lit_int(_, t) { ty::mk_mach_int(tcx, t) }
|
||||
ast::lit_uint(_, t) { ty::mk_mach_uint(tcx, t) }
|
||||
ast::lit_int_unsuffixed(_) {
|
||||
|
@ -1524,7 +1524,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
|
|||
let t: ty::t = fcx.infcx.next_ty_var();
|
||||
for args.each |e| { bot |= check_expr_with(fcx, e, t); }
|
||||
let typ = ty::mk_evec(tcx, {ty: t, mutbl: mutbl},
|
||||
ty::vstore_uniq);
|
||||
ty::vstore_fixed(args.len()));
|
||||
fcx.write_ty(id, typ);
|
||||
}
|
||||
ast::expr_tup(elts) {
|
||||
|
|
|
@ -9,11 +9,11 @@ fn main() {
|
|||
};
|
||||
|
||||
alt "wow" {
|
||||
"wow" to "woow" { }
|
||||
"bar" to "foo" { }
|
||||
};
|
||||
|
||||
alt 5u {
|
||||
'c' to 100u { }
|
||||
_ { }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
// error-pattern:^ cannot be applied to type `~str`
|
||||
|
||||
fn main() { let x = "a" ^ "b"; }
|
||||
fn main() { let x = ~"a" ^ ~"b"; }
|
||||
|
|
|
@ -7,7 +7,7 @@ enum t = @t; //~ ERROR this type cannot be instantiated
|
|||
// the compiler to attempt autoderef and then
|
||||
// try to resolve the method.
|
||||
impl methods for t {
|
||||
fn to_str() -> ~str { "t" }
|
||||
fn to_str() -> ~str { ~"t" }
|
||||
}
|
||||
|
||||
fn new_t(x: t) {
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
// error-pattern:cannot apply unary operator `-` to type `~str`
|
||||
|
||||
fn main() { -"foo"; }
|
||||
fn main() { -~"foo"; }
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
fn foo(f: fn()) { f() }
|
||||
|
||||
fn main() {
|
||||
"" || 42; //~ ERROR binary operation || cannot be applied to type `~str`
|
||||
~"" || 42; //~ ERROR binary operation || cannot be applied to type `~str`
|
||||
foo || {}; //~ ERROR binary operation || cannot be applied to type `extern fn(fn())`
|
||||
//~^ NOTE did you forget the 'do' keyword for the call?
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ fn main() {
|
|||
let v: ~[mut ~[int]] = ~[mut ~[0]];
|
||||
|
||||
fn f(&&v: ~[mut ~[const int]]) {
|
||||
v[0] = [mut 3]
|
||||
v[0] = ~[mut 3]
|
||||
}
|
||||
|
||||
f(v); //~ ERROR (values differ in mutability)
|
||||
|
|
|
@ -5,7 +5,7 @@ fn main() {
|
|||
let v: ~[mut ~[mut int]] = ~[mut ~[mut 0]];
|
||||
|
||||
fn f(&&v: ~[mut ~[const int]]) {
|
||||
v[0] = [3]
|
||||
v[0] = ~[3]
|
||||
}
|
||||
|
||||
f(v); //~ ERROR (values differ in mutability)
|
||||
|
|
|
@ -8,18 +8,18 @@ fn main() {
|
|||
let x = ~[mut ~[mut 0]];
|
||||
|
||||
fn f(&&v: ~[mut ~[int]]) {
|
||||
v[0] = [3]
|
||||
v[0] = ~[3]
|
||||
}
|
||||
|
||||
fn g(&&v: ~[const ~[const int]]) {
|
||||
}
|
||||
|
||||
fn h(&&v: ~[mut ~[mut int]]) {
|
||||
v[0] = [mut 3]
|
||||
v[0] = ~[mut 3]
|
||||
}
|
||||
|
||||
fn i(&&v: ~[mut ~[const int]]) {
|
||||
v[0] = [mut 3]
|
||||
v[0] = ~[mut 3]
|
||||
}
|
||||
|
||||
fn j(&&v: ~[~[const int]]) {
|
||||
|
|
|
@ -6,8 +6,8 @@ enum u { c, d }
|
|||
fn main() {
|
||||
let x = a(c);
|
||||
alt x {
|
||||
a(d) { fail "hello"; }
|
||||
b { fail "goodbye"; }
|
||||
a(d) { fail ~"hello"; }
|
||||
b { fail ~"goodbye"; }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ class foo {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let cat = "kitty";
|
||||
let cat = ~"kitty";
|
||||
let po = comm::port(); //~ ERROR missing `send`
|
||||
let ch = comm::chan(po); //~ ERROR missing `send`
|
||||
comm::send(ch, foo(42, @cat)); //~ ERROR missing `send`
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// xfail-test
|
||||
// I can't for the life of me manage to untangle all of the brackets
|
||||
// in this test. I am just suppessing the old_vec diagnostic. This
|
||||
// doesn't actually care what sort of vector it uses, so if we change
|
||||
// what vectors mean, it shouldn't mind...
|
||||
#[warn(no_old_vecs)];
|
||||
// in this test, so I am xfailing it...
|
||||
|
||||
fn main() {
|
||||
#macro[[#zip_or_unzip[[x, ...], [y, ...]], [[x, y], ...]],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue