Skip to content

Commit bfff2a8

Browse files
committed
make mut a keyword synonymous with mutable
first step towards issue #1273
1 parent dddd990 commit bfff2a8

29 files changed

+224
-206
lines changed

src/comp/driver/driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
159159
bind middle::tstate::ck::check_crate(ty_cx, crate));
160160
let mut_map =
161161
time(time_passes, "mutability checking",
162-
bind middle::mut::check_crate(ty_cx, crate));
162+
bind middle::mutbl::check_crate(ty_cx, crate));
163163
let (copy_map, ref_map) =
164164
time(time_passes, "alias checking",
165165
bind middle::alias::check_crate(ty_cx, crate));

src/comp/front/test.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::ty {
256256
let test_desc_ty: ast::ty =
257257
nospan(ast::ty_path(test_desc_ty_path, cx.sess.next_node_id()));
258258

259-
let vec_mt: ast::mt = {ty: @test_desc_ty, mut: ast::imm};
259+
let vec_mt: ast::mt = {ty: @test_desc_ty, mutbl: ast::m_imm};
260260

261261
ret @nospan(ast::ty_vec(vec_mt));
262262
}
@@ -270,7 +270,7 @@ fn mk_test_desc_vec(cx: test_ctxt) -> @ast::expr {
270270
}
271271

272272
ret @{id: cx.sess.next_node_id(),
273-
node: ast::expr_vec(descs, ast::imm),
273+
node: ast::expr_vec(descs, ast::m_imm),
274274
span: dummy_sp()};
275275
}
276276

@@ -288,7 +288,7 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
288288
span: span};
289289

290290
let name_field: ast::field =
291-
nospan({mut: ast::imm, ident: "name", expr: @name_expr});
291+
nospan({mutbl: ast::m_imm, ident: "name", expr: @name_expr});
292292

293293
let fn_path = @nospan({global: false, idents: path, types: []});
294294

@@ -300,7 +300,7 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
300300
let fn_wrapper_expr = mk_test_wrapper(cx, fn_expr, span);
301301

302302
let fn_field: ast::field =
303-
nospan({mut: ast::imm, ident: "fn", expr: fn_wrapper_expr});
303+
nospan({mutbl: ast::m_imm, ident: "fn", expr: fn_wrapper_expr});
304304

305305
let ignore_lit: ast::lit = nospan(ast::lit_bool(test.ignore));
306306

@@ -310,7 +310,7 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
310310
span: span};
311311

312312
let ignore_field: ast::field =
313-
nospan({mut: ast::imm, ident: "ignore", expr: @ignore_expr});
313+
nospan({mutbl: ast::m_imm, ident: "ignore", expr: @ignore_expr});
314314

315315
let fail_lit: ast::lit = nospan(ast::lit_bool(test.should_fail));
316316

@@ -320,7 +320,7 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
320320
span: span};
321321

322322
let fail_field: ast::field =
323-
nospan({mut: ast::imm, ident: "should_fail", expr: @fail_expr});
323+
nospan({mutbl: ast::m_imm, ident: "should_fail", expr: @fail_expr});
324324

325325
let desc_rec_: ast::expr_ =
326326
ast::expr_rec([name_field, fn_field, ignore_field, fail_field],
@@ -378,7 +378,7 @@ fn mk_test_wrapper(cx: test_ctxt,
378378
fn mk_main(cx: test_ctxt) -> @ast::item {
379379
let str_pt = @nospan({global: false, idents: ["str"], types: []});
380380
let str_ty = @nospan(ast::ty_path(str_pt, cx.sess.next_node_id()));
381-
let args_mt: ast::mt = {ty: str_ty, mut: ast::imm};
381+
let args_mt: ast::mt = {ty: str_ty, mutbl: ast::m_imm};
382382
let args_ty: ast::ty = nospan(ast::ty_vec(args_mt));
383383

384384
let args_arg: ast::arg =

src/comp/metadata/astencode.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,28 +483,28 @@ impl ast_output for ast_ctxt {
483483
self.tag(at_ty_bot) {||}
484484
}
485485

486-
ty_box({ty: ty, mut: m}) {
486+
ty_box({ty: ty, mutbl: m}) {
487487
self.tag(at_ty_box) {||
488488
self.ty(ty);
489489
self.mutbl(m);
490490
}
491491
}
492492

493-
ty_uniq({ty: ty, mut: m}) {
493+
ty_uniq({ty: ty, mutbl: m}) {
494494
self.tag(at_ty_uniq) {||
495495
self.ty(ty);
496496
self.mutbl(m);
497497
}
498498
}
499499

500-
ty_vec({ty: ty, mut: m}) {
500+
ty_vec({ty: ty, mutbl: m}) {
501501
self.tag(at_ty_vec) {||
502502
self.ty(ty);
503503
self.mutbl(m);
504504
}
505505
}
506506

507-
ty_ptr({ty: ty, mut: m}) {
507+
ty_ptr({ty: ty, mutbl: m}) {
508508
self.tag(at_ty_ptr) {||
509509
self.ty(ty);
510510
self.mutbl(m);

src/comp/metadata/tydecode.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,11 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
311311
fn parse_mt(st: @pstate, conv: conv_did) -> ty::mt {
312312
let m;
313313
alt peek(st) {
314-
'm' { next(st); m = ast::mut; }
315-
'?' { next(st); m = ast::maybe_mut; }
316-
_ { m = ast::imm; }
314+
'm' { next(st); m = ast::m_mutbl; }
315+
'?' { next(st); m = ast::m_const; }
316+
_ { m = ast::m_imm; }
317317
}
318-
ret {ty: parse_ty(st, conv), mut: m};
318+
ret {ty: parse_ty(st, conv), mutbl: m};
319319
}
320320

321321
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 {
356356
let inputs: [ty::arg] = [];
357357
while peek(st) != ']' {
358358
let mode = alt check peek(st) {
359-
'&' { ast::by_mut_ref }
359+
'&' { ast::by_mutbl_ref }
360360
'-' { ast::by_move }
361361
'+' { ast::by_copy }
362362
'=' { ast::by_ref }

src/comp/metadata/tyencode.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ fn enc_ty(w: io::writer, cx: @ctxt, t: ty::t) {
8585
}
8686
}
8787
fn enc_mt(w: io::writer, cx: @ctxt, mt: ty::mt) {
88-
alt mt.mut {
89-
imm { }
90-
mut { w.write_char('m'); }
91-
maybe_mut { w.write_char('?'); }
88+
alt mt.mutbl {
89+
m_imm { }
90+
m_mutbl { w.write_char('m'); }
91+
m_const { w.write_char('?'); }
9292
}
9393
enc_ty(w, cx, mt.ty);
9494
}
@@ -215,7 +215,7 @@ fn enc_ty_fn(w: io::writer, cx: @ctxt, ft: ty::fn_ty) {
215215
w.write_char('[');
216216
for arg: ty::arg in ft.inputs {
217217
alt ty::resolved_mode(cx.tcx, arg.mode) {
218-
by_mut_ref { w.write_char('&'); }
218+
by_mutbl_ref { w.write_char('&'); }
219219
by_move { w.write_char('-'); }
220220
by_copy { w.write_char('+'); }
221221
by_ref { w.write_char('='); }

src/comp/middle/alias.rs

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type invalid = {reason: invalid_reason,
2222
node_id: node_id,
2323
sp: span, path: @ast::path};
2424

25-
enum unsafe_ty { contains(ty::t), mut_contains(ty::t), }
25+
enum unsafe_ty { contains(ty::t), mutbl_contains(ty::t), }
2626

2727
type binding = @{node_id: node_id,
2828
span: span,
@@ -183,9 +183,9 @@ fn add_bindings_for_let(cx: ctx, &bs: [binding], loc: @ast::local) {
183183
err(cx, loc.span, "a reference binding can't be \
184184
rooted in a temporary");
185185
}
186-
for proot in pattern_roots(cx.tcx, root.mut, loc.node.pat) {
186+
for proot in pattern_roots(cx.tcx, root.mutbl, loc.node.pat) {
187187
let bnd = mk_binding(cx, proot.id, proot.span, root_var,
188-
unsafe_set(proot.mut));
188+
unsafe_set(proot.mutbl));
189189
// Don't implicitly copy explicit references
190190
bnd.copied = not_allowed;
191191
bs += [bnd];
@@ -228,7 +228,7 @@ fn check_call(cx: ctx, sc: scope, f: @ast::expr, args: [@ast::expr])
228228
let arg = args[i];
229229
let root = expr_root(cx, arg, false);
230230
alt ty::resolved_mode(cx.tcx, arg_t.mode) {
231-
ast::by_mut_ref {
231+
ast::by_mutbl_ref {
232232
alt path_def(cx, arg) {
233233
some(def) {
234234
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])
242242
let root_var = path_def_id(cx, root.ex);
243243
let arg_copied = alt ty::resolved_mode(cx.tcx, arg_t.mode) {
244244
ast::by_move | ast::by_copy { copied }
245-
ast::by_mut_ref { not_allowed }
245+
ast::by_mutbl_ref { not_allowed }
246246
ast::by_ref | ast::by_val { not_copied }
247247
};
248248
bindings += [@{node_id: arg.id,
249249
span: arg.span,
250250
root_var: root_var,
251251
local_id: 0u,
252-
unsafe_tys: unsafe_set(root.mut),
252+
unsafe_tys: unsafe_set(root.mutbl),
253253
mutable copied: arg_copied}];
254254
i += 1u;
255255
}
@@ -285,7 +285,7 @@ fn check_call(cx: ctx, sc: scope, f: @ast::expr, args: [@ast::expr])
285285
let i = 0u;
286286
for arg_t: ty::arg in arg_ts {
287287
let mut_alias =
288-
(ast::by_mut_ref == ty::arg_mode(cx.tcx, arg_t));
288+
(ast::by_mutbl_ref == ty::arg_mode(cx.tcx, arg_t));
289289
if i != j &&
290290
ty_can_unsafely_include(cx, unsafe_ty, arg_t.ty,
291291
mut_alias) &&
@@ -339,14 +339,14 @@ fn check_alt(cx: ctx, input: @ast::expr, arms: [ast::arm], sc: scope,
339339
span: span};
340340
let binding_info: [info] = [];
341341
for pat in a.pats {
342-
for proot in pattern_roots(cx.tcx, root.mut, pat) {
342+
for proot in pattern_roots(cx.tcx, root.mutbl, pat) {
343343
let canon_id = pat_id_map.get(proot.name);
344344
alt vec::find(binding_info, {|x| x.id == canon_id}) {
345-
some(s) { s.unsafe_tys += unsafe_set(proot.mut); }
345+
some(s) { s.unsafe_tys += unsafe_set(proot.mutbl); }
346346
none {
347347
binding_info += [
348348
{id: canon_id,
349-
mutable unsafe_tys: unsafe_set(proot.mut),
349+
mutable unsafe_tys: unsafe_set(proot.mutbl),
350350
span: proot.span}];
351351
}
352352
}
@@ -369,20 +369,20 @@ fn check_for(cx: ctx, local: @ast::local, seq: @ast::expr, blk: ast::blk,
369369

370370
// If this is a mutable vector, don't allow it to be touched.
371371
let seq_t = ty::expr_ty(cx.tcx, seq);
372-
let cur_mut = root.mut;
372+
let cur_mutbl = root.mutbl;
373373
alt ty::get(seq_t).struct {
374374
ty::ty_vec(mt) {
375-
if mt.mut != ast::imm {
376-
cur_mut = some(contains(seq_t));
375+
if mt.mutbl != ast::m_imm {
376+
cur_mutbl = some(contains(seq_t));
377377
}
378378
}
379379
_ {}
380380
}
381381
let root_var = path_def_id(cx, root.ex);
382382
let new_bs = sc.bs;
383-
for proot in pattern_roots(cx.tcx, cur_mut, local.node.pat) {
383+
for proot in pattern_roots(cx.tcx, cur_mutbl, local.node.pat) {
384384
new_bs += [mk_binding(cx, proot.id, proot.span, root_var,
385-
unsafe_set(proot.mut))];
385+
unsafe_set(proot.mutbl))];
386386
}
387387
visit::visit_block(blk, {bs: new_bs with sc}, v);
388388
}
@@ -493,36 +493,36 @@ fn path_def_id(cx: ctx, ex: @ast::expr) -> option<ast::node_id> {
493493
}
494494

495495
fn ty_can_unsafely_include(cx: ctx, needle: unsafe_ty, haystack: ty::t,
496-
mut: bool) -> bool {
497-
fn get_mut(cur: bool, mt: ty::mt) -> bool {
498-
ret cur || mt.mut != ast::imm;
496+
mutbl: bool) -> bool {
497+
fn get_mutbl(cur: bool, mt: ty::mt) -> bool {
498+
ret cur || mt.mutbl != ast::m_imm;
499499
}
500-
fn helper(tcx: ty::ctxt, needle: unsafe_ty, haystack: ty::t, mut: bool)
500+
fn helper(tcx: ty::ctxt, needle: unsafe_ty, haystack: ty::t, mutbl: bool)
501501
-> bool {
502502
if alt needle {
503503
contains(ty) { ty == haystack }
504-
mut_contains(ty) { mut && ty == haystack }
504+
mutbl_contains(ty) { mutbl && ty == haystack }
505505
} { ret true; }
506506
alt ty::get(haystack).struct {
507507
ty::ty_enum(_, ts) {
508508
for t: ty::t in ts {
509-
if helper(tcx, needle, t, mut) { ret true; }
509+
if helper(tcx, needle, t, mutbl) { ret true; }
510510
}
511511
ret false;
512512
}
513513
ty::ty_box(mt) | ty::ty_ptr(mt) | ty::ty_uniq(mt) {
514-
ret helper(tcx, needle, mt.ty, get_mut(mut, mt));
514+
ret helper(tcx, needle, mt.ty, get_mutbl(mutbl, mt));
515515
}
516516
ty::ty_rec(fields) {
517517
for f: ty::field in fields {
518-
if helper(tcx, needle, f.mt.ty, get_mut(mut, f.mt)) {
518+
if helper(tcx, needle, f.mt.ty, get_mutbl(mutbl, f.mt)) {
519519
ret true;
520520
}
521521
}
522522
ret false;
523523
}
524524
ty::ty_tup(ts) {
525-
for t in ts { if helper(tcx, needle, t, mut) { ret true; } }
525+
for t in ts { if helper(tcx, needle, t, mutbl) { ret true; } }
526526
ret false;
527527
}
528528
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,
532532
// treated as opaque downstream, and is thus safe unless we
533533
// saw mutable fields, in which case the whole thing can be
534534
// overwritten.
535-
ty::ty_param(_, _) { ret mut; }
535+
ty::ty_param(_, _) { ret mutbl; }
536536
_ { ret false; }
537537
}
538538
}
539-
ret helper(cx.tcx, needle, haystack, mut);
539+
ret helper(cx.tcx, needle, haystack, mutbl);
540540
}
541541

542542
fn def_is_local(d: ast::def) -> bool {
@@ -589,66 +589,66 @@ fn copy_is_expensive(tcx: ty::ctxt, ty: ty::t) -> bool {
589589

590590
type pattern_root = {id: node_id,
591591
name: ident,
592-
mut: option<unsafe_ty>,
592+
mutbl: option<unsafe_ty>,
593593
span: span};
594594

595-
fn pattern_roots(tcx: ty::ctxt, mut: option<unsafe_ty>, pat: @ast::pat)
595+
fn pattern_roots(tcx: ty::ctxt, mutbl: option<unsafe_ty>, pat: @ast::pat)
596596
-> [pattern_root] {
597-
fn walk(tcx: ty::ctxt, mut: option<unsafe_ty>, pat: @ast::pat,
597+
fn walk(tcx: ty::ctxt, mutbl: option<unsafe_ty>, pat: @ast::pat,
598598
&set: [pattern_root]) {
599599
alt normalize_pat(tcx, pat).node {
600600
ast::pat_wild | ast::pat_lit(_) | ast::pat_range(_, _) {}
601601
ast::pat_ident(nm, sub) {
602-
set += [{id: pat.id, name: path_to_ident(nm), mut: mut,
602+
set += [{id: pat.id, name: path_to_ident(nm), mutbl: mutbl,
603603
span: pat.span}];
604-
alt sub { some(p) { walk(tcx, mut, p, set); } _ {} }
604+
alt sub { some(p) { walk(tcx, mutbl, p, set); } _ {} }
605605
}
606606
ast::pat_enum(_, ps) | ast::pat_tup(ps) {
607-
for p in ps { walk(tcx, mut, p, set); }
607+
for p in ps { walk(tcx, mutbl, p, set); }
608608
}
609609
ast::pat_rec(fs, _) {
610610
let ty = ty::node_id_to_type(tcx, pat.id);
611611
for f in fs {
612-
let m = ty::get_field(ty, f.ident).mt.mut != ast::imm,
613-
c = if m { some(contains(ty)) } else { mut };
612+
let m = ty::get_field(ty, f.ident).mt.mutbl != ast::m_imm,
613+
c = if m { some(contains(ty)) } else { mutbl };
614614
walk(tcx, c, f.pat, set);
615615
}
616616
}
617617
ast::pat_box(p) {
618618
let ty = ty::node_id_to_type(tcx, pat.id);
619619
let m = alt ty::get(ty).struct {
620-
ty::ty_box(mt) { mt.mut != ast::imm }
620+
ty::ty_box(mt) { mt.mutbl != ast::m_imm }
621621
_ { tcx.sess.span_bug(pat.span, "box pat has non-box type"); }
622622
},
623-
c = if m {some(contains(ty)) } else { mut };
623+
c = if m {some(contains(ty)) } else { mutbl };
624624
walk(tcx, c, p, set);
625625
}
626626
ast::pat_uniq(p) {
627627
let ty = ty::node_id_to_type(tcx, pat.id);
628628
let m = alt ty::get(ty).struct {
629-
ty::ty_uniq(mt) { mt.mut != ast::imm }
629+
ty::ty_uniq(mt) { mt.mutbl != ast::m_imm }
630630
_ { tcx.sess.span_bug(pat.span, "uniq pat has non-uniq type"); }
631631
},
632-
c = if m { some(contains(ty)) } else { mut };
632+
c = if m { some(contains(ty)) } else { mutbl };
633633
walk(tcx, c, p, set);
634634
}
635635
}
636636
}
637637
let set = [];
638-
walk(tcx, mut, pat, set);
638+
walk(tcx, mutbl, pat, set);
639639
ret set;
640640
}
641641

642-
// Wraps the expr_root in mut.rs to also handle roots that exist through
642+
// Wraps the expr_root in mutbl.rs to also handle roots that exist through
643643
// return-by-reference
644644
fn expr_root(cx: ctx, ex: @ast::expr, autoderef: bool)
645-
-> {ex: @ast::expr, mut: option<unsafe_ty>} {
646-
let base_root = mut::expr_root(cx.tcx, ex, autoderef);
645+
-> {ex: @ast::expr, mutbl: option<unsafe_ty>} {
646+
let base_root = mutbl::expr_root(cx.tcx, ex, autoderef);
647647
let unsafe_ty = none;
648648
for d in *base_root.ds {
649-
if d.mut { unsafe_ty = some(contains(d.outer_t)); break; }
649+
if d.mutbl { unsafe_ty = some(contains(d.outer_t)); break; }
650650
}
651-
ret {ex: base_root.ex, mut: unsafe_ty};
651+
ret {ex: base_root.ex, mutbl: unsafe_ty};
652652
}
653653

654654
fn unsafe_set(from: option<unsafe_ty>) -> [unsafe_ty] {

0 commit comments

Comments
 (0)