Skip to content

Commit f96a2a2

Browse files
committed
Remove by-mutable-ref mode from the compiler
and test cases. Closes #3513
1 parent 0599929 commit f96a2a2

26 files changed

+59
-95
lines changed

doc/rust.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,14 +2784,12 @@ aside a copy of that value to refer to. If this is not semantically safe (for
27842784
example, if the referred-to value contains mutable fields), it will reject the
27852785
program. If the compiler deems copying the value expensive, it will warn.
27862786

2787-
A function can be declared to take an argument by mutable reference. This
2788-
allows the function to write to the slot that the reference refers to.
2789-
2790-
An example function that accepts an value by mutable reference:
2787+
A function with an argument of type `&mut T`, for some type `T`, can write to
2788+
the slot that its argument refers to. An example of such a function is:
27912789

27922790
~~~~~~~~
2793-
fn incr(&i: int) {
2794-
i = i + 1;
2791+
fn incr(i: &mut int) {
2792+
*i = *i + 1;
27952793
}
27962794
~~~~~~~~
27972795

src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ impl<T:cmp::Eq> inferable<T> : cmp::Eq {
574574

575575
// "resolved" mode: the real modes.
576576
#[auto_serialize]
577-
enum rmode { by_ref, by_val, by_mutbl_ref, by_move, by_copy }
577+
enum rmode { by_ref, by_val, by_move, by_copy }
578578

579579
impl rmode : to_bytes::IterBytes {
580580
pure fn iter_bytes(+lsb0: bool, f: to_bytes::Cb) {

src/libsyntax/parse/obsolete.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ pub enum ObsoleteSyntax {
2222
ObsoleteClassMethod,
2323
ObsoleteClassTraits,
2424
ObsoletePrivSection,
25-
ObsoleteModeInFnType
25+
ObsoleteModeInFnType,
26+
ObsoleteByMutRefMode
2627
}
2728

2829
impl ObsoleteSyntax : cmp::Eq {
@@ -94,6 +95,10 @@ impl parser : ObsoleteReporter {
9495
"to use a (deprecated) mode in a fn type, you should \
9596
give the argument an explicit name (like `&&v: int`)"
9697
),
98+
ObsoleteByMutRefMode => (
99+
"by-mutable-reference mode",
100+
"Declare an argument of type &mut T instead"
101+
),
97102
};
98103

99104
self.report(sp, kind, kind_str, desc);

src/libsyntax/parse/parser.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ use obsolete::{
2020
ObsoleteLowerCaseKindBounds, ObsoleteLet,
2121
ObsoleteFieldTerminator, ObsoleteStructCtor,
2222
ObsoleteWith, ObsoleteClassMethod, ObsoleteClassTraits,
23-
ObsoleteModeInFnType
23+
ObsoleteModeInFnType, ObsoleteByMutRefMode
2424
};
2525
use ast::{_mod, add, alt_check, alt_exhaustive, arg, arm, attribute,
2626
bind_by_ref, bind_by_implicit_ref, bind_by_value, bind_by_move,
2727
bitand, bitor, bitxor, blk, blk_check_mode, bound_const,
2828
bound_copy, bound_send, bound_trait, bound_owned, box, by_copy,
29-
by_move, by_mutbl_ref, by_ref, by_val, capture_clause,
29+
by_move, by_ref, by_val, capture_clause,
3030
capture_item, cdir_dir_mod, cdir_src_mod, cdir_view_item,
3131
class_immutable, class_mutable,
3232
crate, crate_cfg, crate_directive, decl, decl_item, decl_local,
@@ -570,9 +570,10 @@ impl parser {
570570

571571
fn parse_arg_mode() -> mode {
572572
if self.eat(token::BINOP(token::AND)) {
573-
self.span_fatal(copy self.last_span,
574-
~"Obsolete syntax has no effect");
575-
expl(by_mutbl_ref)
573+
self.obsolete(copy self.span,
574+
ObsoleteByMutRefMode);
575+
// Bogus mode, but doesn't matter since it's an error
576+
expl(by_ref)
576577
} else if self.eat(token::BINOP(token::MINUS)) {
577578
expl(by_move)
578579
} else if self.eat(token::ANDAND) {

src/libsyntax/print/pprust.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,6 @@ fn print_fn_block_args(s: ps, decl: ast::fn_decl,
16881688
16891689
fn mode_to_str(m: ast::mode) -> ~str {
16901690
match m {
1691-
ast::expl(ast::by_mutbl_ref) => ~"&",
16921691
ast::expl(ast::by_move) => ~"-",
16931692
ast::expl(ast::by_ref) => ~"&&",
16941693
ast::expl(ast::by_val) => ~"++",

src/rustc/metadata/tydecode.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ fn parse_arg(st: @pstate, conv: conv_did) -> ty::arg {
394394

395395
fn parse_mode(st: @pstate) -> ast::mode {
396396
let m = ast::expl(match next(st) {
397-
'&' => ast::by_mutbl_ref,
398397
'-' => ast::by_move,
399398
'+' => ast::by_copy,
400399
'=' => ast::by_ref,

src/rustc/metadata/tyencode.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ fn enc_arg(w: io::Writer, cx: @ctxt, arg: ty::arg) {
333333

334334
fn enc_mode(w: io::Writer, cx: @ctxt, m: mode) {
335335
match ty::resolved_mode(cx.tcx, m) {
336-
by_mutbl_ref => w.write_char('&'),
337336
by_move => w.write_char('-'),
338337
by_copy => w.write_char('+'),
339338
by_ref => w.write_char('='),

src/rustc/middle/borrowck/check_loans.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ impl check_loan_ctxt {
529529
ast::by_move => {
530530
self.check_move_out(*arg);
531531
}
532-
ast::by_mutbl_ref | ast::by_ref |
532+
ast::by_ref |
533533
ast::by_copy | ast::by_val => {
534534
}
535535
}

src/rustc/middle/borrowck/gather_loans.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ fn req_loans_in_expr(ex: @ast::expr,
115115
let scope_r = ty::re_scope(ex.id);
116116
for vec::each2(args, arg_tys) |arg, arg_ty| {
117117
match ty::resolved_mode(self.tcx(), arg_ty.mode) {
118-
ast::by_mutbl_ref => {
119-
let arg_cmt = self.bccx.cat_expr(*arg);
120-
self.guarantee_valid(arg_cmt, m_mutbl, scope_r);
121-
}
122118
ast::by_ref => {
123119
let arg_cmt = self.bccx.cat_expr(*arg);
124120
self.guarantee_valid(arg_cmt, m_imm, scope_r);

src/rustc/middle/kind.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
323323
for ty::ty_fn_args(ty::expr_ty(cx.tcx, f)).each |arg_t| {
324324
match ty::arg_mode(cx.tcx, *arg_t) {
325325
by_copy => maybe_copy(cx, args[i], None),
326-
by_ref | by_val | by_mutbl_ref | by_move => ()
326+
by_ref | by_val | by_move => ()
327327
}
328328
i += 1u;
329329
}
@@ -335,7 +335,7 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
335335
Some(ref mme) => {
336336
match ty::arg_mode(cx.tcx, mme.self_arg) {
337337
by_copy => maybe_copy(cx, lhs, None),
338-
by_ref | by_val | by_mutbl_ref | by_move => ()
338+
by_ref | by_val | by_move => ()
339339
}
340340
}
341341
_ => ()
@@ -465,14 +465,7 @@ fn check_imm_free_var(cx: ctx, def: def, sp: span) {
465465
cx.tcx.sess.span_err(sp, msg);
466466
}
467467
}
468-
def_arg(_, mode) => {
469-
match ty::resolved_mode(cx.tcx, mode) {
470-
by_ref | by_val | by_move | by_copy => { /* ok */ }
471-
by_mutbl_ref => {
472-
cx.tcx.sess.span_err(sp, msg);
473-
}
474-
}
475-
}
468+
def_arg(*) => { /* ok */ }
476469
def_upvar(_, def1, _, _) => {
477470
check_imm_free_var(cx, *def1, sp);
478471
}

0 commit comments

Comments
 (0)