make mut a keyword synonymous with mutable

first step towards issue #1273
This commit is contained in:
Niko Matsakis 2012-02-15 11:25:39 -08:00
parent dddd9908d5
commit bfff2a8d55
29 changed files with 224 additions and 206 deletions

View file

@ -159,7 +159,7 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
bind middle::tstate::ck::check_crate(ty_cx, crate)); bind middle::tstate::ck::check_crate(ty_cx, crate));
let mut_map = let mut_map =
time(time_passes, "mutability checking", time(time_passes, "mutability checking",
bind middle::mut::check_crate(ty_cx, crate)); bind middle::mutbl::check_crate(ty_cx, crate));
let (copy_map, ref_map) = let (copy_map, ref_map) =
time(time_passes, "alias checking", time(time_passes, "alias checking",
bind middle::alias::check_crate(ty_cx, crate)); bind middle::alias::check_crate(ty_cx, crate));

View file

@ -256,7 +256,7 @@ fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::ty {
let test_desc_ty: ast::ty = let test_desc_ty: ast::ty =
nospan(ast::ty_path(test_desc_ty_path, cx.sess.next_node_id())); nospan(ast::ty_path(test_desc_ty_path, cx.sess.next_node_id()));
let vec_mt: ast::mt = {ty: @test_desc_ty, mut: ast::imm}; let vec_mt: ast::mt = {ty: @test_desc_ty, mutbl: ast::m_imm};
ret @nospan(ast::ty_vec(vec_mt)); ret @nospan(ast::ty_vec(vec_mt));
} }
@ -270,7 +270,7 @@ fn mk_test_desc_vec(cx: test_ctxt) -> @ast::expr {
} }
ret @{id: cx.sess.next_node_id(), ret @{id: cx.sess.next_node_id(),
node: ast::expr_vec(descs, ast::imm), node: ast::expr_vec(descs, ast::m_imm),
span: dummy_sp()}; span: dummy_sp()};
} }
@ -288,7 +288,7 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
span: span}; span: span};
let name_field: ast::field = let name_field: ast::field =
nospan({mut: ast::imm, ident: "name", expr: @name_expr}); nospan({mutbl: ast::m_imm, ident: "name", expr: @name_expr});
let fn_path = @nospan({global: false, idents: path, types: []}); let fn_path = @nospan({global: false, idents: path, types: []});
@ -300,7 +300,7 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
let fn_wrapper_expr = mk_test_wrapper(cx, fn_expr, span); let fn_wrapper_expr = mk_test_wrapper(cx, fn_expr, span);
let fn_field: ast::field = let fn_field: ast::field =
nospan({mut: ast::imm, ident: "fn", expr: fn_wrapper_expr}); nospan({mutbl: ast::m_imm, ident: "fn", expr: fn_wrapper_expr});
let ignore_lit: ast::lit = nospan(ast::lit_bool(test.ignore)); let ignore_lit: ast::lit = nospan(ast::lit_bool(test.ignore));
@ -310,7 +310,7 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
span: span}; span: span};
let ignore_field: ast::field = let ignore_field: ast::field =
nospan({mut: ast::imm, ident: "ignore", expr: @ignore_expr}); nospan({mutbl: ast::m_imm, ident: "ignore", expr: @ignore_expr});
let fail_lit: ast::lit = nospan(ast::lit_bool(test.should_fail)); let fail_lit: ast::lit = nospan(ast::lit_bool(test.should_fail));
@ -320,7 +320,7 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
span: span}; span: span};
let fail_field: ast::field = let fail_field: ast::field =
nospan({mut: ast::imm, ident: "should_fail", expr: @fail_expr}); nospan({mutbl: ast::m_imm, ident: "should_fail", expr: @fail_expr});
let desc_rec_: ast::expr_ = let desc_rec_: ast::expr_ =
ast::expr_rec([name_field, fn_field, ignore_field, fail_field], ast::expr_rec([name_field, fn_field, ignore_field, fail_field],
@ -378,7 +378,7 @@ fn mk_test_wrapper(cx: test_ctxt,
fn mk_main(cx: test_ctxt) -> @ast::item { fn mk_main(cx: test_ctxt) -> @ast::item {
let str_pt = @nospan({global: false, idents: ["str"], types: []}); let str_pt = @nospan({global: false, idents: ["str"], types: []});
let str_ty = @nospan(ast::ty_path(str_pt, cx.sess.next_node_id())); let str_ty = @nospan(ast::ty_path(str_pt, cx.sess.next_node_id()));
let args_mt: ast::mt = {ty: str_ty, mut: ast::imm}; let args_mt: ast::mt = {ty: str_ty, mutbl: ast::m_imm};
let args_ty: ast::ty = nospan(ast::ty_vec(args_mt)); let args_ty: ast::ty = nospan(ast::ty_vec(args_mt));
let args_arg: ast::arg = let args_arg: ast::arg =

View file

@ -483,28 +483,28 @@ impl ast_output for ast_ctxt {
self.tag(at_ty_bot) {||} self.tag(at_ty_bot) {||}
} }
ty_box({ty: ty, mut: m}) { ty_box({ty: ty, mutbl: m}) {
self.tag(at_ty_box) {|| self.tag(at_ty_box) {||
self.ty(ty); self.ty(ty);
self.mutbl(m); self.mutbl(m);
} }
} }
ty_uniq({ty: ty, mut: m}) { ty_uniq({ty: ty, mutbl: m}) {
self.tag(at_ty_uniq) {|| self.tag(at_ty_uniq) {||
self.ty(ty); self.ty(ty);
self.mutbl(m); self.mutbl(m);
} }
} }
ty_vec({ty: ty, mut: m}) { ty_vec({ty: ty, mutbl: m}) {
self.tag(at_ty_vec) {|| self.tag(at_ty_vec) {||
self.ty(ty); self.ty(ty);
self.mutbl(m); self.mutbl(m);
} }
} }
ty_ptr({ty: ty, mut: m}) { ty_ptr({ty: ty, mutbl: m}) {
self.tag(at_ty_ptr) {|| self.tag(at_ty_ptr) {||
self.ty(ty); self.ty(ty);
self.mutbl(m); self.mutbl(m);

View file

@ -311,11 +311,11 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
fn parse_mt(st: @pstate, conv: conv_did) -> ty::mt { fn parse_mt(st: @pstate, conv: conv_did) -> ty::mt {
let m; let m;
alt peek(st) { alt peek(st) {
'm' { next(st); m = ast::mut; } 'm' { next(st); m = ast::m_mutbl; }
'?' { next(st); m = ast::maybe_mut; } '?' { next(st); m = ast::m_const; }
_ { m = ast::imm; } _ { m = ast::m_imm; }
} }
ret {ty: parse_ty(st, conv), mut: m}; ret {ty: parse_ty(st, conv), mutbl: m};
} }
fn parse_def(st: @pstate, conv: conv_did) -> ast::def_id { fn parse_def(st: @pstate, conv: conv_did) -> ast::def_id {
@ -356,7 +356,7 @@ fn parse_ty_fn(st: @pstate, conv: conv_did) -> ty::fn_ty {
let inputs: [ty::arg] = []; let inputs: [ty::arg] = [];
while peek(st) != ']' { while peek(st) != ']' {
let mode = alt check peek(st) { let mode = alt check peek(st) {
'&' { ast::by_mut_ref } '&' { ast::by_mutbl_ref }
'-' { ast::by_move } '-' { ast::by_move }
'+' { ast::by_copy } '+' { ast::by_copy }
'=' { ast::by_ref } '=' { ast::by_ref }

View file

@ -85,10 +85,10 @@ fn enc_ty(w: io::writer, cx: @ctxt, t: ty::t) {
} }
} }
fn enc_mt(w: io::writer, cx: @ctxt, mt: ty::mt) { fn enc_mt(w: io::writer, cx: @ctxt, mt: ty::mt) {
alt mt.mut { alt mt.mutbl {
imm { } m_imm { }
mut { w.write_char('m'); } m_mutbl { w.write_char('m'); }
maybe_mut { w.write_char('?'); } m_const { w.write_char('?'); }
} }
enc_ty(w, cx, mt.ty); enc_ty(w, cx, mt.ty);
} }
@ -215,7 +215,7 @@ fn enc_ty_fn(w: io::writer, cx: @ctxt, ft: ty::fn_ty) {
w.write_char('['); w.write_char('[');
for arg: ty::arg in ft.inputs { for arg: ty::arg in ft.inputs {
alt ty::resolved_mode(cx.tcx, arg.mode) { alt ty::resolved_mode(cx.tcx, arg.mode) {
by_mut_ref { w.write_char('&'); } by_mutbl_ref { w.write_char('&'); }
by_move { w.write_char('-'); } by_move { w.write_char('-'); }
by_copy { w.write_char('+'); } by_copy { w.write_char('+'); }
by_ref { w.write_char('='); } by_ref { w.write_char('='); }

View file

@ -22,7 +22,7 @@ type invalid = {reason: invalid_reason,
node_id: node_id, node_id: node_id,
sp: span, path: @ast::path}; sp: span, path: @ast::path};
enum unsafe_ty { contains(ty::t), mut_contains(ty::t), } enum unsafe_ty { contains(ty::t), mutbl_contains(ty::t), }
type binding = @{node_id: node_id, type binding = @{node_id: node_id,
span: span, span: span,
@ -183,9 +183,9 @@ fn add_bindings_for_let(cx: ctx, &bs: [binding], loc: @ast::local) {
err(cx, loc.span, "a reference binding can't be \ err(cx, loc.span, "a reference binding can't be \
rooted in a temporary"); rooted in a temporary");
} }
for proot in pattern_roots(cx.tcx, root.mut, loc.node.pat) { for proot in pattern_roots(cx.tcx, root.mutbl, loc.node.pat) {
let bnd = mk_binding(cx, proot.id, proot.span, root_var, let bnd = mk_binding(cx, proot.id, proot.span, root_var,
unsafe_set(proot.mut)); unsafe_set(proot.mutbl));
// Don't implicitly copy explicit references // Don't implicitly copy explicit references
bnd.copied = not_allowed; bnd.copied = not_allowed;
bs += [bnd]; bs += [bnd];
@ -228,7 +228,7 @@ fn check_call(cx: ctx, sc: scope, f: @ast::expr, args: [@ast::expr])
let arg = args[i]; let arg = args[i];
let root = expr_root(cx, arg, false); let root = expr_root(cx, arg, false);
alt ty::resolved_mode(cx.tcx, arg_t.mode) { alt ty::resolved_mode(cx.tcx, arg_t.mode) {
ast::by_mut_ref { ast::by_mutbl_ref {
alt path_def(cx, arg) { alt path_def(cx, arg) {
some(def) { some(def) {
let dnum = ast_util::def_id_of_def(def).node; let dnum = ast_util::def_id_of_def(def).node;
@ -242,14 +242,14 @@ fn check_call(cx: ctx, sc: scope, f: @ast::expr, args: [@ast::expr])
let root_var = path_def_id(cx, root.ex); let root_var = path_def_id(cx, root.ex);
let arg_copied = alt ty::resolved_mode(cx.tcx, arg_t.mode) { let arg_copied = alt ty::resolved_mode(cx.tcx, arg_t.mode) {
ast::by_move | ast::by_copy { copied } ast::by_move | ast::by_copy { copied }
ast::by_mut_ref { not_allowed } ast::by_mutbl_ref { not_allowed }
ast::by_ref | ast::by_val { not_copied } ast::by_ref | ast::by_val { not_copied }
}; };
bindings += [@{node_id: arg.id, bindings += [@{node_id: arg.id,
span: arg.span, span: arg.span,
root_var: root_var, root_var: root_var,
local_id: 0u, local_id: 0u,
unsafe_tys: unsafe_set(root.mut), unsafe_tys: unsafe_set(root.mutbl),
mutable copied: arg_copied}]; mutable copied: arg_copied}];
i += 1u; i += 1u;
} }
@ -285,7 +285,7 @@ fn check_call(cx: ctx, sc: scope, f: @ast::expr, args: [@ast::expr])
let i = 0u; let i = 0u;
for arg_t: ty::arg in arg_ts { for arg_t: ty::arg in arg_ts {
let mut_alias = let mut_alias =
(ast::by_mut_ref == ty::arg_mode(cx.tcx, arg_t)); (ast::by_mutbl_ref == ty::arg_mode(cx.tcx, arg_t));
if i != j && if i != j &&
ty_can_unsafely_include(cx, unsafe_ty, arg_t.ty, ty_can_unsafely_include(cx, unsafe_ty, arg_t.ty,
mut_alias) && mut_alias) &&
@ -339,14 +339,14 @@ fn check_alt(cx: ctx, input: @ast::expr, arms: [ast::arm], sc: scope,
span: span}; span: span};
let binding_info: [info] = []; let binding_info: [info] = [];
for pat in a.pats { for pat in a.pats {
for proot in pattern_roots(cx.tcx, root.mut, pat) { for proot in pattern_roots(cx.tcx, root.mutbl, pat) {
let canon_id = pat_id_map.get(proot.name); let canon_id = pat_id_map.get(proot.name);
alt vec::find(binding_info, {|x| x.id == canon_id}) { alt vec::find(binding_info, {|x| x.id == canon_id}) {
some(s) { s.unsafe_tys += unsafe_set(proot.mut); } some(s) { s.unsafe_tys += unsafe_set(proot.mutbl); }
none { none {
binding_info += [ binding_info += [
{id: canon_id, {id: canon_id,
mutable unsafe_tys: unsafe_set(proot.mut), mutable unsafe_tys: unsafe_set(proot.mutbl),
span: proot.span}]; span: proot.span}];
} }
} }
@ -369,20 +369,20 @@ fn check_for(cx: ctx, local: @ast::local, seq: @ast::expr, blk: ast::blk,
// If this is a mutable vector, don't allow it to be touched. // If this is a mutable vector, don't allow it to be touched.
let seq_t = ty::expr_ty(cx.tcx, seq); let seq_t = ty::expr_ty(cx.tcx, seq);
let cur_mut = root.mut; let cur_mutbl = root.mutbl;
alt ty::get(seq_t).struct { alt ty::get(seq_t).struct {
ty::ty_vec(mt) { ty::ty_vec(mt) {
if mt.mut != ast::imm { if mt.mutbl != ast::m_imm {
cur_mut = some(contains(seq_t)); cur_mutbl = some(contains(seq_t));
} }
} }
_ {} _ {}
} }
let root_var = path_def_id(cx, root.ex); let root_var = path_def_id(cx, root.ex);
let new_bs = sc.bs; let new_bs = sc.bs;
for proot in pattern_roots(cx.tcx, cur_mut, local.node.pat) { for proot in pattern_roots(cx.tcx, cur_mutbl, local.node.pat) {
new_bs += [mk_binding(cx, proot.id, proot.span, root_var, new_bs += [mk_binding(cx, proot.id, proot.span, root_var,
unsafe_set(proot.mut))]; unsafe_set(proot.mutbl))];
} }
visit::visit_block(blk, {bs: new_bs with sc}, v); visit::visit_block(blk, {bs: new_bs with sc}, v);
} }
@ -493,36 +493,36 @@ fn path_def_id(cx: ctx, ex: @ast::expr) -> option<ast::node_id> {
} }
fn ty_can_unsafely_include(cx: ctx, needle: unsafe_ty, haystack: ty::t, fn ty_can_unsafely_include(cx: ctx, needle: unsafe_ty, haystack: ty::t,
mut: bool) -> bool { mutbl: bool) -> bool {
fn get_mut(cur: bool, mt: ty::mt) -> bool { fn get_mutbl(cur: bool, mt: ty::mt) -> bool {
ret cur || mt.mut != ast::imm; ret cur || mt.mutbl != ast::m_imm;
} }
fn helper(tcx: ty::ctxt, needle: unsafe_ty, haystack: ty::t, mut: bool) fn helper(tcx: ty::ctxt, needle: unsafe_ty, haystack: ty::t, mutbl: bool)
-> bool { -> bool {
if alt needle { if alt needle {
contains(ty) { ty == haystack } contains(ty) { ty == haystack }
mut_contains(ty) { mut && ty == haystack } mutbl_contains(ty) { mutbl && ty == haystack }
} { ret true; } } { ret true; }
alt ty::get(haystack).struct { alt ty::get(haystack).struct {
ty::ty_enum(_, ts) { ty::ty_enum(_, ts) {
for t: ty::t in ts { for t: ty::t in ts {
if helper(tcx, needle, t, mut) { ret true; } if helper(tcx, needle, t, mutbl) { ret true; }
} }
ret false; ret false;
} }
ty::ty_box(mt) | ty::ty_ptr(mt) | ty::ty_uniq(mt) { ty::ty_box(mt) | ty::ty_ptr(mt) | ty::ty_uniq(mt) {
ret helper(tcx, needle, mt.ty, get_mut(mut, mt)); ret helper(tcx, needle, mt.ty, get_mutbl(mutbl, mt));
} }
ty::ty_rec(fields) { ty::ty_rec(fields) {
for f: ty::field in fields { for f: ty::field in fields {
if helper(tcx, needle, f.mt.ty, get_mut(mut, f.mt)) { if helper(tcx, needle, f.mt.ty, get_mutbl(mutbl, f.mt)) {
ret true; ret true;
} }
} }
ret false; ret false;
} }
ty::ty_tup(ts) { ty::ty_tup(ts) {
for t in ts { if helper(tcx, needle, t, mut) { ret true; } } for t in ts { if helper(tcx, needle, t, mutbl) { ret true; } }
ret false; ret false;
} }
ty::ty_fn({proto: ast::proto_bare, _}) { ret false; } ty::ty_fn({proto: ast::proto_bare, _}) { ret false; }
@ -532,11 +532,11 @@ fn ty_can_unsafely_include(cx: ctx, needle: unsafe_ty, haystack: ty::t,
// treated as opaque downstream, and is thus safe unless we // treated as opaque downstream, and is thus safe unless we
// saw mutable fields, in which case the whole thing can be // saw mutable fields, in which case the whole thing can be
// overwritten. // overwritten.
ty::ty_param(_, _) { ret mut; } ty::ty_param(_, _) { ret mutbl; }
_ { ret false; } _ { ret false; }
} }
} }
ret helper(cx.tcx, needle, haystack, mut); ret helper(cx.tcx, needle, haystack, mutbl);
} }
fn def_is_local(d: ast::def) -> bool { fn def_is_local(d: ast::def) -> bool {
@ -589,66 +589,66 @@ fn copy_is_expensive(tcx: ty::ctxt, ty: ty::t) -> bool {
type pattern_root = {id: node_id, type pattern_root = {id: node_id,
name: ident, name: ident,
mut: option<unsafe_ty>, mutbl: option<unsafe_ty>,
span: span}; span: span};
fn pattern_roots(tcx: ty::ctxt, mut: option<unsafe_ty>, pat: @ast::pat) fn pattern_roots(tcx: ty::ctxt, mutbl: option<unsafe_ty>, pat: @ast::pat)
-> [pattern_root] { -> [pattern_root] {
fn walk(tcx: ty::ctxt, mut: option<unsafe_ty>, pat: @ast::pat, fn walk(tcx: ty::ctxt, mutbl: option<unsafe_ty>, pat: @ast::pat,
&set: [pattern_root]) { &set: [pattern_root]) {
alt normalize_pat(tcx, pat).node { alt normalize_pat(tcx, pat).node {
ast::pat_wild | ast::pat_lit(_) | ast::pat_range(_, _) {} ast::pat_wild | ast::pat_lit(_) | ast::pat_range(_, _) {}
ast::pat_ident(nm, sub) { ast::pat_ident(nm, sub) {
set += [{id: pat.id, name: path_to_ident(nm), mut: mut, set += [{id: pat.id, name: path_to_ident(nm), mutbl: mutbl,
span: pat.span}]; span: pat.span}];
alt sub { some(p) { walk(tcx, mut, p, set); } _ {} } alt sub { some(p) { walk(tcx, mutbl, p, set); } _ {} }
} }
ast::pat_enum(_, ps) | ast::pat_tup(ps) { ast::pat_enum(_, ps) | ast::pat_tup(ps) {
for p in ps { walk(tcx, mut, p, set); } for p in ps { walk(tcx, mutbl, p, set); }
} }
ast::pat_rec(fs, _) { ast::pat_rec(fs, _) {
let ty = ty::node_id_to_type(tcx, pat.id); let ty = ty::node_id_to_type(tcx, pat.id);
for f in fs { for f in fs {
let m = ty::get_field(ty, f.ident).mt.mut != ast::imm, let m = ty::get_field(ty, f.ident).mt.mutbl != ast::m_imm,
c = if m { some(contains(ty)) } else { mut }; c = if m { some(contains(ty)) } else { mutbl };
walk(tcx, c, f.pat, set); walk(tcx, c, f.pat, set);
} }
} }
ast::pat_box(p) { ast::pat_box(p) {
let ty = ty::node_id_to_type(tcx, pat.id); let ty = ty::node_id_to_type(tcx, pat.id);
let m = alt ty::get(ty).struct { let m = alt ty::get(ty).struct {
ty::ty_box(mt) { mt.mut != ast::imm } ty::ty_box(mt) { mt.mutbl != ast::m_imm }
_ { tcx.sess.span_bug(pat.span, "box pat has non-box type"); } _ { tcx.sess.span_bug(pat.span, "box pat has non-box type"); }
}, },
c = if m {some(contains(ty)) } else { mut }; c = if m {some(contains(ty)) } else { mutbl };
walk(tcx, c, p, set); walk(tcx, c, p, set);
} }
ast::pat_uniq(p) { ast::pat_uniq(p) {
let ty = ty::node_id_to_type(tcx, pat.id); let ty = ty::node_id_to_type(tcx, pat.id);
let m = alt ty::get(ty).struct { let m = alt ty::get(ty).struct {
ty::ty_uniq(mt) { mt.mut != ast::imm } ty::ty_uniq(mt) { mt.mutbl != ast::m_imm }
_ { tcx.sess.span_bug(pat.span, "uniq pat has non-uniq type"); } _ { tcx.sess.span_bug(pat.span, "uniq pat has non-uniq type"); }
}, },
c = if m { some(contains(ty)) } else { mut }; c = if m { some(contains(ty)) } else { mutbl };
walk(tcx, c, p, set); walk(tcx, c, p, set);
} }
} }
} }
let set = []; let set = [];
walk(tcx, mut, pat, set); walk(tcx, mutbl, pat, set);
ret set; ret set;
} }
// Wraps the expr_root in mut.rs to also handle roots that exist through // Wraps the expr_root in mutbl.rs to also handle roots that exist through
// return-by-reference // return-by-reference
fn expr_root(cx: ctx, ex: @ast::expr, autoderef: bool) fn expr_root(cx: ctx, ex: @ast::expr, autoderef: bool)
-> {ex: @ast::expr, mut: option<unsafe_ty>} { -> {ex: @ast::expr, mutbl: option<unsafe_ty>} {
let base_root = mut::expr_root(cx.tcx, ex, autoderef); let base_root = mutbl::expr_root(cx.tcx, ex, autoderef);
let unsafe_ty = none; let unsafe_ty = none;
for d in *base_root.ds { for d in *base_root.ds {
if d.mut { unsafe_ty = some(contains(d.outer_t)); break; } if d.mutbl { unsafe_ty = some(contains(d.outer_t)); break; }
} }
ret {ex: base_root.ex, mut: unsafe_ty}; ret {ex: base_root.ex, mutbl: unsafe_ty};
} }
fn unsafe_set(from: option<unsafe_ty>) -> [unsafe_ty] { fn unsafe_set(from: option<unsafe_ty>) -> [unsafe_ty] {

View file

@ -587,21 +587,21 @@ fn create_ty(_cx: @crate_ctxt, _t: ty::t, _ty: @ast::ty)
ty::ty_float(t) { ast::ty_float(t) } ty::ty_float(t) { ast::ty_float(t) }
ty::ty_uint(t) { ast::ty_uint(t) } ty::ty_uint(t) { ast::ty_uint(t) }
ty::ty_box(mt) { ast::ty_box({ty: t_to_ty(cx, mt.ty, span), ty::ty_box(mt) { ast::ty_box({ty: t_to_ty(cx, mt.ty, span),
mut: mt.mut}) } mutbl: mt.mutbl}) }
ty::ty_uniq(mt) { ast::ty_uniq({ty: t_to_ty(cx, mt.ty, span), ty::ty_uniq(mt) { ast::ty_uniq({ty: t_to_ty(cx, mt.ty, span),
mut: mt.mut}) } mutbl: mt.mutbl}) }
ty::ty_rec(fields) { ty::ty_rec(fields) {
let fs = []; let fs = [];
for field in fields { for field in fields {
fs += [{node: {ident: field.ident, fs += [{node: {ident: field.ident,
mt: {ty: t_to_ty(cx, field.mt.ty, span), mt: {ty: t_to_ty(cx, field.mt.ty, span),
mut: field.mt.mut}}, mutbl: field.mt.mutbl}},
span: span}]; span: span}];
} }
ast::ty_rec(fs) ast::ty_rec(fs)
} }
ty::ty_vec(mt) { ast::ty_vec({ty: t_to_ty(cx, mt.ty, span), ty::ty_vec(mt) { ast::ty_vec({ty: t_to_ty(cx, mt.ty, span),
mut: mt.mut}) } mutbl: mt.mutbl}) }
_ { _ {
cx.tcx.sess.span_bug(span, "t_to_ty: Can't handle this type"); cx.tcx.sess.span_bug(span, "t_to_ty: Can't handle this type");
} }

View file

@ -167,7 +167,7 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
for arg_t in ty::ty_fn_args(ty::expr_ty(cx.tcx, f)) { for arg_t in ty::ty_fn_args(ty::expr_ty(cx.tcx, f)) {
alt ty::arg_mode(cx.tcx, arg_t) { alt ty::arg_mode(cx.tcx, arg_t) {
by_copy { maybe_copy(cx, args[i]); } by_copy { maybe_copy(cx, args[i]); }
by_ref | by_val | by_mut_ref | by_move { } by_ref | by_val | by_mutbl_ref | by_move { }
} }
i += 1u; i += 1u;
} }

View file

@ -156,7 +156,7 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
} }
_ { _ {
alt ty::arg_mode(cx.tcx, arg_ts[i]) { alt ty::arg_mode(cx.tcx, arg_ts[i]) {
by_mut_ref { clear_if_path(cx, arg, v, false); } by_mutbl_ref { clear_if_path(cx, arg, v, false); }
_ { v.visit_expr(arg, cx, v); } _ { v.visit_expr(arg, cx, v); }
} }
} }
@ -299,7 +299,7 @@ fn clear_def_if_path(cx: ctx, d: def, to: bool)
clear_in_current(cx, def_id.node, to); clear_in_current(cx, def_id.node, to);
some(def_id.node) some(def_id.node)
} }
by_ref | by_val | by_mut_ref { by_ref | by_val | by_mutbl_ref {
none none
} }
} }

View file

@ -5,7 +5,7 @@ import driver::session::session;
enum deref_t { unbox(bool), field, index, } enum deref_t { unbox(bool), field, index, }
type deref = @{mut: bool, kind: deref_t, outer_t: ty::t}; type deref = @{mutbl: bool, kind: deref_t, outer_t: ty::t};
// Finds the root (the thing that is dereferenced) for the given expr, and a // Finds the root (the thing that is dereferenced) for the given expr, and a
// vec of dereferences that were used on this root. Note that, in this vec, // vec of dereferences that were used on this root. Note that, in this vec,
@ -18,15 +18,19 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
while true { while true {
alt ty::get(t).struct { alt ty::get(t).struct {
ty::ty_box(mt) { ty::ty_box(mt) {
ds += [@{mut: mt.mut == mut, kind: unbox(false), outer_t: t}]; ds += [@{mutbl: mt.mutbl == m_mutbl,
kind: unbox(false),
outer_t: t}];
t = mt.ty; t = mt.ty;
} }
ty::ty_uniq(mt) { ty::ty_uniq(mt) {
ds += [@{mut: mt.mut == mut, kind: unbox(false), outer_t: t}]; ds += [@{mutbl: mt.mutbl == m_mutbl,
kind: unbox(false),
outer_t: t}];
t = mt.ty; t = mt.ty;
} }
ty::ty_res(_, inner, tps) { ty::ty_res(_, inner, tps) {
ds += [@{mut: false, kind: unbox(false), outer_t: t}]; ds += [@{mutbl: false, kind: unbox(false), outer_t: t}];
t = ty::substitute_type_params(tcx, tps, inner); t = ty::substitute_type_params(tcx, tps, inner);
} }
ty::ty_enum(did, tps) { ty::ty_enum(did, tps) {
@ -35,7 +39,7 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
vec::len(variants[0].args) != 1u { vec::len(variants[0].args) != 1u {
break; break;
} }
ds += [@{mut: false, kind: unbox(false), outer_t: t}]; ds += [@{mutbl: false, kind: unbox(false), outer_t: t}];
t = ty::substitute_type_params(tcx, tps, variants[0].args[0]); t = ty::substitute_type_params(tcx, tps, variants[0].args[0]);
} }
_ { break; } _ { break; }
@ -48,19 +52,19 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
alt copy ex.node { alt copy ex.node {
expr_field(base, ident, _) { expr_field(base, ident, _) {
let auto_unbox = maybe_auto_unbox(tcx, ty::expr_ty(tcx, base)); let auto_unbox = maybe_auto_unbox(tcx, ty::expr_ty(tcx, base));
let is_mut = false; let is_mutbl = false;
alt ty::get(auto_unbox.t).struct { alt ty::get(auto_unbox.t).struct {
ty::ty_rec(fields) { ty::ty_rec(fields) {
for fld: ty::field in fields { for fld: ty::field in fields {
if str::eq(ident, fld.ident) { if str::eq(ident, fld.ident) {
is_mut = fld.mt.mut == mut; is_mutbl = fld.mt.mutbl == m_mutbl;
break; break;
} }
} }
} }
_ {} _ {}
} }
ds += [@{mut: is_mut, kind: field, outer_t: auto_unbox.t}]; ds += [@{mutbl: is_mutbl, kind: field, outer_t: auto_unbox.t}];
ds += auto_unbox.ds; ds += auto_unbox.ds;
ex = base; ex = base;
} }
@ -69,12 +73,12 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
alt ty::get(auto_unbox.t).struct { alt ty::get(auto_unbox.t).struct {
ty::ty_vec(mt) { ty::ty_vec(mt) {
ds += ds +=
[@{mut: mt.mut == mut, [@{mutbl: mt.mutbl == m_mutbl,
kind: index, kind: index,
outer_t: auto_unbox.t}]; outer_t: auto_unbox.t}];
} }
ty::ty_str { ty::ty_str {
ds += [@{mut: false, kind: index, outer_t: auto_unbox.t}]; ds += [@{mutbl: false, kind: index, outer_t: auto_unbox.t}];
} }
_ { break; } _ { break; }
} }
@ -84,17 +88,20 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
expr_unary(op, base) { expr_unary(op, base) {
if op == deref { if op == deref {
let base_t = ty::expr_ty(tcx, base); let base_t = ty::expr_ty(tcx, base);
let is_mut = false, ptr = false; let is_mutbl = false, ptr = false;
alt ty::get(base_t).struct { alt ty::get(base_t).struct {
ty::ty_box(mt) { is_mut = mt.mut == mut; } ty::ty_box(mt) { is_mutbl = mt.mutbl == m_mutbl; }
ty::ty_uniq(mt) { is_mut = mt.mut == mut; } ty::ty_uniq(mt) { is_mutbl = mt.mutbl == m_mutbl; }
ty::ty_res(_, _, _) { } ty::ty_res(_, _, _) { }
ty::ty_enum(_, _) { } ty::ty_enum(_, _) { }
ty::ty_ptr(mt) { is_mut = mt.mut == mut; ptr = true; } ty::ty_ptr(mt) {
is_mutbl = mt.mutbl == m_mutbl;
ptr = true;
}
_ { tcx.sess.span_bug(base.span, "Ill-typed base \ _ { tcx.sess.span_bug(base.span, "Ill-typed base \
expression in deref"); } expression in deref"); }
} }
ds += [@{mut: is_mut, kind: unbox(ptr && is_mut), ds += [@{mutbl: is_mutbl, kind: unbox(ptr && is_mutbl),
outer_t: base_t}]; outer_t: base_t}];
ex = base; ex = base;
} else { break; } } else { break; }
@ -109,27 +116,27 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
ret {ex: ex, ds: @ds}; ret {ex: ex, ds: @ds};
} }
// Actual mut-checking pass // Actual mutbl-checking pass
type mut_map = std::map::hashmap<node_id, ()>; type mutbl_map = std::map::hashmap<node_id, ()>;
type ctx = {tcx: ty::ctxt, mut_map: mut_map}; type ctx = {tcx: ty::ctxt, mutbl_map: mutbl_map};
fn check_crate(tcx: ty::ctxt, crate: @crate) -> mut_map { fn check_crate(tcx: ty::ctxt, crate: @crate) -> mutbl_map {
let cx = @{tcx: tcx, mut_map: std::map::new_int_hash()}; let cx = @{tcx: tcx, mutbl_map: std::map::new_int_hash()};
let v = @{visit_expr: bind visit_expr(cx, _, _, _), let v = @{visit_expr: bind visit_expr(cx, _, _, _),
visit_decl: bind visit_decl(cx, _, _, _) visit_decl: bind visit_decl(cx, _, _, _)
with *visit::default_visitor()}; with *visit::default_visitor()};
visit::visit_crate(*crate, (), visit::mk_vt(v)); visit::visit_crate(*crate, (), visit::mk_vt(v));
ret cx.mut_map; ret cx.mutbl_map;
} }
enum msg { msg_assign, msg_move_out, msg_mut_ref, } enum msg { msg_assign, msg_move_out, msg_mutbl_ref, }
fn mk_err(cx: @ctx, span: syntax::codemap::span, msg: msg, name: str) { fn mk_err(cx: @ctx, span: syntax::codemap::span, msg: msg, name: str) {
cx.tcx.sess.span_err(span, alt msg { cx.tcx.sess.span_err(span, alt msg {
msg_assign { "assigning to " + name } msg_assign { "assigning to " + name }
msg_move_out { "moving out of " + name } msg_move_out { "moving out of " + name }
msg_mut_ref { "passing " + name + " by mutable reference" } msg_mutbl_ref { "passing " + name + " by mutable reference" }
}); });
} }
@ -178,7 +185,7 @@ fn check_lval(cx: @ctx, dest: @expr, msg: msg) {
some(name) { mk_err(cx, dest.span, msg, name); } some(name) { mk_err(cx, dest.span, msg, name); }
_ { } _ { }
} }
cx.mut_map.insert(ast_util::def_id_of_def(def).node, ()); cx.mutbl_map.insert(ast_util::def_id_of_def(def).node, ());
} }
_ { _ {
let root = expr_root(cx.tcx, dest, false); let root = expr_root(cx.tcx, dest, false);
@ -186,12 +193,12 @@ fn check_lval(cx: @ctx, dest: @expr, msg: msg) {
if msg != msg_move_out { if msg != msg_move_out {
mk_err(cx, dest.span, msg, "non-lvalue"); mk_err(cx, dest.span, msg, "non-lvalue");
} }
} else if !root.ds[0].mut { } else if !root.ds[0].mutbl {
let name = let name =
alt root.ds[0].kind { alt root.ds[0].kind {
mut::unbox(_) { "immutable box" } mutbl::unbox(_) { "immutable box" }
mut::field { "immutable field" } mutbl::field { "immutable field" }
mut::index { "immutable vec content" } mutbl::index { "immutable vec content" }
}; };
mk_err(cx, dest.span, msg, name); mk_err(cx, dest.span, msg, name);
} }
@ -227,7 +234,7 @@ fn check_call(cx: @ctx, f: @expr, args: [@expr]) {
let i = 0u; let i = 0u;
for arg_t: ty::arg in arg_ts { for arg_t: ty::arg in arg_ts {
alt ty::resolved_mode(cx.tcx, arg_t.mode) { alt ty::resolved_mode(cx.tcx, arg_t.mode) {
by_mut_ref { check_lval(cx, args[i], msg_mut_ref); } by_mutbl_ref { check_lval(cx, args[i], msg_mutbl_ref); }
by_move { check_lval(cx, args[i], msg_move_out); } by_move { check_lval(cx, args[i], msg_move_out); }
by_ref | by_val | by_copy { } by_ref | by_val | by_copy { }
} }
@ -242,7 +249,7 @@ fn check_bind(cx: @ctx, f: @expr, args: [option<@expr>]) {
alt arg { alt arg {
some(expr) { some(expr) {
let o_msg = alt ty::resolved_mode(cx.tcx, arg_ts[i].mode) { let o_msg = alt ty::resolved_mode(cx.tcx, arg_ts[i].mode) {
by_mut_ref { some("by mutable reference") } by_mutbl_ref { some("by mutable reference") }
by_move { some("by move") } by_move { some("by move") }
_ { none } _ { none }
}; };
@ -269,7 +276,7 @@ fn is_immutable_def(cx: @ctx, def: def) -> option<str> {
def_arg(_, m) { def_arg(_, m) {
alt ty::resolved_mode(cx.tcx, m) { alt ty::resolved_mode(cx.tcx, m) {
by_ref | by_val { some("argument") } by_ref | by_val { some("argument") }
by_mut_ref | by_move | by_copy { none } by_mutbl_ref | by_move | by_copy { none }
} }
} }
def_self(_) { some("self argument") } def_self(_) { some("self argument") }

View file

@ -3987,7 +3987,7 @@ fn alloc_local(cx: @block_ctxt, local: @ast::local) -> @block_ctxt {
}; };
// Do not allocate space for locals that can be kept immediate. // Do not allocate space for locals that can be kept immediate.
let ccx = bcx_ccx(cx); let ccx = bcx_ccx(cx);
if is_simple && !ccx.mut_map.contains_key(local.node.pat.id) && if is_simple && !ccx.mutbl_map.contains_key(local.node.pat.id) &&
!ccx.last_uses.contains_key(local.node.pat.id) && !ccx.last_uses.contains_key(local.node.pat.id) &&
ty::type_is_immediate(t) { ty::type_is_immediate(t) {
alt local.node.init { alt local.node.init {
@ -4166,7 +4166,7 @@ fn copy_args_to_allocas(fcx: @fn_ctxt, bcx: @block_ctxt, args: [ast::arg],
let argval = alt fcx.llargs.get(id) { local_mem(v) { v } let argval = alt fcx.llargs.get(id) { local_mem(v) { v }
_ { epic_fail() } }; _ { epic_fail() } };
alt ty::resolved_mode(tcx, arg.mode) { alt ty::resolved_mode(tcx, arg.mode) {
ast::by_mut_ref { } ast::by_mutbl_ref { }
ast::by_move | ast::by_copy { add_clean(bcx, argval, arg.ty); } ast::by_move | ast::by_copy { add_clean(bcx, argval, arg.ty); }
ast::by_val { ast::by_val {
if !ty::type_is_immediate(arg.ty) { if !ty::type_is_immediate(arg.ty) {
@ -4598,7 +4598,7 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
let unit_ty = ty::mk_str(ccx.tcx); let unit_ty = ty::mk_str(ccx.tcx);
let vecarg_ty: ty::arg = let vecarg_ty: ty::arg =
{mode: ast::expl(ast::by_val), {mode: ast::expl(ast::by_val),
ty: ty::mk_vec(ccx.tcx, {ty: unit_ty, mut: ast::imm})}; ty: ty::mk_vec(ccx.tcx, {ty: unit_ty, mutbl: ast::m_imm})};
// FIXME: mk_nil should have a postcondition // FIXME: mk_nil should have a postcondition
let nt = ty::mk_nil(ccx.tcx); let nt = ty::mk_nil(ccx.tcx);
let llfty = type_of_fn(ccx, [vecarg_ty], nt, []); let llfty = type_of_fn(ccx, [vecarg_ty], nt, []);
@ -5003,7 +5003,7 @@ fn write_abi_version(ccx: @crate_ctxt) {
fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt, fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
output: str, emap: resolve::exp_map, amap: ast_map::map, output: str, emap: resolve::exp_map, amap: ast_map::map,
mut_map: mut::mut_map, copy_map: alias::copy_map, mutbl_map: mutbl::mutbl_map, copy_map: alias::copy_map,
last_uses: last_use::last_uses, impl_map: resolve::impl_map, last_uses: last_use::last_uses, impl_map: resolve::impl_map,
method_map: typeck::method_map, dict_map: typeck::dict_map) method_map: typeck::method_map, dict_map: typeck::dict_map)
-> (ModuleRef, link::link_meta) { -> (ModuleRef, link::link_meta) {
@ -5080,7 +5080,7 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
type_sha1s: ty::new_ty_hash(), type_sha1s: ty::new_ty_hash(),
type_short_names: ty::new_ty_hash(), type_short_names: ty::new_ty_hash(),
tcx: tcx, tcx: tcx,
mut_map: mut_map, mutbl_map: mutbl_map,
copy_map: copy_map, copy_map: copy_map,
last_uses: last_uses, last_uses: last_uses,
impl_map: impl_map, impl_map: impl_map,

View file

@ -276,7 +276,7 @@ fn store_environment(
// tuple. This could be a ptr in uniq or a box or on stack, // tuple. This could be a ptr in uniq or a box or on stack,
// whatever. // whatever.
let cbox_ty = tuplify_box_ty(tcx, cdata_ty); let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
let cboxptr_ty = ty::mk_ptr(tcx, {ty:cbox_ty, mut:ast::imm}); let cboxptr_ty = ty::mk_ptr(tcx, {ty:cbox_ty, mutbl:ast::m_imm});
let llbox = cast_if_we_can(bcx, llbox, cboxptr_ty); let llbox = cast_if_we_can(bcx, llbox, cboxptr_ty);
// If necessary, copy tydescs describing type parameters into the // If necessary, copy tydescs describing type parameters into the
@ -905,7 +905,7 @@ fn trans_bind_thunk(ccx: @crate_ctxt,
bcx = take_ty(bcx, alloc, out_arg.ty); bcx = take_ty(bcx, alloc, out_arg.ty);
val = alloc; val = alloc;
} }
ast::by_ref | ast::by_mut_ref | ast::by_move { } ast::by_ref | ast::by_mutbl_ref | ast::by_move { }
} }
// If the type is parameterized, then we need to cast the // If the type is parameterized, then we need to cast the

View file

@ -104,7 +104,7 @@ type crate_ctxt =
type_sha1s: hashmap<ty::t, str>, type_sha1s: hashmap<ty::t, str>,
type_short_names: hashmap<ty::t, str>, type_short_names: hashmap<ty::t, str>,
tcx: ty::ctxt, tcx: ty::ctxt,
mut_map: mut::mut_map, mutbl_map: mutbl::mutbl_map,
copy_map: alias::copy_map, copy_map: alias::copy_map,
last_uses: last_use::last_uses, last_uses: last_use::last_uses,
impl_map: resolve::impl_map, impl_map: resolve::impl_map,
@ -622,7 +622,7 @@ fn tuplify_box_ty(tcx: ty::ctxt, t: ty::t) -> ty::t {
// descr is embedded in the box (ty::type vs ty::send_type). This is useful // descr is embedded in the box (ty::type vs ty::send_type). This is useful
// for unique closure boxes, hence the name "cbox_ty" (closure box type). // for unique closure boxes, hence the name "cbox_ty" (closure box type).
fn tuplify_cbox_ty(tcx: ty::ctxt, t: ty::t, tydesc_t: ty::t) -> ty::t { fn tuplify_cbox_ty(tcx: ty::ctxt, t: ty::t, tydesc_t: ty::t) -> ty::t {
let ptr = ty::mk_ptr(tcx, {ty: ty::mk_nil(tcx), mut: ast::imm}); let ptr = ty::mk_ptr(tcx, {ty: ty::mk_nil(tcx), mutbl: ast::m_imm});
ret ty::mk_tup(tcx, [ty::mk_uint(tcx), tydesc_t, ret ty::mk_tup(tcx, [ty::mk_uint(tcx), tydesc_t,
ptr, ptr, ptr, ptr,
t]); t]);

View file

@ -782,7 +782,7 @@ fn dynamic_metrics(cx: @block_ctxt, t: ty::t) -> metrics {
// nominal type that has pointers to itself in it. // nominal type that has pointers to itself in it.
fn simplify_type(tcx: ty::ctxt, typ: ty::t) -> ty::t { fn simplify_type(tcx: ty::ctxt, typ: ty::t) -> ty::t {
fn nilptr(tcx: ty::ctxt) -> ty::t { fn nilptr(tcx: ty::ctxt) -> ty::t {
ty::mk_ptr(tcx, {ty: ty::mk_nil(tcx), mut: ast::imm}) ty::mk_ptr(tcx, {ty: ty::mk_nil(tcx), mutbl: ast::m_imm})
} }
fn simplifier(tcx: ty::ctxt, typ: ty::t) -> ty::t { fn simplifier(tcx: ty::ctxt, typ: ty::t) -> ty::t {
alt ty::get(typ).struct { alt ty::get(typ).struct {

View file

@ -1089,7 +1089,7 @@ fn callee_arg_init_ops(fcx: fn_ctxt, callee: node_id) -> [init_op] {
vec::map(callee_modes(fcx, callee)) {|m| vec::map(callee_modes(fcx, callee)) {|m|
alt ty::resolved_mode(fcx.ccx.tcx, m) { alt ty::resolved_mode(fcx.ccx.tcx, m) {
by_move { init_move } by_move { init_move }
by_copy | by_ref | by_val | by_mut_ref { init_assign } by_copy | by_ref | by_val | by_mutbl_ref { init_assign }
} }
} }
} }

View file

@ -275,7 +275,7 @@ fn forget_args_moved_in(fcx: fn_ctxt, parent: @expr, modes: [mode],
vec::iteri(modes) {|i,mode| vec::iteri(modes) {|i,mode|
alt ty::resolved_mode(fcx.ccx.tcx, mode) { alt ty::resolved_mode(fcx.ccx.tcx, mode) {
by_move { forget_in_postcond(fcx, parent.id, operands[i].id); } by_move { forget_in_postcond(fcx, parent.id, operands[i].id); }
by_ref | by_val | by_mut_ref | by_copy { } by_ref | by_val | by_mutbl_ref | by_copy { }
} }
} }
} }

View file

@ -147,7 +147,7 @@ type method = {ident: ast::ident,
type constr_table = hashmap<ast::node_id, [constr]>; type constr_table = hashmap<ast::node_id, [constr]>;
type mt = {ty: t, mut: ast::mutability}; type mt = {ty: t, mutbl: ast::mutability};
// Contains information needed to resolve types and (in the future) look up // Contains information needed to resolve types and (in the future) look up
@ -423,15 +423,18 @@ fn mk_enum(cx: ctxt, did: ast::def_id, tys: [t]) -> t {
fn mk_box(cx: ctxt, tm: mt) -> t { mk_t(cx, ty_box(tm)) } fn mk_box(cx: ctxt, tm: mt) -> t { mk_t(cx, ty_box(tm)) }
fn mk_imm_box(cx: ctxt, ty: t) -> t { mk_box(cx, {ty: ty, mut: ast::imm}) } fn mk_imm_box(cx: ctxt, ty: t) -> t { mk_box(cx, {ty: ty,
mutbl: ast::m_imm}) }
fn mk_uniq(cx: ctxt, tm: mt) -> t { mk_t(cx, ty_uniq(tm)) } fn mk_uniq(cx: ctxt, tm: mt) -> t { mk_t(cx, ty_uniq(tm)) }
fn mk_imm_uniq(cx: ctxt, ty: t) -> t { mk_uniq(cx, {ty: ty, mut: ast::imm}) } fn mk_imm_uniq(cx: ctxt, ty: t) -> t { mk_uniq(cx, {ty: ty,
mutbl: ast::m_imm}) }
fn mk_ptr(cx: ctxt, tm: mt) -> t { mk_t(cx, ty_ptr(tm)) } fn mk_ptr(cx: ctxt, tm: mt) -> t { mk_t(cx, ty_ptr(tm)) }
fn mk_mut_ptr(cx: ctxt, ty: t) -> t { mk_ptr(cx, {ty: ty, mut: ast::mut}) } fn mk_mut_ptr(cx: ctxt, ty: t) -> t { mk_ptr(cx, {ty: ty,
mutbl: ast::m_mutbl}) }
fn mk_vec(cx: ctxt, tm: mt) -> t { mk_t(cx, ty_vec(tm)) } fn mk_vec(cx: ctxt, tm: mt) -> t { mk_t(cx, ty_vec(tm)) }
@ -541,16 +544,16 @@ fn fold_ty(cx: ctxt, fld: fold_mode, ty_0: t) -> t {
ty_str | ty_type | ty_send_type | ty_opaque_closure_ptr(_) | ty_str | ty_type | ty_send_type | ty_opaque_closure_ptr(_) |
ty_opaque_box {} ty_opaque_box {}
ty_box(tm) { ty_box(tm) {
ty = mk_box(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}); ty = mk_box(cx, {ty: fold_ty(cx, fld, tm.ty), mutbl: tm.mutbl});
} }
ty_uniq(tm) { ty_uniq(tm) {
ty = mk_uniq(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}); ty = mk_uniq(cx, {ty: fold_ty(cx, fld, tm.ty), mutbl: tm.mutbl});
} }
ty_ptr(tm) { ty_ptr(tm) {
ty = mk_ptr(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}); ty = mk_ptr(cx, {ty: fold_ty(cx, fld, tm.ty), mutbl: tm.mutbl});
} }
ty_vec(tm) { ty_vec(tm) {
ty = mk_vec(cx, {ty: fold_ty(cx, fld, tm.ty), mut: tm.mut}); ty = mk_vec(cx, {ty: fold_ty(cx, fld, tm.ty), mutbl: tm.mutbl});
} }
ty_enum(tid, subtys) { ty_enum(tid, subtys) {
ty = mk_enum(cx, tid, vec::map(subtys, {|t| fold_ty(cx, fld, t) })); ty = mk_enum(cx, tid, vec::map(subtys, {|t| fold_ty(cx, fld, t) }));
@ -565,7 +568,7 @@ fn fold_ty(cx: ctxt, fld: fold_mode, ty_0: t) -> t {
let new_fields: [field] = []; let new_fields: [field] = [];
for fl: field in fields { for fl: field in fields {
let new_ty = fold_ty(cx, fld, fl.mt.ty); let new_ty = fold_ty(cx, fld, fl.mt.ty);
let new_mt = {ty: new_ty, mut: fl.mt.mut}; let new_mt = {ty: new_ty, mutbl: fl.mt.mutbl};
new_fields += [{ident: fl.ident, mt: new_mt}]; new_fields += [{ident: fl.ident, mt: new_mt}];
} }
ty = mk_rec(cx, new_fields); ty = mk_rec(cx, new_fields);
@ -922,12 +925,11 @@ fn type_allows_implicit_copy(cx: ctxt, ty: t) -> bool {
alt sty { alt sty {
ty_param(_, _) { true } ty_param(_, _) { true }
ty_vec(mt) { ty_vec(mt) {
mt.mut != ast::imm mt.mutbl != ast::m_imm
} }
ty_rec(fields) { ty_rec(fields) {
for field in fields { for field in fields {
if field.mt.mut != if field.mt.mutbl != ast::m_imm {
ast::imm {
ret true; ret true;
} }
} }
@ -1665,7 +1667,7 @@ mod unify {
// If you're unifying on something mutable then we have to // If you're unifying on something mutable then we have to
// be invariant on the inner type // be invariant on the inner type
let newvariance = alt expected { let newvariance = alt expected {
ast::mut { ast::m_mutbl {
variance_transform(variance, invariant) variance_transform(variance, invariant)
} }
_ { _ {
@ -1675,11 +1677,11 @@ mod unify {
if expected == actual { ret some((expected, newvariance)); } if expected == actual { ret some((expected, newvariance)); }
if variance == covariant { if variance == covariant {
if expected == ast::maybe_mut { if expected == ast::m_const {
ret some((actual, newvariance)); ret some((actual, newvariance));
} }
} else if variance == contravariant { } else if variance == contravariant {
if actual == ast::maybe_mut { if actual == ast::m_const {
ret some((expected, newvariance)); ret some((expected, newvariance));
} }
} }
@ -1960,7 +1962,7 @@ mod unify {
alt get(actual).struct { alt get(actual).struct {
ty_box(actual_mt) { ty_box(actual_mt) {
let (mutt, var) = alt unify_mut( let (mutt, var) = alt unify_mut(
expected_mt.mut, actual_mt.mut, variance) { expected_mt.mutbl, actual_mt.mutbl, variance) {
none { ret ures_err(terr_box_mutability); } none { ret ures_err(terr_box_mutability); }
some(mv) { mv } some(mv) { mv }
}; };
@ -1968,7 +1970,7 @@ mod unify {
cx, expected_mt.ty, actual_mt.ty, var); cx, expected_mt.ty, actual_mt.ty, var);
alt result { alt result {
ures_ok(result_sub) { ures_ok(result_sub) {
let mt = {ty: result_sub, mut: mutt}; let mt = {ty: result_sub, mutbl: mutt};
ret ures_ok(mk_box(cx.tcx, mt)); ret ures_ok(mk_box(cx.tcx, mt));
} }
_ { ret result; } _ { ret result; }
@ -1981,7 +1983,7 @@ mod unify {
alt get(actual).struct { alt get(actual).struct {
ty_uniq(actual_mt) { ty_uniq(actual_mt) {
let (mutt, var) = alt unify_mut( let (mutt, var) = alt unify_mut(
expected_mt.mut, actual_mt.mut, variance) { expected_mt.mutbl, actual_mt.mutbl, variance) {
none { ret ures_err(terr_box_mutability); } none { ret ures_err(terr_box_mutability); }
some(mv) { mv } some(mv) { mv }
}; };
@ -1989,7 +1991,7 @@ mod unify {
cx, expected_mt.ty, actual_mt.ty, var); cx, expected_mt.ty, actual_mt.ty, var);
alt result { alt result {
ures_ok(result_mt) { ures_ok(result_mt) {
let mt = {ty: result_mt, mut: mutt}; let mt = {ty: result_mt, mutbl: mutt};
ret ures_ok(mk_uniq(cx.tcx, mt)); ret ures_ok(mk_uniq(cx.tcx, mt));
} }
_ { ret result; } _ { ret result; }
@ -2002,7 +2004,7 @@ mod unify {
alt get(actual).struct { alt get(actual).struct {
ty_vec(actual_mt) { ty_vec(actual_mt) {
let (mutt, var) = alt unify_mut( let (mutt, var) = alt unify_mut(
expected_mt.mut, actual_mt.mut, variance) { expected_mt.mutbl, actual_mt.mutbl, variance) {
none { ret ures_err(terr_vec_mutability); } none { ret ures_err(terr_vec_mutability); }
some(mv) { mv } some(mv) { mv }
}; };
@ -2010,7 +2012,7 @@ mod unify {
cx, expected_mt.ty, actual_mt.ty, var); cx, expected_mt.ty, actual_mt.ty, var);
alt result { alt result {
ures_ok(result_sub) { ures_ok(result_sub) {
let mt = {ty: result_sub, mut: mutt}; let mt = {ty: result_sub, mutbl: mutt};
ret ures_ok(mk_vec(cx.tcx, mt)); ret ures_ok(mk_vec(cx.tcx, mt));
} }
_ { ret result; } _ { ret result; }
@ -2023,7 +2025,7 @@ mod unify {
alt get(actual).struct { alt get(actual).struct {
ty_ptr(actual_mt) { ty_ptr(actual_mt) {
let (mutt, var) = alt unify_mut( let (mutt, var) = alt unify_mut(
expected_mt.mut, actual_mt.mut, variance) { expected_mt.mutbl, actual_mt.mutbl, variance) {
none { ret ures_err(terr_vec_mutability); } none { ret ures_err(terr_vec_mutability); }
some(mv) { mv } some(mv) { mv }
}; };
@ -2031,7 +2033,7 @@ mod unify {
cx, expected_mt.ty, actual_mt.ty, var); cx, expected_mt.ty, actual_mt.ty, var);
alt result { alt result {
ures_ok(result_sub) { ures_ok(result_sub) {
let mt = {ty: result_sub, mut: mutt}; let mt = {ty: result_sub, mutbl: mutt};
ret ures_ok(mk_ptr(cx.tcx, mt)); ret ures_ok(mk_ptr(cx.tcx, mt));
} }
_ { ret result; } _ { ret result; }
@ -2086,9 +2088,10 @@ mod unify {
while i < expected_len { while i < expected_len {
let expected_field = expected_fields[i]; let expected_field = expected_fields[i];
let actual_field = actual_fields[i]; let actual_field = actual_fields[i];
let (mutt, var) = alt unify_mut( let u_mut = unify_mut(expected_field.mt.mutbl,
expected_field.mt.mut, actual_field.mt.mut, variance) actual_field.mt.mutbl,
{ variance);
let (mutt, var) = alt u_mut {
none { ret ures_err(terr_record_mutability); } none { ret ures_err(terr_record_mutability); }
some(mv) { mv } some(mv) { mv }
}; };
@ -2103,7 +2106,7 @@ mod unify {
actual_field.mt.ty, var); actual_field.mt.ty, var);
alt result { alt result {
ures_ok(rty) { ures_ok(rty) {
let mt = {ty: rty, mut: mutt}; let mt = {ty: rty, mutbl: mutt};
result_fields += [{mt: mt with expected_field}]; result_fields += [{mt: mt with expected_field}];
} }
_ { ret result; } _ { ret result; }

View file

@ -115,7 +115,7 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
fcx.ccx.tcx, fcx.ccx.tcx,
{ {
ty: ty::mk_mach_uint(fcx.ccx.tcx, ast::ty_u8), ty: ty::mk_mach_uint(fcx.ccx.tcx, ast::ty_u8),
mut: ast::imm mutbl: ast::m_imm
}) })
}; };
} }
@ -259,7 +259,7 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
tcx.ast_ty_to_ty_cache.insert(ast_ty, none::<ty::t>); tcx.ast_ty_to_ty_cache.insert(ast_ty, none::<ty::t>);
fn ast_mt_to_mt(tcx: ty::ctxt, mode: mode, mt: ast::mt) -> ty::mt { fn ast_mt_to_mt(tcx: ty::ctxt, mode: mode, mt: ast::mt) -> ty::mt {
ret {ty: ast_ty_to_ty(tcx, mode, mt.ty), mut: mt.mut}; ret {ty: ast_ty_to_ty(tcx, mode, mt.ty), mutbl: mt.mutbl};
} }
fn instantiate(tcx: ty::ctxt, sp: span, mode: mode, fn instantiate(tcx: ty::ctxt, sp: span, mode: mode,
id: ast::def_id, args: [@ast::ty]) -> ty::t { id: ast::def_id, args: [@ast::ty]) -> ty::t {
@ -2057,9 +2057,11 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
bot = check_expr(fcx, oper); bot = check_expr(fcx, oper);
let oper_t = expr_ty(tcx, oper); let oper_t = expr_ty(tcx, oper);
alt unop { alt unop {
ast::box(mut) { oper_t = ty::mk_box(tcx, {ty: oper_t, mut: mut}); } ast::box(mutbl) {
ast::uniq(mut) { oper_t = ty::mk_box(tcx, {ty: oper_t, mutbl: mutbl});
oper_t = ty::mk_uniq(tcx, {ty: oper_t, mut: mut}); }
ast::uniq(mutbl) {
oper_t = ty::mk_uniq(tcx, {ty: oper_t, mutbl: mutbl});
} }
ast::deref { ast::deref {
alt structure_of(fcx, expr.span, oper_t) { alt structure_of(fcx, expr.span, oper_t) {
@ -2358,10 +2360,10 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
} }
write_ty(tcx, id, t_1); write_ty(tcx, id, t_1);
} }
ast::expr_vec(args, mut) { ast::expr_vec(args, mutbl) {
let t: ty::t = next_ty_var(fcx); let t: ty::t = next_ty_var(fcx);
for e: @ast::expr in args { bot |= check_expr_with(fcx, e, t); } for e: @ast::expr in args { bot |= check_expr_with(fcx, e, t); }
let typ = ty::mk_vec(tcx, {ty: t, mut: mut}); let typ = ty::mk_vec(tcx, {ty: t, mutbl: mutbl});
write_ty(tcx, id, typ); write_ty(tcx, id, typ);
} }
ast::expr_tup(elts) { ast::expr_tup(elts) {
@ -2381,7 +2383,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
for f: ast::field in fields { for f: ast::field in fields {
bot |= check_expr(fcx, f.node.expr); bot |= check_expr(fcx, f.node.expr);
let expr_t = expr_ty(tcx, f.node.expr); let expr_t = expr_ty(tcx, f.node.expr);
let expr_mt = {ty: expr_t, mut: f.node.mut}; let expr_mt = {ty: expr_t, mutbl: f.node.mutbl};
// for the most precise error message, // for the most precise error message,
// should be f.node.expr.span, not f.span // should be f.node.expr.span, not f.span
fields_t += fields_t +=
@ -2894,7 +2896,7 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) {
fn arg_is_argv_ty(_tcx: ty::ctxt, a: ty::arg) -> bool { fn arg_is_argv_ty(_tcx: ty::ctxt, a: ty::arg) -> bool {
alt ty::get(a.ty).struct { alt ty::get(a.ty).struct {
ty::ty_vec(mt) { ty::ty_vec(mt) {
if mt.mut != ast::imm { ret false; } if mt.mutbl != ast::m_imm { ret false; }
alt ty::get(mt.ty).struct { alt ty::get(mt.ty).struct {
ty::ty_str { ret true; } ty::ty_str { ret true; }
_ { ret false; } _ { ret false; }

View file

@ -34,7 +34,7 @@ mod middle {
mod check_alt; mod check_alt;
mod check_const; mod check_const;
mod lint; mod lint;
mod mut; mod mutbl;
mod alias; mod alias;
mod last_use; mod last_use;
mod block_use; mod block_use;

View file

@ -121,7 +121,7 @@ enum pat_ {
pat_range(@expr, @expr), pat_range(@expr, @expr),
} }
enum mutability { mut, imm, maybe_mut, } enum mutability { m_mutbl, m_imm, m_const, }
enum proto { enum proto {
proto_bare, // native fn proto_bare, // native fn
@ -173,7 +173,7 @@ enum inferable<T> {
} }
// "resolved" mode: the real modes. // "resolved" mode: the real modes.
enum rmode { by_ref, by_val, by_mut_ref, by_move, by_copy } enum rmode { by_ref, by_val, by_mutbl_ref, by_move, by_copy }
// inferable mode. // inferable mode.
type mode = inferable<rmode>; type mode = inferable<rmode>;
@ -205,7 +205,7 @@ enum decl_ { decl_local([@local]), decl_item(@item), }
type arm = {pats: [@pat], guard: option<@expr>, body: blk}; type arm = {pats: [@pat], guard: option<@expr>, body: blk};
type field_ = {mut: mutability, ident: ident, expr: @expr}; type field_ = {mutbl: mutability, ident: ident, expr: @expr};
type field = spanned<field_>; type field = spanned<field_>;
@ -316,7 +316,7 @@ enum lit_ {
// NB: If you change this, you'll probably want to change the corresponding // NB: If you change this, you'll probably want to change the corresponding
// type structure in middle/ty.rs as well. // type structure in middle/ty.rs as well.
type mt = {ty: @ty, mut: mutability}; type mt = {ty: @ty, mutbl: mutability};
type ty_field_ = {ident: ident, mt: mt}; type ty_field_ = {ident: ident, mt: mt};

View file

@ -66,8 +66,8 @@ pure fn lazy_binop(b: binop) -> bool {
fn unop_to_str(op: unop) -> str { fn unop_to_str(op: unop) -> str {
alt op { alt op {
box(mt) { if mt == mut { ret "@mutable "; } ret "@"; } box(mt) { if mt == m_mutbl { ret "@mut "; } ret "@"; }
uniq(mt) { if mt == mut { ret "~mutable "; } ret "~"; } uniq(mt) { if mt == m_mutbl { ret "~mut "; } ret "~"; }
deref { ret "*"; } deref { ret "*"; }
not { ret "!"; } not { ret "!"; }
neg { ret "-"; } neg { ret "-"; }

View file

@ -61,7 +61,7 @@ fn mk_call(cx: ext_ctxt, sp: span, fn_path: [ast::ident],
// e = expr, t = type // e = expr, t = type
fn mk_vec_e(cx: ext_ctxt, sp: span, exprs: [@ast::expr]) -> fn mk_vec_e(cx: ext_ctxt, sp: span, exprs: [@ast::expr]) ->
@ast::expr { @ast::expr {
let vecexpr = ast::expr_vec(exprs, ast::imm); let vecexpr = ast::expr_vec(exprs, ast::m_imm);
ret @{id: cx.next_id(), node: vecexpr, span: sp}; ret @{id: cx.next_id(), node: vecexpr, span: sp};
} }
fn mk_rec_e(cx: ext_ctxt, sp: span, fn mk_rec_e(cx: ext_ctxt, sp: span,
@ -72,7 +72,7 @@ fn mk_rec_e(cx: ext_ctxt, sp: span,
let ident = field.ident; let ident = field.ident;
let val = field.ex; let val = field.ex;
let astfield = let astfield =
{node: {mut: ast::imm, ident: ident, expr: val}, span: sp}; {node: {mutbl: ast::m_imm, ident: ident, expr: val}, span: sp};
astfields += [astfield]; astfields += [astfield];
} }
let recexpr = ast::expr_rec(astfields, option::none::<@ast::expr>); let recexpr = ast::expr_rec(astfields, option::none::<@ast::expr>);

View file

@ -231,7 +231,7 @@ fn finish<T: qq_helper>
[mk_str(cx,sp, loc.file.name), [mk_str(cx,sp, loc.file.name),
mk_uint(cx,sp, loc.line), mk_uint(cx,sp, loc.line),
mk_uint(cx,sp, loc.col)]), mk_uint(cx,sp, loc.col)]),
mk_unary(cx,sp, ast::box(ast::imm), mk_unary(cx,sp, ast::box(ast::m_imm),
mk_str(cx,sp, str2)), mk_str(cx,sp, str2)),
mk_access_(cx,sp, mk_access_(cx,sp,
mk_access_(cx,sp, session_call(), "opts"), mk_access_(cx,sp, session_call(), "opts"),

View file

@ -682,7 +682,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
let clauses: [@clause] = []; let clauses: [@clause] = [];
for arg: @expr in args { for arg: @expr in args {
alt arg.node { alt arg.node {
expr_vec(elts, mut) { expr_vec(elts, mutbl) {
if vec::len(elts) != 2u { if vec::len(elts) != 2u {
cx.span_fatal((*arg).span, cx.span_fatal((*arg).span,
"extension clause must consist of [" + "extension clause must consist of [" +

View file

@ -337,7 +337,7 @@ fn wrap<T>(f: fn@(T, ast_fold) -> T)
fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ { fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
fn fold_field_(field: field, fld: ast_fold) -> field { fn fold_field_(field: field, fld: ast_fold) -> field {
ret {node: ret {node:
{mut: field.node.mut, {mutbl: field.node.mutbl,
ident: fld.fold_ident(field.node.ident), ident: fld.fold_ident(field.node.ident),
expr: fld.fold_expr(field.node.expr)}, expr: fld.fold_expr(field.node.expr)},
span: field.span}; span: field.span};
@ -434,7 +434,7 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ { fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ {
let fold_mac = bind fold_mac_(_, fld); let fold_mac = bind fold_mac_(_, fld);
fn fold_mt(mt: mt, fld: ast_fold) -> mt { fn fold_mt(mt: mt, fld: ast_fold) -> mt {
{ty: fld.fold_ty(mt.ty), mut: mt.mut} {ty: fld.fold_ty(mt.ty), mutbl: mt.mutbl}
} }
fn fold_field(f: ty_field, fld: ast_fold) -> ty_field { fn fold_field(f: ty_field, fld: ast_fold) -> ty_field {
{node: {ident: fld.fold_ident(f.node.ident), {node: {ident: fld.fold_ident(f.node.ident),

View file

@ -150,7 +150,7 @@ fn bad_expr_word_table() -> hashmap<str, ()> {
"export", "fail", "fn", "for", "if", "iface", "impl", "export", "fail", "fn", "for", "if", "iface", "impl",
"import", "let", "log", "mod", "mutable", "native", "pure", "import", "let", "log", "mod", "mutable", "native", "pure",
"resource", "ret", "trait", "type", "unchecked", "unsafe", "resource", "ret", "trait", "type", "unchecked", "unsafe",
"while, crust"] { "while", "crust", "mut"] {
words.insert(word, ()); words.insert(word, ());
} }
words words
@ -293,18 +293,18 @@ fn parse_ty_methods(p: parser) -> [ast::ty_method] {
} }
fn parse_mt(p: parser) -> ast::mt { fn parse_mt(p: parser) -> ast::mt {
let mut = parse_mutability(p); let mutbl = parse_mutability(p);
let t = parse_ty(p, false); let t = parse_ty(p, false);
ret {ty: t, mut: mut}; ret {ty: t, mutbl: mutbl};
} }
fn parse_ty_field(p: parser) -> ast::ty_field { fn parse_ty_field(p: parser) -> ast::ty_field {
let lo = p.span.lo; let lo = p.span.lo;
let mut = parse_mutability(p); let mutbl = parse_mutability(p);
let id = parse_ident(p); let id = parse_ident(p);
expect(p, token::COLON); expect(p, token::COLON);
let ty = parse_ty(p, false); let ty = parse_ty(p, false);
ret spanned(lo, ty.span.hi, {ident: id, mt: {ty: ty, mut: mut}}); ret spanned(lo, ty.span.hi, {ident: id, mt: {ty: ty, mutbl: mutbl}});
} }
// if i is the jth ident in args, return j // if i is the jth ident in args, return j
@ -486,7 +486,7 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty {
fn parse_arg_mode(p: parser) -> ast::mode { fn parse_arg_mode(p: parser) -> ast::mode {
if eat(p, token::BINOP(token::AND)) { if eat(p, token::BINOP(token::AND)) {
ast::expl(ast::by_mut_ref) ast::expl(ast::by_mutbl_ref)
} else if eat(p, token::BINOP(token::MINUS)) { } else if eat(p, token::BINOP(token::MINUS)) {
ast::expl(ast::by_move) ast::expl(ast::by_move)
} else if eat(p, token::ANDAND) { } else if eat(p, token::ANDAND) {
@ -693,11 +693,13 @@ fn parse_path_and_ty_param_substs(p: parser, colons: bool) -> @ast::path {
fn parse_mutability(p: parser) -> ast::mutability { fn parse_mutability(p: parser) -> ast::mutability {
if eat_word(p, "mutable") { if eat_word(p, "mutable") {
ast::mut ast::m_mutbl
} else if eat_word(p, "mut") {
ast::m_mutbl
} else if eat_word(p, "const") { } else if eat_word(p, "const") {
ast::maybe_mut ast::m_const
} else { } else {
ast::imm ast::m_imm
} }
} }
@ -707,7 +709,7 @@ fn parse_field(p: parser, sep: token::token) -> ast::field {
let i = parse_ident(p); let i = parse_ident(p);
expect(p, sep); expect(p, sep);
let e = parse_expr(p); let e = parse_expr(p);
ret spanned(lo, e.span.hi, {mut: m, ident: i, expr: e}); ret spanned(lo, e.span.hi, {mutbl: m, ident: i, expr: e});
} }
fn mk_expr(p: parser, lo: uint, hi: uint, node: ast::expr_) -> @ast::expr { fn mk_expr(p: parser, lo: uint, hi: uint, node: ast::expr_) -> @ast::expr {
@ -786,7 +788,7 @@ fn parse_bottom_expr(p: parser) -> pexpr {
ret mk_pexpr(p, lo, hi, ast::expr_tup(es)); ret mk_pexpr(p, lo, hi, ast::expr_tup(es));
} else if p.token == token::LBRACE { } else if p.token == token::LBRACE {
p.bump(); p.bump();
if is_word(p, "mutable") || if is_word(p, "mut") || is_word(p, "mutable") ||
is_plain_ident(p) && p.look_ahead(1u) == token::COLON { is_plain_ident(p) && p.look_ahead(1u) == token::COLON {
let fields = [parse_field(p, token::COLON)]; let fields = [parse_field(p, token::COLON)];
let base = none; let base = none;
@ -832,11 +834,11 @@ fn parse_bottom_expr(p: parser) -> pexpr {
ret pexpr(parse_block_expr(p, lo, ast::unsafe_blk)); ret pexpr(parse_block_expr(p, lo, ast::unsafe_blk));
} else if p.token == token::LBRACKET { } else if p.token == token::LBRACKET {
p.bump(); p.bump();
let mut = parse_mutability(p); let mutbl = parse_mutability(p);
let es = let es =
parse_seq_to_end(token::RBRACKET, seq_sep(token::COMMA), parse_seq_to_end(token::RBRACKET, seq_sep(token::COMMA),
parse_expr, p); parse_expr, p);
ex = ast::expr_vec(es, mut); ex = ast::expr_vec(es, mutbl);
} else if p.token == token::POUND_LT { } else if p.token == token::POUND_LT {
p.bump(); p.bump();
let ty = parse_ty(p, false); let ty = parse_ty(p, false);
@ -971,7 +973,7 @@ fn parse_syntax_ext_naked(p: parser, lo: uint) -> @ast::expr {
}; };
let hi = es.span.hi; let hi = es.span.hi;
e = some(mk_expr(p, es.span.lo, hi, e = some(mk_expr(p, es.span.lo, hi,
ast::expr_vec(es.node, ast::imm))); ast::expr_vec(es.node, ast::m_imm)));
} }
let b = none; let b = none;
if p.token == token::LBRACE { if p.token == token::LBRACE {
@ -1578,6 +1580,9 @@ fn parse_local(p: parser, allow_init: bool) -> @ast::local {
} }
fn parse_let(p: parser) -> @ast::decl { fn parse_let(p: parser) -> @ast::decl {
if eat_word(p, "mut") {
/* TODO */
}
let lo = p.span.lo; let lo = p.span.lo;
let locals = [parse_local(p, true)]; let locals = [parse_local(p, true)];
while eat(p, token::COMMA) { while eat(p, token::COMMA) {
@ -1587,10 +1592,10 @@ fn parse_let(p: parser) -> @ast::decl {
} }
fn parse_instance_var(p:parser) -> ast::class_member { fn parse_instance_var(p:parser) -> ast::class_member {
let is_mut = ast::class_immutable; let is_mutbl = ast::class_immutable;
expect_word(p, "let"); expect_word(p, "let");
if eat_word(p, "mutable") { if eat_word(p, "mut") || eat_word(p, "mutable") {
is_mut = ast::class_mutable; is_mutbl = ast::class_mutable;
} }
if !is_plain_ident(p) { if !is_plain_ident(p) {
p.fatal("expecting ident"); p.fatal("expecting ident");
@ -1598,7 +1603,7 @@ fn parse_instance_var(p:parser) -> ast::class_member {
let name = parse_ident(p); let name = parse_ident(p);
expect(p, token::COLON); expect(p, token::COLON);
let ty = parse_ty(p, false); let ty = parse_ty(p, false);
ret ast::instance_var(name, ty, is_mut, p.get_id()); ret ast::instance_var(name, ty, is_mutbl, p.get_id());
} }
fn parse_stmt(p: parser, first_item_attrs: [ast::attribute]) -> @ast::stmt { fn parse_stmt(p: parser, first_item_attrs: [ast::attribute]) -> @ast::stmt {

View file

@ -318,10 +318,10 @@ fn print_type(s: ps, &&ty: @ast::ty) {
ast::ty_uniq(mt) { word(s.s, "~"); print_mt(s, mt); } ast::ty_uniq(mt) { word(s.s, "~"); print_mt(s, mt); }
ast::ty_vec(mt) { ast::ty_vec(mt) {
word(s.s, "["); word(s.s, "[");
alt mt.mut { alt mt.mutbl {
ast::mut { word_space(s, "mutable"); } ast::m_mutbl { word_space(s, "mut"); }
ast::maybe_mut { word_space(s, "const"); } ast::m_const { word_space(s, "const"); }
ast::imm { } ast::m_imm { }
} }
print_type(s, mt.ty); print_type(s, mt.ty);
word(s.s, "]"); word(s.s, "]");
@ -331,7 +331,7 @@ fn print_type(s: ps, &&ty: @ast::ty) {
word(s.s, "{"); word(s.s, "{");
fn print_field(s: ps, f: ast::ty_field) { fn print_field(s: ps, f: ast::ty_field) {
cbox(s, indent_unit); cbox(s, indent_unit);
print_mutability(s, f.node.mt.mut); print_mutability(s, f.node.mt.mutbl);
word(s.s, f.node.ident); word(s.s, f.node.ident);
word_space(s, ":"); word_space(s, ":");
print_type(s, f.node.mt.ty); print_type(s, f.node.mt.ty);
@ -785,10 +785,10 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
let ann_node = node_expr(s, expr); let ann_node = node_expr(s, expr);
s.ann.pre(ann_node); s.ann.pre(ann_node);
alt expr.node { alt expr.node {
ast::expr_vec(exprs, mut) { ast::expr_vec(exprs, mutbl) {
ibox(s, indent_unit); ibox(s, indent_unit);
word(s.s, "["); word(s.s, "[");
if mut == ast::mut { if mutbl == ast::m_mutbl {
word(s.s, "mutable"); word(s.s, "mutable");
if vec::len(exprs) > 0u { nbsp(s); } if vec::len(exprs) > 0u { nbsp(s); }
} }
@ -799,7 +799,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
ast::expr_rec(fields, wth) { ast::expr_rec(fields, wth) {
fn print_field(s: ps, field: ast::field) { fn print_field(s: ps, field: ast::field) {
ibox(s, indent_unit); ibox(s, indent_unit);
if field.node.mut == ast::mut { word_nbsp(s, "mutable"); } if field.node.mutbl == ast::m_mutbl { word_nbsp(s, "mutable"); }
word(s.s, field.node.ident); word(s.s, field.node.ident);
word_space(s, ":"); word_space(s, ":");
print_expr(s, field.node.expr); print_expr(s, field.node.expr);
@ -1274,7 +1274,7 @@ fn print_fn_block_args(s: ps, decl: ast::fn_decl) {
fn mode_to_str(m: ast::mode) -> str { fn mode_to_str(m: ast::mode) -> str {
alt m { alt m {
ast::expl(ast::by_mut_ref) { "&" } ast::expl(ast::by_mutbl_ref) { "&" }
ast::expl(ast::by_move) { "-" } ast::expl(ast::by_move) { "-" }
ast::expl(ast::by_ref) { "&&" } ast::expl(ast::by_ref) { "&&" }
ast::expl(ast::by_val) { "++" } ast::expl(ast::by_val) { "++" }
@ -1436,16 +1436,16 @@ fn print_op_maybe_parens(s: ps, expr: @ast::expr, outer_prec: int) {
if add_them { pclose(s); } if add_them { pclose(s); }
} }
fn print_mutability(s: ps, mut: ast::mutability) { fn print_mutability(s: ps, mutbl: ast::mutability) {
alt mut { alt mutbl {
ast::mut { word_nbsp(s, "mutable"); } ast::m_mutbl { word_nbsp(s, "mutable"); }
ast::maybe_mut { word_nbsp(s, "const"); } ast::m_const { word_nbsp(s, "const"); }
ast::imm {/* nothing */ } ast::m_imm {/* nothing */ }
} }
} }
fn print_mt(s: ps, mt: ast::mt) { fn print_mt(s: ps, mt: ast::mt) {
print_mutability(s, mt.mut); print_mutability(s, mt.mutbl);
print_type(s, mt.ty); print_type(s, mt.ty);
} }

View file

@ -53,12 +53,11 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
ret f.ident + ": " + mt_to_str(cx, f.mt); ret f.ident + ": " + mt_to_str(cx, f.mt);
} }
fn mt_to_str(cx: ctxt, m: mt) -> str { fn mt_to_str(cx: ctxt, m: mt) -> str {
let mstr; let mstr = alt m.mutbl {
alt m.mut { ast::m_mutbl { "mut " }
ast::mut { mstr = "mutable "; } ast::m_imm { "" }
ast::imm { mstr = ""; } ast::m_const { "const " }
ast::maybe_mut { mstr = "const "; } };
}
ret mstr + ty_to_str(cx, m.ty); ret mstr + ty_to_str(cx, m.ty);
} }
fn parameterized(cx: ctxt, base: str, tps: [ty::t]) -> str { fn parameterized(cx: ctxt, base: str, tps: [ty::t]) -> str {

View file

@ -50,8 +50,10 @@ fn common_exprs() -> [ast::expr] {
dse(ast::expr_lit(@dsl(ast::lit_nil))), dse(ast::expr_lit(@dsl(ast::lit_nil))),
dse(ast::expr_lit(@dsl(ast::lit_bool(false)))), dse(ast::expr_lit(@dsl(ast::lit_bool(false)))),
dse(ast::expr_lit(@dsl(ast::lit_bool(true)))), dse(ast::expr_lit(@dsl(ast::lit_bool(true)))),
dse(ast::expr_unary(ast::box(ast::imm), @dse(ast::expr_lit(@dsl(ast::lit_bool(true)))))), dse(ast::expr_unary(ast::box(ast::m_imm),
dse(ast::expr_unary(ast::uniq(ast::imm), @dse(ast::expr_lit(@dsl(ast::lit_bool(true)))))) @dse(ast::expr_lit(@dsl(ast::lit_bool(true)))))),
dse(ast::expr_unary(ast::uniq(ast::m_imm),
@dse(ast::expr_lit(@dsl(ast::lit_bool(true))))))
] ]
} }