Skip to content

librustc: Implement "&mut [T]" as an expression #4138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/trans/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,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(_)) => {
Expand Down
1 change: 1 addition & 0 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3099,6 +3099,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
Expand Down
6 changes: 4 additions & 2 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
};
}
Expand Down
4 changes: 4 additions & 0 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,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");
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/test/run-pass/mut-vstore-expr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
let x: &mut [int] = &mut [ 1, 2, 3 ];
}