1
Fork 0

Remove copy bindings from patterns.

This commit is contained in:
Niko Matsakis 2013-05-29 19:59:33 -04:00
parent 5209709e46
commit 7a1a40890d
34 changed files with 176 additions and 201 deletions

View file

@ -35,13 +35,13 @@ enum TreeNode<K, V> {
pub fn init<K, V>() -> Treemap<K, V> { @Empty } pub fn init<K, V>() -> Treemap<K, V> { @Empty }
/// Insert a value into the map /// Insert a value into the map
pub fn insert<K:Copy + Eq + Ord,V:Copy>(m: Treemap<K, V>, k: K, v: V) -> Treemap<K, V> { pub fn insert<K:Eq + Ord,V>(m: Treemap<K, V>, k: K, v: V) -> Treemap<K, V> {
@match m { @match m {
@Empty => Node(@k, @v, @Empty, @Empty), @Empty => Node(@k, @v, @Empty, @Empty),
@Node(@copy kk, vv, left, right) => cond!( @Node(kk, vv, left, right) => cond!(
(k < kk) { Node(@kk, vv, insert(left, k, v), right) } (k < *kk) { Node(kk, vv, insert(left, k, v), right) }
(k == kk) { Node(@kk, @v, left, right) } (k == *kk) { Node(kk, @v, left, right) }
_ { Node(@kk, vv, left, insert(right, k, v)) } _ { Node(kk, vv, left, insert(right, k, v)) }
) )
} }
} }
@ -50,8 +50,8 @@ pub fn insert<K:Copy + Eq + Ord,V:Copy>(m: Treemap<K, V>, k: K, v: V) -> Treemap
pub fn find<K:Eq + Ord,V:Copy>(m: Treemap<K, V>, k: K) -> Option<V> { pub fn find<K:Eq + Ord,V:Copy>(m: Treemap<K, V>, k: K) -> Option<V> {
match *m { match *m {
Empty => None, Empty => None,
Node(@ref kk, @copy v, left, right) => cond!( Node(kk, v, left, right) => cond!(
(k == *kk) { Some(v) } (k == *kk) { Some(copy *v) }
(k < *kk) { find(left, k) } (k < *kk) { find(left, k) }
_ { find(right, k) } _ { find(right, k) }
) )

View file

@ -171,7 +171,7 @@ fn is_arg(arg: &str) -> bool {
fn name_str(nm: &Name) -> ~str { fn name_str(nm: &Name) -> ~str {
return match *nm { return match *nm {
Short(ch) => str::from_char(ch), Short(ch) => str::from_char(ch),
Long(copy s) => s Long(ref s) => copy *s
}; };
} }
@ -390,7 +390,7 @@ pub fn opts_present(mm: &Matches, names: &[~str]) -> bool {
* argument * argument
*/ */
pub fn opt_str(mm: &Matches, nm: &str) -> ~str { pub fn opt_str(mm: &Matches, nm: &str) -> ~str {
return match opt_val(mm, nm) { Val(copy s) => s, _ => fail!() }; return match opt_val(mm, nm) { Val(s) => s, _ => fail!() };
} }
/** /**
@ -402,7 +402,7 @@ pub fn opt_str(mm: &Matches, nm: &str) -> ~str {
pub fn opts_str(mm: &Matches, names: &[~str]) -> ~str { pub fn opts_str(mm: &Matches, names: &[~str]) -> ~str {
for names.each |nm| { for names.each |nm| {
match opt_val(mm, *nm) { match opt_val(mm, *nm) {
Val(copy s) => return s, Val(ref s) => return copy *s,
_ => () _ => ()
} }
} }
@ -419,7 +419,7 @@ pub fn opts_str(mm: &Matches, names: &[~str]) -> ~str {
pub fn opt_strs(mm: &Matches, nm: &str) -> ~[~str] { pub fn opt_strs(mm: &Matches, nm: &str) -> ~[~str] {
let mut acc: ~[~str] = ~[]; let mut acc: ~[~str] = ~[];
for vec::each(opt_vals(mm, nm)) |v| { for vec::each(opt_vals(mm, nm)) |v| {
match *v { Val(copy s) => acc.push(s), _ => () } match *v { Val(ref s) => acc.push(copy *s), _ => () }
} }
return acc; return acc;
} }
@ -429,7 +429,7 @@ pub fn opt_maybe_str(mm: &Matches, nm: &str) -> Option<~str> {
let vals = opt_vals(mm, nm); let vals = opt_vals(mm, nm);
if vec::len::<Optval>(vals) == 0u { return None::<~str>; } if vec::len::<Optval>(vals) == 0u { return None::<~str>; }
return match vals[0] { return match vals[0] {
Val(copy s) => Some(s), Val(ref s) => Some(copy *s),
_ => None _ => None
}; };
} }
@ -445,7 +445,7 @@ pub fn opt_maybe_str(mm: &Matches, nm: &str) -> Option<~str> {
pub fn opt_default(mm: &Matches, nm: &str, def: &str) -> Option<~str> { pub fn opt_default(mm: &Matches, nm: &str, def: &str) -> Option<~str> {
let vals = opt_vals(mm, nm); let vals = opt_vals(mm, nm);
if vec::len::<Optval>(vals) == 0u { return None::<~str>; } if vec::len::<Optval>(vals) == 0u { return None::<~str>; }
return match vals[0] { Val(copy s) => Some::<~str>(s), return match vals[0] { Val(ref s) => Some::<~str>(copy *s),
_ => Some::<~str>(str::to_owned(def)) } _ => Some::<~str>(str::to_owned(def)) }
} }
@ -701,7 +701,7 @@ mod tests {
let opts = ~[reqopt("test")]; let opts = ~[reqopt("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, OptionMissing_), Err(f) => check_fail_type(f, OptionMissing_),
_ => fail!() _ => fail!()
} }
} }
@ -712,7 +712,7 @@ mod tests {
let opts = ~[reqopt("test")]; let opts = ~[reqopt("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, ArgumentMissing_), Err(f) => check_fail_type(f, ArgumentMissing_),
_ => fail!() _ => fail!()
} }
} }
@ -723,7 +723,7 @@ mod tests {
let opts = ~[reqopt("test")]; let opts = ~[reqopt("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, OptionDuplicated_), Err(f) => check_fail_type(f, OptionDuplicated_),
_ => fail!() _ => fail!()
} }
} }
@ -748,7 +748,7 @@ mod tests {
let opts = ~[reqopt("t")]; let opts = ~[reqopt("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, OptionMissing_), Err(f) => check_fail_type(f, OptionMissing_),
_ => fail!() _ => fail!()
} }
} }
@ -759,7 +759,7 @@ mod tests {
let opts = ~[reqopt("t")]; let opts = ~[reqopt("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, ArgumentMissing_), Err(f) => check_fail_type(f, ArgumentMissing_),
_ => fail!() _ => fail!()
} }
} }
@ -770,7 +770,7 @@ mod tests {
let opts = ~[reqopt("t")]; let opts = ~[reqopt("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, OptionDuplicated_), Err(f) => check_fail_type(f, OptionDuplicated_),
_ => fail!() _ => fail!()
} }
} }
@ -808,7 +808,7 @@ mod tests {
let opts = ~[optopt("test")]; let opts = ~[optopt("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, ArgumentMissing_), Err(f) => check_fail_type(f, ArgumentMissing_),
_ => fail!() _ => fail!()
} }
} }
@ -819,7 +819,7 @@ mod tests {
let opts = ~[optopt("test")]; let opts = ~[optopt("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, OptionDuplicated_), Err(f) => check_fail_type(f, OptionDuplicated_),
_ => fail!() _ => fail!()
} }
} }
@ -855,7 +855,7 @@ mod tests {
let opts = ~[optopt("t")]; let opts = ~[optopt("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, ArgumentMissing_), Err(f) => check_fail_type(f, ArgumentMissing_),
_ => fail!() _ => fail!()
} }
} }
@ -866,7 +866,7 @@ mod tests {
let opts = ~[optopt("t")]; let opts = ~[optopt("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, OptionDuplicated_), Err(f) => check_fail_type(f, OptionDuplicated_),
_ => fail!() _ => fail!()
} }
} }
@ -901,7 +901,7 @@ mod tests {
let opts = ~[optflag("test")]; let opts = ~[optflag("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => { Err(f) => {
error!(fail_str(copy f)); error!(fail_str(copy f));
check_fail_type(f, UnexpectedArgument_); check_fail_type(f, UnexpectedArgument_);
} }
@ -915,7 +915,7 @@ mod tests {
let opts = ~[optflag("test")]; let opts = ~[optflag("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, OptionDuplicated_), Err(f) => check_fail_type(f, OptionDuplicated_),
_ => fail!() _ => fail!()
} }
} }
@ -963,7 +963,7 @@ mod tests {
let opts = ~[optflag("t")]; let opts = ~[optflag("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, OptionDuplicated_), Err(f) => check_fail_type(f, OptionDuplicated_),
_ => fail!() _ => fail!()
} }
} }
@ -1066,7 +1066,7 @@ mod tests {
let opts = ~[optmulti("test")]; let opts = ~[optmulti("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, ArgumentMissing_), Err(f) => check_fail_type(f, ArgumentMissing_),
_ => fail!() _ => fail!()
} }
} }
@ -1119,7 +1119,7 @@ mod tests {
let opts = ~[optmulti("t")]; let opts = ~[optmulti("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, ArgumentMissing_), Err(f) => check_fail_type(f, ArgumentMissing_),
_ => fail!() _ => fail!()
} }
} }
@ -1147,7 +1147,7 @@ mod tests {
let opts = ~[optmulti("t")]; let opts = ~[optmulti("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, UnrecognizedOption_), Err(f) => check_fail_type(f, UnrecognizedOption_),
_ => fail!() _ => fail!()
} }
} }
@ -1158,7 +1158,7 @@ mod tests {
let opts = ~[optmulti("test")]; let opts = ~[optmulti("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, UnrecognizedOption_), Err(f) => check_fail_type(f, UnrecognizedOption_),
_ => fail!() _ => fail!()
} }
} }

View file

@ -1384,7 +1384,7 @@ mod tests {
for items.each |item| { for items.each |item| {
match *item { match *item {
(copy key, copy value) => { d.insert(key, value); }, (ref key, ref value) => { d.insert(copy *key, copy *value); },
} }
}; };

View file

@ -104,7 +104,7 @@ pub fn tail<T:Copy>(ls: @List<T>) -> @List<T> {
/// Returns the first element of a list /// Returns the first element of a list
pub fn head<T:Copy>(ls: @List<T>) -> T { pub fn head<T:Copy>(ls: @List<T>) -> T {
match *ls { match *ls {
Cons(copy hd, _) => hd, Cons(ref hd, _) => copy *hd,
// makes me sad // makes me sad
_ => fail!("head invoked on empty list") _ => fail!("head invoked on empty list")
} }
@ -114,9 +114,9 @@ pub fn head<T:Copy>(ls: @List<T>) -> T {
pub fn append<T:Copy>(l: @List<T>, m: @List<T>) -> @List<T> { pub fn append<T:Copy>(l: @List<T>, m: @List<T>) -> @List<T> {
match *l { match *l {
Nil => return m, Nil => return m,
Cons(copy x, xs) => { Cons(ref x, xs) => {
let rest = append(xs, m); let rest = append(xs, m);
return @Cons(x, rest); return @Cons(copy *x, rest);
} }
} }
} }

View file

@ -278,7 +278,7 @@ pub mod v6 {
pub fn parse_addr(ip: &str) -> IpAddr { pub fn parse_addr(ip: &str) -> IpAddr {
match try_parse_addr(ip) { match try_parse_addr(ip) {
result::Ok(addr) => addr, result::Ok(addr) => addr,
result::Err(copy err_data) => fail!(copy err_data.err_msg) result::Err(err_data) => fail!(copy err_data.err_msg)
} }
} }
pub fn try_parse_addr(ip: &str) -> result::Result<IpAddr,ParseAddrErr> { pub fn try_parse_addr(ip: &str) -> result::Result<IpAddr,ParseAddrErr> {

View file

@ -595,7 +595,7 @@ pub fn accept(new_conn: TcpNewConnection)
} }
// UNSAFE LIBUV INTERACTION END // UNSAFE LIBUV INTERACTION END
match result_po.recv() { match result_po.recv() {
Some(copy err_data) => result::Err(err_data), Some(err_data) => result::Err(err_data),
None => result::Ok(TcpSocket(client_socket_data)) None => result::Ok(TcpSocket(client_socket_data))
} }
} }

View file

@ -223,7 +223,7 @@ pub fn run_tests_console(opts: &TestOpts,
} }
TeWait(ref test) => st.out.write_str( TeWait(ref test) => st.out.write_str(
fmt!("test %s ... ", test.name.to_str())), fmt!("test %s ... ", test.name.to_str())),
TeResult(copy test, result) => { TeResult(test, result) => {
match st.log_out { match st.log_out {
Some(f) => write_log(f, copy result, &test), Some(f) => write_log(f, copy result, &test),
None => () None => ()
@ -504,9 +504,8 @@ pub fn filter_tests(
filtered = if opts.filter.is_none() { filtered = if opts.filter.is_none() {
filtered filtered
} else { } else {
let filter_str = let filter_str = match opts.filter {
match opts.filter { option::Some(ref f) => copy *f,
option::Some(copy f) => f,
option::None => ~"" option::None => ~""
}; };
@ -866,7 +865,7 @@ mod tests {
fn first_free_arg_should_be_a_filter() { fn first_free_arg_should_be_a_filter() {
let args = ~[~"progname", ~"filter"]; let args = ~[~"progname", ~"filter"];
let opts = match parse_opts(args) { let opts = match parse_opts(args) {
either::Left(copy o) => o, either::Left(o) => o,
_ => fail!("Malformed arg in first_free_arg_should_be_a_filter") _ => fail!("Malformed arg in first_free_arg_should_be_a_filter")
}; };
assert!("filter" == (copy opts.filter).get()); assert!("filter" == (copy opts.filter).get());
@ -876,7 +875,7 @@ mod tests {
fn parse_ignored_flag() { fn parse_ignored_flag() {
let args = ~[~"progname", ~"filter", ~"--ignored"]; let args = ~[~"progname", ~"filter", ~"--ignored"];
let opts = match parse_opts(args) { let opts = match parse_opts(args) {
either::Left(copy o) => o, either::Left(o) => o,
_ => fail!("Malformed arg in parse_ignored_flag") _ => fail!("Malformed arg in parse_ignored_flag")
}; };
assert!((opts.run_ignored)); assert!((opts.run_ignored));

View file

@ -275,10 +275,12 @@ priv fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {
let mut i = 0u; let mut i = 0u;
let len = strs.len(); let len = strs.len();
while i < len { while i < len {
let &(needle, value) = &strs[i]; match strs[i] { // can't use let due to stage0 bugs
(ref needle, value) => {
if match_str(ss, pos, needle) { if match_str(ss, pos, *needle) {
return Some((value, pos + str::len(needle))); return Some((value, pos + str::len(*needle)));
}
}
} }
i += 1u; i += 1u;
} }
@ -1007,7 +1009,7 @@ mod tests {
== Err(~"Invalid time")); == Err(~"Invalid time"));
match strptime("Fri Feb 13 15:31:30 2009", format) { match strptime("Fri Feb 13 15:31:30 2009", format) {
Err(copy e) => fail!(e), Err(e) => fail!(e),
Ok(ref tm) => { Ok(ref tm) => {
assert!(tm.tm_sec == 30_i32); assert!(tm.tm_sec == 30_i32);
assert!(tm.tm_min == 31_i32); assert!(tm.tm_min == 31_i32);
@ -1027,7 +1029,7 @@ mod tests {
fn test(s: &str, format: &str) -> bool { fn test(s: &str, format: &str) -> bool {
match strptime(s, format) { match strptime(s, format) {
Ok(ref tm) => tm.strftime(format) == str::to_owned(s), Ok(ref tm) => tm.strftime(format) == str::to_owned(s),
Err(copy e) => fail!(e) Err(e) => fail!(e)
} }
} }

View file

@ -375,8 +375,8 @@ pub mod write {
pub fn run_ndk(sess: Session, assembly: &Path, object: &Path) { pub fn run_ndk(sess: Session, assembly: &Path, object: &Path) {
let cc_prog: ~str = match &sess.opts.android_cross_path { let cc_prog: ~str = match &sess.opts.android_cross_path {
&Some(copy path) => { &Some(ref path) => {
fmt!("%s/bin/arm-linux-androideabi-gcc", path) fmt!("%s/bin/arm-linux-androideabi-gcc", *path)
} }
&None => { &None => {
sess.fatal("need Android NDK path for building \ sess.fatal("need Android NDK path for building \
@ -763,12 +763,12 @@ pub fn link_binary(sess: Session,
// For win32, there is no cc command, // For win32, there is no cc command,
// so we add a condition to make it use gcc. // so we add a condition to make it use gcc.
let cc_prog: ~str = match sess.opts.linker { let cc_prog: ~str = match sess.opts.linker {
Some(copy linker) => linker, Some(ref linker) => copy *linker,
None => { None => {
if sess.targ_cfg.os == session::os_android { if sess.targ_cfg.os == session::os_android {
match &sess.opts.android_cross_path { match &sess.opts.android_cross_path {
&Some(copy path) => { &Some(ref path) => {
fmt!("%s/bin/arm-linux-androideabi-gcc", path) fmt!("%s/bin/arm-linux-androideabi-gcc", *path)
} }
&None => { &None => {
sess.fatal("need Android NDK path for linking \ sess.fatal("need Android NDK path for linking \

View file

@ -956,8 +956,8 @@ mod test {
fn test_switch_implies_cfg_test() { fn test_switch_implies_cfg_test() {
let matches = let matches =
&match getopts([~"--test"], optgroups()) { &match getopts([~"--test"], optgroups()) {
Ok(copy m) => m, Ok(m) => m,
Err(copy f) => fail!("test_switch_implies_cfg_test: %s", getopts::fail_str(f)) Err(f) => fail!("test_switch_implies_cfg_test: %s", getopts::fail_str(f))
}; };
let sessopts = build_session_options( let sessopts = build_session_options(
@~"rustc", matches, diagnostic::emit); @~"rustc", matches, diagnostic::emit);
@ -972,8 +972,8 @@ mod test {
fn test_switch_implies_cfg_test_unless_cfg_test() { fn test_switch_implies_cfg_test_unless_cfg_test() {
let matches = let matches =
&match getopts([~"--test", ~"--cfg=test"], optgroups()) { &match getopts([~"--test", ~"--cfg=test"], optgroups()) {
Ok(copy m) => m, Ok(m) => m,
Err(copy f) => { Err(f) => {
fail!("test_switch_implies_cfg_test_unless_cfg_test: %s", getopts::fail_str(f)); fail!("test_switch_implies_cfg_test_unless_cfg_test: %s", getopts::fail_str(f));
} }
}; };

View file

@ -141,10 +141,10 @@ fn visit_crate(e: @mut Env, c: &ast::crate) {
fn visit_view_item(e: @mut Env, i: @ast::view_item) { fn visit_view_item(e: @mut Env, i: @ast::view_item) {
match i.node { match i.node {
ast::view_item_extern_mod(ident, /*bad*/copy meta_items, id) => { ast::view_item_extern_mod(ident, ref meta_items, id) => {
debug!("resolving extern mod stmt. ident: %?, meta: %?", debug!("resolving extern mod stmt. ident: %?, meta: %?",
ident, meta_items); ident, *meta_items);
let cnum = resolve_crate(e, ident, meta_items, @~"", i.span); let cnum = resolve_crate(e, ident, copy *meta_items, @~"", i.span);
cstore::add_extern_mod_stmt_cnum(e.cstore, id, cnum); cstore::add_extern_mod_stmt_cnum(e.cstore, id, cnum);
} }
_ => () _ => ()

View file

@ -623,7 +623,7 @@ pub impl GatherLoanCtxt {
cmt, mutbl, scope_r); cmt, mutbl, scope_r);
} }
} }
ast::bind_by_copy | ast::bind_infer => { ast::bind_infer => {
// No borrows here, but there may be moves // No borrows here, but there may be moves
if self.bccx.is_move(pat.id) { if self.bccx.is_move(pat.id) {
gather_moves::gather_move_from_pat( gather_moves::gather_move_from_pat(

View file

@ -827,7 +827,6 @@ pub fn check_legality_of_move_bindings(cx: @MatchCheckCtxt,
for pats.each |pat| { for pats.each |pat| {
do pat_bindings(def_map, *pat) |bm, id, span, _path| { do pat_bindings(def_map, *pat) |bm, id, span, _path| {
match bm { match bm {
bind_by_copy => {}
bind_by_ref(_) => { bind_by_ref(_) => {
by_ref_span = Some(span); by_ref_span = Some(span);
} }

View file

@ -71,7 +71,6 @@ pub fn check_crate(tcx: ty::ctxt,
current_item: -1 current_item: -1
}; };
let visit = visit::mk_vt(@visit::Visitor { let visit = visit::mk_vt(@visit::Visitor {
visit_arm: check_arm,
visit_expr: check_expr, visit_expr: check_expr,
visit_fn: check_fn, visit_fn: check_fn,
visit_ty: check_ty, visit_ty: check_ty,
@ -238,19 +237,6 @@ fn check_fn(
visit::visit_fn(fk, decl, body, sp, fn_id, cx, v); visit::visit_fn(fk, decl, body, sp, fn_id, cx, v);
} }
fn check_arm(a: &arm, cx: Context, v: visit::vt<Context>) {
for a.pats.each |p| {
do pat_util::pat_bindings(cx.tcx.def_map, *p) |mode, id, span, _pth| {
if mode == bind_by_copy {
let t = ty::node_id_to_type(cx.tcx, id);
let reason = "consider binding with `ref` or `move` instead";
check_copy(cx, t, span, reason);
}
}
}
visit::visit_arm(a, cx, v);
}
pub fn check_expr(e: @expr, cx: Context, v: visit::vt<Context>) { pub fn check_expr(e: @expr, cx: Context, v: visit::vt<Context>) {
debug!("kind::check_expr(%s)", expr_to_str(e, cx.tcx.sess.intr())); debug!("kind::check_expr(%s)", expr_to_str(e, cx.tcx.sess.intr()));

View file

@ -576,14 +576,18 @@ pub impl VisitContext {
do pat_bindings(self.tcx.def_map, pat) |bm, id, _span, _path| { do pat_bindings(self.tcx.def_map, pat) |bm, id, _span, _path| {
let binding_moves = match bm { let binding_moves = match bm {
bind_by_copy => false,
bind_by_ref(_) => false, bind_by_ref(_) => false,
bind_infer => { bind_infer => {
let pat_ty = ty::node_id_to_type(self.tcx, id); let pat_ty = ty::node_id_to_type(self.tcx, id);
debug!("pattern %? type is %s",
id, pat_ty.repr(self.tcx));
ty::type_moves_by_default(self.tcx, pat_ty) ty::type_moves_by_default(self.tcx, pat_ty)
} }
}; };
debug!("pattern binding %?: bm=%?, binding_moves=%b",
id, bm, binding_moves);
if binding_moves { if binding_moves {
self.move_maps.moves_map.insert(id); self.move_maps.moves_map.insert(id);
} }

View file

@ -520,12 +520,12 @@ pub impl NameBindings {
type_span: Some(sp) type_span: Some(sp)
}); });
} }
Some(copy type_def) => { Some(type_def) => {
self.type_def = Some(TypeNsDef { self.type_def = Some(TypeNsDef {
privacy: privacy, privacy: privacy,
module_def: Some(module_), module_def: Some(module_),
type_span: Some(sp), type_span: Some(sp),
.. type_def type_def: type_def.type_def
}); });
} }
} }
@ -577,12 +577,12 @@ pub impl NameBindings {
type_span: Some(sp) type_span: Some(sp)
}); });
} }
Some(copy type_def) => { Some(type_def) => {
self.type_def = Some(TypeNsDef { self.type_def = Some(TypeNsDef {
privacy: privacy, privacy: privacy,
type_def: Some(def), type_def: Some(def),
type_span: Some(sp), type_span: Some(sp),
.. type_def module_def: type_def.module_def
}); });
} }
} }
@ -1566,7 +1566,7 @@ pub impl Resolver {
match def { match def {
def_mod(def_id) | def_foreign_mod(def_id) => { def_mod(def_id) | def_foreign_mod(def_id) => {
match child_name_bindings.type_def { match child_name_bindings.type_def {
Some(TypeNsDef { module_def: Some(copy module_def), _ }) => { Some(TypeNsDef { module_def: Some(module_def), _ }) => {
debug!("(building reduced graph for external crate) \ debug!("(building reduced graph for external crate) \
already created module"); already created module");
module_def.def_id = Some(def_id); module_def.def_id = Some(def_id);
@ -1745,7 +1745,7 @@ pub impl Resolver {
NormalModuleKind, NormalModuleKind,
dummy_sp()); dummy_sp());
} }
Some(copy type_ns_def) Some(type_ns_def)
if type_ns_def.module_def.is_none() => { if type_ns_def.module_def.is_none() => {
debug!("(building reduced graph for external crate) \ debug!("(building reduced graph for external crate) \
autovivifying missing module def %s", autovivifying missing module def %s",
@ -1812,7 +1812,7 @@ pub impl Resolver {
let type_module; let type_module;
match child_name_bindings.type_def { match child_name_bindings.type_def {
Some(TypeNsDef { Some(TypeNsDef {
module_def: Some(copy module_def), module_def: Some(module_def),
_ _
}) => { }) => {
// We already have a module. This // We already have a module. This
@ -2445,7 +2445,7 @@ pub impl Resolver {
None => { None => {
// Continue. // Continue.
} }
Some(copy value_target) => { Some(value_target) => {
dest_import_resolution.value_target = dest_import_resolution.value_target =
Some(value_target); Some(value_target);
} }
@ -2454,7 +2454,7 @@ pub impl Resolver {
None => { None => {
// Continue. // Continue.
} }
Some(copy type_target) => { Some(type_target) => {
dest_import_resolution.type_target = dest_import_resolution.type_target =
Some(type_target); Some(type_target);
} }
@ -2566,7 +2566,7 @@ pub impl Resolver {
// Check to see whether there are type bindings, and, if // Check to see whether there are type bindings, and, if
// so, whether there is a module within. // so, whether there is a module within.
match target.bindings.type_def { match target.bindings.type_def {
Some(copy type_def) => { Some(type_def) => {
match type_def.module_def { match type_def.module_def {
None => { None => {
// Not a module. // Not a module.
@ -5170,12 +5170,6 @@ pub impl Resolver {
descr: &str) { descr: &str) {
match pat_binding_mode { match pat_binding_mode {
bind_infer => {} bind_infer => {}
bind_by_copy => {
self.session.span_err(
pat.span,
fmt!("cannot use `copy` binding mode with %s",
descr));
}
bind_by_ref(*) => { bind_by_ref(*) => {
self.session.span_err( self.session.span_err(
pat.span, pat.span,
@ -5316,7 +5310,7 @@ pub fn resolve_crate(session: Session,
-> CrateMap { -> CrateMap {
let resolver = @mut Resolver(session, lang_items, crate); let resolver = @mut Resolver(session, lang_items, crate);
resolver.resolve(); resolver.resolve();
let @Resolver{def_map, export_map2, trait_map, _} = resolver; let Resolver{def_map, export_map2, trait_map, _} = copy *resolver;
CrateMap { CrateMap {
def_map: def_map, def_map: def_map,
exp_map2: export_map2, exp_map2: export_map2,

View file

@ -1640,7 +1640,7 @@ fn create_bindings_map(bcx: block, pat: @ast::pat) -> BindingsMap {
let llmatch, trmode; let llmatch, trmode;
match bm { match bm {
ast::bind_by_copy | ast::bind_infer => { ast::bind_infer => {
// in this case, the final type of the variable will be T, // in this case, the final type of the variable will be T,
// but during matching we need to store a *T as explained // but during matching we need to store a *T as explained
// above // above

View file

@ -450,7 +450,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: @ast::pat, expected: ty::t) {
demand::eqtype(fcx, pat.span, region_ty, typ); demand::eqtype(fcx, pat.span, region_ty, typ);
} }
// otherwise the type of x is the expected type T // otherwise the type of x is the expected type T
ast::bind_by_copy | ast::bind_infer => { ast::bind_infer => {
demand::eqtype(fcx, pat.span, expected, typ); demand::eqtype(fcx, pat.span, expected, typ);
} }
} }

View file

@ -308,7 +308,7 @@ pub impl CoherenceChecker {
implementation = implementation =
self.create_impl_from_item(item); self.create_impl_from_item(item);
} }
Some(copy existing_implementation) => { Some(existing_implementation) => {
implementation = existing_implementation; implementation = existing_implementation;
} }
} }

View file

@ -1933,7 +1933,7 @@ mod tests {
#[test] #[test]
fn file_reader_not_exist() { fn file_reader_not_exist() {
match io::file_reader(&Path("not a file")) { match io::file_reader(&Path("not a file")) {
result::Err(copy e) => { result::Err(e) => {
assert_eq!(e, ~"error opening not a file"); assert_eq!(e, ~"error opening not a file");
} }
result::Ok(_) => fail!() result::Ok(_) => fail!()
@ -1974,7 +1974,7 @@ mod tests {
#[test] #[test]
fn file_writer_bad_name() { fn file_writer_bad_name() {
match io::file_writer(&Path("?/?"), []) { match io::file_writer(&Path("?/?"), []) {
result::Err(copy e) => { result::Err(e) => {
assert!(str::starts_with(e, "error opening")); assert!(str::starts_with(e, "error opening"));
} }
result::Ok(_) => fail!() result::Ok(_) => fail!()
@ -1984,7 +1984,7 @@ mod tests {
#[test] #[test]
fn buffered_file_writer_bad_name() { fn buffered_file_writer_bad_name() {
match io::buffered_file_writer(&Path("?/?")) { match io::buffered_file_writer(&Path("?/?")) {
result::Err(copy e) => { result::Err(e) => {
assert!(str::starts_with(e, "error opening")); assert!(str::starts_with(e, "error opening"));
} }
result::Ok(_) => fail!() result::Ok(_) => fail!()

View file

@ -341,7 +341,7 @@ pub impl<T:Copy> Option<T> {
#[inline(always)] #[inline(always)]
fn get(self) -> T { fn get(self) -> T {
match self { match self {
Some(copy x) => return x, Some(x) => return x,
None => fail!("option::get none") None => fail!("option::get none")
} }
} }
@ -349,7 +349,7 @@ pub impl<T:Copy> Option<T> {
/// Returns the contained value or a default /// Returns the contained value or a default
#[inline(always)] #[inline(always)]
fn get_or_default(self, def: T) -> T { fn get_or_default(self, def: T) -> T {
match self { Some(copy x) => x, None => def } match self { Some(x) => x, None => def }
} }
/// Applies a function zero or more times until the result is none. /// Applies a function zero or more times until the result is none.
@ -366,7 +366,7 @@ pub impl<T:Copy + Zero> Option<T> {
/// Returns the contained value or zero (for this type) /// Returns the contained value or zero (for this type)
#[inline(always)] #[inline(always)]
fn get_or_zero(self) -> T { fn get_or_zero(self) -> T {
match self { Some(copy x) => x, None => Zero::zero() } match self { Some(x) => x, None => Zero::zero() }
} }
} }

View file

@ -774,9 +774,9 @@ impl GenericPath for WindowsPath {
/* if rhs has a host set, then the whole thing wins */ /* if rhs has a host set, then the whole thing wins */
match other.host { match other.host {
Some(copy host) => { Some(ref host) => {
return WindowsPath { return WindowsPath {
host: Some(host), host: Some(copy *host),
device: copy other.device, device: copy other.device,
is_absolute: true, is_absolute: true,
components: copy other.components, components: copy other.components,
@ -787,10 +787,10 @@ impl GenericPath for WindowsPath {
/* if rhs has a device set, then a part wins */ /* if rhs has a device set, then a part wins */
match other.device { match other.device {
Some(copy device) => { Some(ref device) => {
return WindowsPath { return WindowsPath {
host: None, host: None,
device: Some(device), device: Some(copy *device),
is_absolute: true, is_absolute: true,
components: copy other.components, components: copy other.components,
}; };

View file

@ -40,7 +40,7 @@ pub enum Result<T, U> {
#[inline(always)] #[inline(always)]
pub fn get<T:Copy,U>(res: &Result<T, U>) -> T { pub fn get<T:Copy,U>(res: &Result<T, U>) -> T {
match *res { match *res {
Ok(copy t) => t, Ok(ref t) => copy *t,
Err(ref the_err) => Err(ref the_err) =>
fail!("get called on error result: %?", *the_err) fail!("get called on error result: %?", *the_err)
} }
@ -72,7 +72,7 @@ pub fn get_ref<'a, T, U>(res: &'a Result<T, U>) -> &'a T {
#[inline(always)] #[inline(always)]
pub fn get_err<T, U: Copy>(res: &Result<T, U>) -> U { pub fn get_err<T, U: Copy>(res: &Result<T, U>) -> U {
match *res { match *res {
Err(copy u) => u, Err(ref u) => copy *u,
Ok(_) => fail!("get_err called on ok result") Ok(_) => fail!("get_err called on ok result")
} }
} }
@ -102,8 +102,8 @@ pub fn is_err<T, U>(res: &Result<T, U>) -> bool {
pub fn to_either<T:Copy,U:Copy>(res: &Result<U, T>) pub fn to_either<T:Copy,U:Copy>(res: &Result<U, T>)
-> Either<T, U> { -> Either<T, U> {
match *res { match *res {
Ok(copy res) => either::Right(res), Ok(ref res) => either::Right(copy *res),
Err(copy fail_) => either::Left(fail_) Err(ref fail_) => either::Left(copy *fail_)
} }
} }
@ -206,7 +206,7 @@ pub fn map<T, E: Copy, U: Copy>(res: &Result<T, E>, op: &fn(&T) -> U)
-> Result<U, E> { -> Result<U, E> {
match *res { match *res {
Ok(ref t) => Ok(op(t)), Ok(ref t) => Ok(op(t)),
Err(copy e) => Err(e) Err(ref e) => Err(copy *e)
} }
} }
@ -222,7 +222,7 @@ pub fn map<T, E: Copy, U: Copy>(res: &Result<T, E>, op: &fn(&T) -> U)
pub fn map_err<T:Copy,E,F:Copy>(res: &Result<T, E>, op: &fn(&E) -> F) pub fn map_err<T:Copy,E,F:Copy>(res: &Result<T, E>, op: &fn(&E) -> F)
-> Result<T, F> { -> Result<T, F> {
match *res { match *res {
Ok(copy t) => Ok(t), Ok(ref t) => Ok(copy *t),
Err(ref e) => Err(op(e)) Err(ref e) => Err(op(e))
} }
} }
@ -304,8 +304,8 @@ pub fn map_vec<T,U:Copy,V:Copy>(
let mut vs: ~[V] = vec::with_capacity(vec::len(ts)); let mut vs: ~[V] = vec::with_capacity(vec::len(ts));
for ts.each |t| { for ts.each |t| {
match op(t) { match op(t) {
Ok(copy v) => vs.push(v), Ok(v) => vs.push(v),
Err(copy u) => return Err(u) Err(u) => return Err(u)
} }
} }
return Ok(vs); return Ok(vs);
@ -319,8 +319,8 @@ pub fn map_opt<T,U:Copy,V:Copy>(
match *o_t { match *o_t {
None => Ok(None), None => Ok(None),
Some(ref t) => match op(t) { Some(ref t) => match op(t) {
Ok(copy v) => Ok(Some(v)), Ok(v) => Ok(Some(v)),
Err(copy e) => Err(e) Err(e) => Err(e)
} }
} }
} }
@ -344,8 +344,8 @@ pub fn map_vec2<S,T,U:Copy,V:Copy>(ss: &[S], ts: &[T],
let mut i = 0u; let mut i = 0u;
while i < n { while i < n {
match op(&ss[i],&ts[i]) { match op(&ss[i],&ts[i]) {
Ok(copy v) => vs.push(v), Ok(v) => vs.push(v),
Err(copy u) => return Err(u) Err(u) => return Err(u)
} }
i += 1u; i += 1u;
} }
@ -367,7 +367,7 @@ pub fn iter_vec2<S,T,U:Copy>(ss: &[S], ts: &[T],
while i < n { while i < n {
match op(&ss[i],&ts[i]) { match op(&ss[i],&ts[i]) {
Ok(()) => (), Ok(()) => (),
Err(copy u) => return Err(u) Err(u) => return Err(u)
} }
i += 1u; i += 1u;
} }

View file

@ -257,7 +257,6 @@ pub struct field_pat {
#[deriving(Eq, Encodable, Decodable)] #[deriving(Eq, Encodable, Decodable)]
pub enum binding_mode { pub enum binding_mode {
bind_by_copy,
bind_by_ref(mutability), bind_by_ref(mutability),
bind_infer bind_infer
} }
@ -265,13 +264,13 @@ pub enum binding_mode {
impl to_bytes::IterBytes for binding_mode { impl to_bytes::IterBytes for binding_mode {
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool { fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
match *self { match *self {
bind_by_copy => 0u8.iter_bytes(lsb0, f),
bind_by_ref(ref m) => { bind_by_ref(ref m) => {
1u8.iter_bytes(lsb0, f) && m.iter_bytes(lsb0, f) 0u8.iter_bytes(lsb0, f) && m.iter_bytes(lsb0, f)
} }
bind_infer => 2u8.iter_bytes(lsb0, f), bind_infer => {
1u8.iter_bytes(lsb0, f)
}
} }
} }
} }

View file

@ -233,7 +233,7 @@ pub fn ident_to_path(s: span, i: ident) -> @Path {
pub fn ident_to_pat(id: node_id, s: span, i: ident) -> @pat { pub fn ident_to_pat(id: node_id, s: span, i: ident) -> @pat {
@ast::pat { id: id, @ast::pat { id: id,
node: pat_ident(bind_by_copy, ident_to_path(s, i), None), node: pat_ident(bind_infer, ident_to_path(s, i), None),
span: s } span: s }
} }

View file

@ -560,7 +560,7 @@ impl AstBuilder for @ExtCtxt {
self.pat(span, ast::pat_lit(expr)) self.pat(span, ast::pat_lit(expr))
} }
fn pat_ident(&self, span: span, ident: ast::ident) -> @ast::pat { fn pat_ident(&self, span: span, ident: ast::ident) -> @ast::pat {
self.pat_ident_binding_mode(span, ident, ast::bind_by_copy) self.pat_ident_binding_mode(span, ident, ast::bind_infer)
} }
fn pat_ident_binding_mode(&self, fn pat_ident_binding_mode(&self,

View file

@ -62,11 +62,11 @@ fn iter_bytes_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @
Struct(ref fs) => { Struct(ref fs) => {
fields = fs fields = fs
} }
EnumMatching(copy index, ref variant, ref fs) => { EnumMatching(index, ref variant, ref fs) => {
// Determine the discriminant. We will feed this value to the byte // Determine the discriminant. We will feed this value to the byte
// iteration function. // iteration function.
let discriminant = match variant.node.disr_expr { let discriminant = match variant.node.disr_expr {
Some(copy d)=> d, Some(d)=> d,
None => cx.expr_uint(span, index) None => cx.expr_uint(span, index)
}; };

View file

@ -119,7 +119,7 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr {
summary: &Either<uint, ~[ident]>, summary: &Either<uint, ~[ident]>,
rand_call: &fn() -> @expr) -> @expr { rand_call: &fn() -> @expr) -> @expr {
match *summary { match *summary {
Left(copy count) => { Left(count) => {
if count == 0 { if count == 0 {
cx.expr_ident(span, ctor_ident) cx.expr_ident(span, ctor_ident)
} else { } else {

View file

@ -58,8 +58,8 @@ pub fn expand_file(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
base::check_zero_tts(cx, sp, tts, "file!"); base::check_zero_tts(cx, sp, tts, "file!");
let topmost = topmost_expn_info(cx.backtrace().get()); let topmost = topmost_expn_info(cx.backtrace().get());
let Loc { file: @FileMap { name: filename, _ }, _ } = let loc = cx.codemap().lookup_char_pos(topmost.call_site.lo);
cx.codemap().lookup_char_pos(topmost.call_site.lo); let filename = copy loc.file.name;
base::MRExpr(cx.expr_str(topmost.call_site, filename)) base::MRExpr(cx.expr_str(topmost.call_site, filename))
} }

View file

@ -423,7 +423,7 @@ pub fn parse_nt(p: &Parser, name: &str) -> nonterminal {
}, },
"block" => token::nt_block(p.parse_block()), "block" => token::nt_block(p.parse_block()),
"stmt" => token::nt_stmt(p.parse_stmt(~[])), "stmt" => token::nt_stmt(p.parse_stmt(~[])),
"pat" => token::nt_pat(p.parse_pat(true)), "pat" => token::nt_pat(p.parse_pat()),
"expr" => token::nt_expr(p.parse_expr()), "expr" => token::nt_expr(p.parse_expr()),
"ty" => token::nt_ty(p.parse_ty(false /* no need to disambiguate*/)), "ty" => token::nt_ty(p.parse_ty(false /* no need to disambiguate*/)),
// this could be handled like a token, since it is one // this could be handled like a token, since it is one

View file

@ -207,8 +207,8 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
} else { /* repeat */ } else { /* repeat */
r.stack.idx = 0u; r.stack.idx = 0u;
r.repeat_idx[r.repeat_idx.len() - 1u] += 1u; r.repeat_idx[r.repeat_idx.len() - 1u] += 1u;
match r.stack.sep { match copy r.stack.sep {
Some(copy tk) => { Some(tk) => {
r.cur_tok = tk; /* repeat same span, I guess */ r.cur_tok = tk; /* repeat same span, I guess */
return ret_val; return ret_val;
} }
@ -218,8 +218,8 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
} }
loop { /* because it's easiest, this handles `tt_delim` not starting loop { /* because it's easiest, this handles `tt_delim` not starting
with a `tt_tok`, even though it won't happen */ with a `tt_tok`, even though it won't happen */
match r.stack.forest[r.stack.idx] { match copy r.stack.forest[r.stack.idx] {
tt_delim(copy tts) => { tt_delim(tts) => {
r.stack = @mut TtFrame { r.stack = @mut TtFrame {
forest: @mut tts, forest: @mut tts,
idx: 0u, idx: 0u,
@ -229,13 +229,13 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
}; };
// if this could be 0-length, we'd need to potentially recur here // if this could be 0-length, we'd need to potentially recur here
} }
tt_tok(sp, copy tok) => { tt_tok(sp, tok) => {
r.cur_span = sp; r.cur_span = sp;
r.cur_tok = tok; r.cur_tok = tok;
r.stack.idx += 1u; r.stack.idx += 1u;
return ret_val; return ret_val;
} }
tt_seq(sp, copy tts, copy sep, zerok) => { tt_seq(sp, tts, sep, zerok) => {
let t = tt_seq(sp, copy tts, copy sep, zerok); let t = tt_seq(sp, copy tts, copy sep, zerok);
match lockstep_iter_size(&t, r) { match lockstep_iter_size(&t, r) {
lis_unconstrained => { lis_unconstrained => {

View file

@ -487,7 +487,7 @@ mod test {
let parser = string_to_parser(@~"b"); let parser = string_to_parser(@~"b");
assert_eq!(parser.parse_pat(false), assert_eq!(parser.parse_pat(false),
@ast::pat{id:1, // fixme @ast::pat{id:1, // fixme
node: ast::pat_ident(ast::bind_by_copy, node: ast::pat_ident(ast::bind_infer,
@ast::Path{ @ast::Path{
span:sp(0,1), span:sp(0,1),
global:false, global:false,
@ -516,7 +516,7 @@ mod test {
2), 2),
span:sp(4,7)}, span:sp(4,7)},
pat: @ast::pat{id:1, pat: @ast::pat{id:1,
node: ast::pat_ident(ast::bind_by_copy, node: ast::pat_ident(ast::bind_infer,
@ast::Path{ @ast::Path{
span:sp(0,1), span:sp(0,1),
global:false, global:false,
@ -553,7 +553,7 @@ mod test {
span:sp(10,13)}, span:sp(10,13)},
pat: @ast::pat{id:1, // fixme pat: @ast::pat{id:1, // fixme
node: ast::pat_ident( node: ast::pat_ident(
ast::bind_by_copy, ast::bind_infer,
@ast::Path{ @ast::Path{
span:sp(6,7), span:sp(6,7),
global:false, global:false,

View file

@ -18,7 +18,7 @@ use ast::{TyBareFn, TyClosure};
use ast::{RegionTyParamBound, TraitTyParamBound}; use ast::{RegionTyParamBound, TraitTyParamBound};
use ast::{provided, public, purity}; use ast::{provided, public, purity};
use ast::{_mod, add, arg, arm, attribute, bind_by_ref, bind_infer}; use ast::{_mod, add, arg, arm, attribute, bind_by_ref, bind_infer};
use ast::{bind_by_copy, bitand, bitor, bitxor, blk}; use ast::{bitand, bitor, bitxor, blk};
use ast::{blk_check_mode, box}; use ast::{blk_check_mode, box};
use ast::{crate, crate_cfg, decl, decl_item}; use ast::{crate, crate_cfg, decl, decl_item};
use ast::{decl_local, default_blk, deref, div, enum_def, explicit_self}; use ast::{decl_local, default_blk, deref, div, enum_def, explicit_self};
@ -131,11 +131,11 @@ at INTERPOLATED tokens */
macro_rules! maybe_whole_expr ( macro_rules! maybe_whole_expr (
($p:expr) => ( ($p:expr) => (
match *($p).token { match *($p).token {
INTERPOLATED(token::nt_expr(copy e)) => { INTERPOLATED(token::nt_expr(e)) => {
$p.bump(); $p.bump();
return e; return e;
} }
INTERPOLATED(token::nt_path(copy pt)) => { INTERPOLATED(token::nt_path(pt)) => {
$p.bump(); $p.bump();
return $p.mk_expr( return $p.mk_expr(
($p).span.lo, ($p).span.lo,
@ -150,8 +150,8 @@ macro_rules! maybe_whole_expr (
macro_rules! maybe_whole ( macro_rules! maybe_whole (
($p:expr, $constructor:ident) => ( ($p:expr, $constructor:ident) => (
match *($p).token { match copy *($p).token {
INTERPOLATED(token::$constructor(copy x)) => { INTERPOLATED(token::$constructor(x)) => {
$p.bump(); $p.bump();
return x; return x;
} }
@ -159,8 +159,8 @@ macro_rules! maybe_whole (
} }
); );
(deref $p:expr, $constructor:ident) => ( (deref $p:expr, $constructor:ident) => (
match *($p).token { match copy *($p).token {
INTERPOLATED(token::$constructor(copy x)) => { INTERPOLATED(token::$constructor(x)) => {
$p.bump(); $p.bump();
return copy *x; return copy *x;
} }
@ -168,8 +168,8 @@ macro_rules! maybe_whole (
} }
); );
(Some $p:expr, $constructor:ident) => ( (Some $p:expr, $constructor:ident) => (
match *($p).token { match copy *($p).token {
INTERPOLATED(token::$constructor(copy x)) => { INTERPOLATED(token::$constructor(x)) => {
$p.bump(); $p.bump();
return Some(x); return Some(x);
} }
@ -177,8 +177,8 @@ macro_rules! maybe_whole (
} }
); );
(iovi $p:expr, $constructor:ident) => ( (iovi $p:expr, $constructor:ident) => (
match *($p).token { match copy *($p).token {
INTERPOLATED(token::$constructor(copy x)) => { INTERPOLATED(token::$constructor(x)) => {
$p.bump(); $p.bump();
return iovi_item(x); return iovi_item(x);
} }
@ -186,8 +186,8 @@ macro_rules! maybe_whole (
} }
); );
(pair_empty $p:expr, $constructor:ident) => ( (pair_empty $p:expr, $constructor:ident) => (
match *($p).token { match copy *($p).token {
INTERPOLATED(token::$constructor(copy x)) => { INTERPOLATED(token::$constructor(x)) => {
$p.bump(); $p.bump();
return (~[], x); return (~[], x);
} }
@ -825,7 +825,7 @@ pub impl Parser {
let pat = if require_name || self.is_named_argument() { let pat = if require_name || self.is_named_argument() {
self.parse_arg_mode(); self.parse_arg_mode();
is_mutbl = self.eat_keyword(keywords::Mut); is_mutbl = self.eat_keyword(keywords::Mut);
let pat = self.parse_pat(false); let pat = self.parse_pat();
self.expect(&token::COLON); self.expect(&token::COLON);
pat pat
} else { } else {
@ -853,7 +853,7 @@ pub impl Parser {
fn parse_fn_block_arg(&self) -> arg_or_capture_item { fn parse_fn_block_arg(&self) -> arg_or_capture_item {
self.parse_arg_mode(); self.parse_arg_mode();
let is_mutbl = self.eat_keyword(keywords::Mut); let is_mutbl = self.eat_keyword(keywords::Mut);
let pat = self.parse_pat(false); let pat = self.parse_pat();
let t = if self.eat(&token::COLON) { let t = if self.eat(&token::COLON) {
self.parse_ty(false) self.parse_ty(false)
} else { } else {
@ -1992,28 +1992,29 @@ pub impl Parser {
// them as the lambda arguments // them as the lambda arguments
let e = self.parse_expr_res(RESTRICT_NO_BAR_OR_DOUBLEBAR_OP); let e = self.parse_expr_res(RESTRICT_NO_BAR_OR_DOUBLEBAR_OP);
match e.node { match e.node {
expr_call(f, /*bad*/ copy args, NoSugar) => { expr_call(f, ref args, NoSugar) => {
let block = self.parse_lambda_block_expr(); let block = self.parse_lambda_block_expr();
let last_arg = self.mk_expr(block.span.lo, block.span.hi, let last_arg = self.mk_expr(block.span.lo, block.span.hi,
ctor(block)); ctor(block));
let args = vec::append(args, [last_arg]); let args = vec::append(copy *args, [last_arg]);
self.mk_expr(lo.lo, block.span.hi, expr_call(f, args, sugar)) self.mk_expr(lo.lo, block.span.hi, expr_call(f, args, sugar))
} }
expr_method_call(f, i, /*bad*/ copy tps, expr_method_call(f, i, ref tps, ref args, NoSugar) => {
/*bad*/ copy args, NoSugar) => {
let block = self.parse_lambda_block_expr(); let block = self.parse_lambda_block_expr();
let last_arg = self.mk_expr(block.span.lo, block.span.hi, let last_arg = self.mk_expr(block.span.lo, block.span.hi,
ctor(block)); ctor(block));
let args = vec::append(args, [last_arg]); let args = vec::append(copy *args, [last_arg]);
self.mk_expr(lo.lo, block.span.hi, self.mk_expr(lo.lo, block.span.hi,
expr_method_call(f, i, tps, args, sugar)) expr_method_call(f, i, copy *tps,
args, sugar))
} }
expr_field(f, i, /*bad*/ copy tps) => { expr_field(f, i, ref tps) => {
let block = self.parse_lambda_block_expr(); let block = self.parse_lambda_block_expr();
let last_arg = self.mk_expr(block.span.lo, block.span.hi, let last_arg = self.mk_expr(block.span.lo, block.span.hi,
ctor(block)); ctor(block));
self.mk_expr(lo.lo, block.span.hi, self.mk_expr(lo.lo, block.span.hi,
expr_method_call(f, i, tps, ~[last_arg], sugar)) expr_method_call(f, i,
copy *tps, ~[last_arg], sugar))
} }
expr_path(*) | expr_call(*) | expr_method_call(*) | expr_path(*) | expr_call(*) | expr_method_call(*) |
expr_paren(*) => { expr_paren(*) => {
@ -2162,7 +2163,7 @@ pub impl Parser {
fn parse_pats(&self) -> ~[@pat] { fn parse_pats(&self) -> ~[@pat] {
let mut pats = ~[]; let mut pats = ~[];
loop { loop {
pats.push(self.parse_pat(true)); pats.push(self.parse_pat());
if *self.token == token::BINOP(token::OR) { self.bump(); } if *self.token == token::BINOP(token::OR) { self.bump(); }
else { return pats; } else { return pats; }
}; };
@ -2170,7 +2171,6 @@ pub impl Parser {
fn parse_pat_vec_elements( fn parse_pat_vec_elements(
&self, &self,
refutable: bool
) -> (~[@pat], Option<@pat>, ~[@pat]) { ) -> (~[@pat], Option<@pat>, ~[@pat]) {
let mut before = ~[]; let mut before = ~[];
let mut slice = None; let mut slice = None;
@ -2191,7 +2191,7 @@ pub impl Parser {
} }
} }
let subpat = self.parse_pat(refutable); let subpat = self.parse_pat();
if is_slice { if is_slice {
match subpat { match subpat {
@ast::pat { node: pat_wild, _ } => (), @ast::pat { node: pat_wild, _ } => (),
@ -2214,7 +2214,7 @@ pub impl Parser {
} }
// parse the fields of a struct-like pattern // parse the fields of a struct-like pattern
fn parse_pat_fields(&self, refutable: bool) -> (~[ast::field_pat], bool) { fn parse_pat_fields(&self) -> (~[ast::field_pat], bool) {
let mut fields = ~[]; let mut fields = ~[];
let mut etc = false; let mut etc = false;
let mut first = true; let mut first = true;
@ -2244,7 +2244,7 @@ pub impl Parser {
let subpat; let subpat;
if *self.token == token::COLON { if *self.token == token::COLON {
self.bump(); self.bump();
subpat = self.parse_pat(refutable); subpat = self.parse_pat();
} else { } else {
subpat = @ast::pat { subpat = @ast::pat {
id: self.get_id(), id: self.get_id(),
@ -2257,10 +2257,8 @@ pub impl Parser {
return (fields, etc); return (fields, etc);
} }
// parse a pattern. The 'refutable' argument // parse a pattern.
// appears to control whether the binding_mode fn parse_pat(&self) -> @pat {
// 'bind_infer' or 'bind_by_copy' is used.
fn parse_pat(&self, refutable: bool) -> @pat {
maybe_whole!(self, nt_pat); maybe_whole!(self, nt_pat);
let lo = self.span.lo; let lo = self.span.lo;
@ -2272,7 +2270,7 @@ pub impl Parser {
// parse @pat // parse @pat
token::AT => { token::AT => {
self.bump(); self.bump();
let sub = self.parse_pat(refutable); let sub = self.parse_pat();
hi = sub.span.hi; hi = sub.span.hi;
// HACK: parse @"..." as a literal of a vstore @str // HACK: parse @"..." as a literal of a vstore @str
pat = match sub.node { pat = match sub.node {
@ -2295,7 +2293,7 @@ pub impl Parser {
token::TILDE => { token::TILDE => {
// parse ~pat // parse ~pat
self.bump(); self.bump();
let sub = self.parse_pat(refutable); let sub = self.parse_pat();
hi = sub.span.hi; hi = sub.span.hi;
// HACK: parse ~"..." as a literal of a vstore ~str // HACK: parse ~"..." as a literal of a vstore ~str
pat = match sub.node { pat = match sub.node {
@ -2319,7 +2317,7 @@ pub impl Parser {
// parse &pat // parse &pat
let lo = self.span.lo; let lo = self.span.lo;
self.bump(); self.bump();
let sub = self.parse_pat(refutable); let sub = self.parse_pat();
hi = sub.span.hi; hi = sub.span.hi;
// HACK: parse &"..." as a literal of a borrowed str // HACK: parse &"..." as a literal of a borrowed str
pat = match sub.node { pat = match sub.node {
@ -2340,7 +2338,7 @@ pub impl Parser {
} }
token::LBRACE => { token::LBRACE => {
self.bump(); self.bump();
let (_, _) = self.parse_pat_fields(refutable); let (_, _) = self.parse_pat_fields();
hi = self.span.hi; hi = self.span.hi;
self.bump(); self.bump();
self.obsolete(*self.span, ObsoleteRecordPattern); self.obsolete(*self.span, ObsoleteRecordPattern);
@ -2358,11 +2356,11 @@ pub impl Parser {
let expr = self.mk_expr(lo, hi, expr_lit(lit)); let expr = self.mk_expr(lo, hi, expr_lit(lit));
pat = pat_lit(expr); pat = pat_lit(expr);
} else { } else {
let mut fields = ~[self.parse_pat(refutable)]; let mut fields = ~[self.parse_pat()];
if self.look_ahead(1) != token::RPAREN { if self.look_ahead(1) != token::RPAREN {
while *self.token == token::COMMA { while *self.token == token::COMMA {
self.bump(); self.bump();
fields.push(self.parse_pat(refutable)); fields.push(self.parse_pat());
} }
} }
if fields.len() == 1 { self.expect(&token::COMMA); } if fields.len() == 1 { self.expect(&token::COMMA); }
@ -2375,7 +2373,7 @@ pub impl Parser {
// parse [pat,pat,...] as vector pattern // parse [pat,pat,...] as vector pattern
self.bump(); self.bump();
let (before, slice, after) = let (before, slice, after) =
self.parse_pat_vec_elements(refutable); self.parse_pat_vec_elements();
hi = self.span.hi; hi = self.span.hi;
self.expect(&token::RBRACKET); self.expect(&token::RBRACKET);
pat = ast::pat_vec(before, slice, after); pat = ast::pat_vec(before, slice, after);
@ -2405,15 +2403,13 @@ pub impl Parser {
} else if self.eat_keyword(keywords::Ref) { } else if self.eat_keyword(keywords::Ref) {
// parse ref pat // parse ref pat
let mutbl = self.parse_mutability(); let mutbl = self.parse_mutability();
pat = self.parse_pat_ident(refutable, bind_by_ref(mutbl)); pat = self.parse_pat_ident(bind_by_ref(mutbl));
} else if self.eat_keyword(keywords::Copy) { } else if self.eat_keyword(keywords::Copy) {
// parse copy pat // parse copy pat
pat = self.parse_pat_ident(refutable, bind_by_copy); self.warn("copy keyword in patterns no longer has any effect, \
remove it");
pat = self.parse_pat_ident(bind_infer);
} else { } else {
// XXX---refutable match bindings should work same as let
let binding_mode =
if refutable {bind_infer} else {bind_by_copy};
let can_be_enum_or_struct; let can_be_enum_or_struct;
match self.look_ahead(1) { match self.look_ahead(1) {
token::LPAREN | token::LBRACKET | token::LT | token::LPAREN | token::LBRACKET | token::LT |
@ -2434,12 +2430,12 @@ pub impl Parser {
let sub; let sub;
if self.eat(&token::AT) { if self.eat(&token::AT) {
// parse foo @ pat // parse foo @ pat
sub = Some(self.parse_pat(refutable)); sub = Some(self.parse_pat());
} else { } else {
// or just foo // or just foo
sub = None; sub = None;
} }
pat = pat_ident(binding_mode, name, sub); pat = pat_ident(bind_infer, name, sub);
} else { } else {
// parse an enum pat // parse an enum pat
let enum_path = self.parse_path_with_tps(true); let enum_path = self.parse_path_with_tps(true);
@ -2447,7 +2443,7 @@ pub impl Parser {
token::LBRACE => { token::LBRACE => {
self.bump(); self.bump();
let (fields, etc) = let (fields, etc) =
self.parse_pat_fields(refutable); self.parse_pat_fields();
self.bump(); self.bump();
pat = pat_struct(enum_path, fields, etc); pat = pat_struct(enum_path, fields, etc);
} }
@ -2468,7 +2464,7 @@ pub impl Parser {
seq_sep_trailing_disallowed( seq_sep_trailing_disallowed(
token::COMMA token::COMMA
), ),
|p| p.parse_pat(refutable) |p| p.parse_pat()
); );
pat = pat_enum(enum_path, Some(args)); pat = pat_enum(enum_path, Some(args));
} }
@ -2478,7 +2474,7 @@ pub impl Parser {
// it could still be either an enum // it could still be either an enum
// or an identifier pattern, resolve // or an identifier pattern, resolve
// will sort it out: // will sort it out:
pat = pat_ident(binding_mode, pat = pat_ident(bind_infer,
enum_path, enum_path,
None); None);
} else { } else {
@ -2500,7 +2496,6 @@ pub impl Parser {
// used by the copy foo and ref foo patterns to give a good // used by the copy foo and ref foo patterns to give a good
// error message when parsing mistakes like ref foo(a,b) // error message when parsing mistakes like ref foo(a,b)
fn parse_pat_ident(&self, fn parse_pat_ident(&self,
refutable: bool,
binding_mode: ast::binding_mode) binding_mode: ast::binding_mode)
-> ast::pat_ { -> ast::pat_ {
if !is_plain_ident(&*self.token) { if !is_plain_ident(&*self.token) {
@ -2510,7 +2505,7 @@ pub impl Parser {
// why a path here, and not just an identifier? // why a path here, and not just an identifier?
let name = self.parse_path_without_tps(); let name = self.parse_path_without_tps();
let sub = if self.eat(&token::AT) { let sub = if self.eat(&token::AT) {
Some(self.parse_pat(refutable)) Some(self.parse_pat())
} else { } else {
None None
}; };
@ -2533,7 +2528,7 @@ pub impl Parser {
// parse a local variable declaration // parse a local variable declaration
fn parse_local(&self, is_mutbl: bool) -> @local { fn parse_local(&self, is_mutbl: bool) -> @local {
let lo = self.span.lo; let lo = self.span.lo;
let pat = self.parse_pat(false); let pat = self.parse_pat();
let mut ty = @Ty { let mut ty = @Ty {
id: self.get_id(), id: self.get_id(),
node: ty_infer, node: ty_infer,
@ -2760,7 +2755,7 @@ pub impl Parser {
match stmt.node { match stmt.node {
stmt_expr(e, stmt_id) => { stmt_expr(e, stmt_id) => {
// expression without semicolon // expression without semicolon
match *self.token { match copy *self.token {
token::SEMI => { token::SEMI => {
self.bump(); self.bump();
stmts.push(@codemap::spanned { stmts.push(@codemap::spanned {
@ -2770,7 +2765,7 @@ pub impl Parser {
token::RBRACE => { token::RBRACE => {
expr = Some(e); expr = Some(e);
} }
copy t => { t => {
if classify::stmt_ends_with_semi(stmt) { if classify::stmt_ends_with_semi(stmt) {
self.fatal( self.fatal(
fmt!( fmt!(
@ -2880,7 +2875,7 @@ pub impl Parser {
token::MOD_SEP | token::IDENT(*) => { token::MOD_SEP | token::IDENT(*) => {
let obsolete_bound = match *self.token { let obsolete_bound = match *self.token {
token::MOD_SEP => false, token::MOD_SEP => false,
token::IDENT(copy sid, _) => { token::IDENT(sid, _) => {
match *self.id_to_str(sid) { match *self.id_to_str(sid) {
~"send" | ~"send" |
~"copy" | ~"copy" |

View file

@ -1537,9 +1537,6 @@ pub fn print_pat(s: @ps, pat: @ast::pat, refutable: bool) {
word_nbsp(s, "ref"); word_nbsp(s, "ref");
print_mutability(s, mutbl); print_mutability(s, mutbl);
} }
ast::bind_by_copy => {
word_nbsp(s, "copy");
}
ast::bind_infer => {} ast::bind_infer => {}
} }
} }