librustc: Implement "&mut [T]" as an expression. r=brson
This commit is contained in:
parent
87f3ea7705
commit
ab3b752906
src
librustc/middle
libsyntax
test/run-pass
@ -103,7 +103,8 @@ fn classify(e: @expr,
|
||||
ast::expr_vstore_slice => classify(e, def_map, tcx),
|
||||
ast::expr_vstore_uniq |
|
||||
ast::expr_vstore_box |
|
||||
ast::expr_vstore_mut_box => non_const
|
||||
ast::expr_vstore_mut_box |
|
||||
ast::expr_vstore_mut_slice => non_const
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -535,7 +535,8 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr,
|
||||
ast::expr_lit(@{node: ast::lit_str(s), _}) => {
|
||||
return tvec::trans_lit_str(bcx, expr, s, dest);
|
||||
}
|
||||
ast::expr_vstore(contents, ast::expr_vstore_slice) => {
|
||||
ast::expr_vstore(contents, ast::expr_vstore_slice) |
|
||||
ast::expr_vstore(contents, ast::expr_vstore_mut_slice) => {
|
||||
return tvec::trans_slice_vstore(bcx, expr, contents, dest);
|
||||
}
|
||||
ast::expr_vstore(contents, ast::expr_vstore_fixed(_)) => {
|
||||
|
@ -3126,6 +3126,7 @@ fn expr_kind(tcx: ctxt,
|
||||
ast::expr_repeat(*) |
|
||||
ast::expr_lit(@{node: lit_str(_), _}) |
|
||||
ast::expr_vstore(_, ast::expr_vstore_slice) |
|
||||
ast::expr_vstore(_, ast::expr_vstore_mut_slice) |
|
||||
ast::expr_vstore(_, ast::expr_vstore_fixed(_)) |
|
||||
ast::expr_vec(*) => {
|
||||
RvalueDpsExpr
|
||||
|
@ -1804,7 +1804,9 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
|
||||
let tt = ast_expr_vstore_to_vstore(fcx, ev, args.len(), vst);
|
||||
let mutability;
|
||||
match vst {
|
||||
ast::expr_vstore_mut_box => mutability = ast::m_mutbl,
|
||||
ast::expr_vstore_mut_box | ast::expr_vstore_mut_slice => {
|
||||
mutability = ast::m_mutbl
|
||||
}
|
||||
_ => mutability = mutbl
|
||||
}
|
||||
let t: ty::t = fcx.infcx().next_ty_var();
|
||||
@ -2823,7 +2825,7 @@ fn ast_expr_vstore_to_vstore(fcx: @fn_ctxt, e: @ast::expr, n: uint,
|
||||
}
|
||||
ast::expr_vstore_uniq => ty::vstore_uniq,
|
||||
ast::expr_vstore_box | ast::expr_vstore_mut_box => ty::vstore_box,
|
||||
ast::expr_vstore_slice => {
|
||||
ast::expr_vstore_slice | ast::expr_vstore_mut_slice => {
|
||||
let r = fcx.infcx().next_region_var(e.span, e.id);
|
||||
ty::vstore_slice(r)
|
||||
}
|
||||
|
@ -441,7 +441,8 @@ enum expr_vstore {
|
||||
expr_vstore_uniq, // ~[1,2,3,4]
|
||||
expr_vstore_box, // @[1,2,3,4]
|
||||
expr_vstore_mut_box, // @mut [1,2,3,4]
|
||||
expr_vstore_slice // &[1,2,3,4]
|
||||
expr_vstore_slice, // &[1,2,3,4]
|
||||
expr_vstore_mut_slice, // &mut [1,2,3,4]
|
||||
}
|
||||
|
||||
pure fn is_blockish(p: ast::Proto) -> bool {
|
||||
|
@ -37,7 +37,7 @@ use ast::{_mod, add, arg, arm, attribute,
|
||||
expr_method_call, expr_paren, expr_path, expr_rec, expr_repeat,
|
||||
expr_ret, expr_swap, expr_struct, expr_tup, expr_unary,
|
||||
expr_unary_move, expr_vec, expr_vstore, expr_vstore_mut_box,
|
||||
expr_while, extern_fn, field, fn_decl,
|
||||
expr_vstore_mut_slice, expr_while, extern_fn, field, fn_decl,
|
||||
foreign_item, foreign_item_const, foreign_item_fn, foreign_mod,
|
||||
ident, impure_fn, infer, inherited,
|
||||
item, item_, item_class, item_const, item_enum, item_fn,
|
||||
@ -1456,6 +1456,9 @@ impl Parser {
|
||||
if m == m_imm => {
|
||||
expr_vstore(e, expr_vstore_slice)
|
||||
}
|
||||
expr_vec(*) if m == m_mutbl => {
|
||||
expr_vstore(e, expr_vstore_mut_slice)
|
||||
}
|
||||
_ => expr_addr_of(m, e)
|
||||
};
|
||||
}
|
||||
|
@ -1052,6 +1052,10 @@ fn print_expr_vstore(s: ps, t: ast::expr_vstore) {
|
||||
word(s.s, ~"mut");
|
||||
}
|
||||
ast::expr_vstore_slice => word(s.s, ~"&"),
|
||||
ast::expr_vstore_mut_slice => {
|
||||
word(s.s, ~"&");
|
||||
word(s.s, ~"mut");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
4
src/test/run-pass/mut-vstore-expr.rs
Normal file
4
src/test/run-pass/mut-vstore-expr.rs
Normal file
@ -0,0 +1,4 @@
|
||||
fn main() {
|
||||
let x: &mut [int] = &mut [ 1, 2, 3 ];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user