Remove copy bindings from patterns.
This commit is contained in:
parent
5209709e46
commit
7a1a40890d
34 changed files with 176 additions and 201 deletions
|
@ -35,13 +35,13 @@ enum TreeNode<K, V> {
|
|||
pub fn init<K, V>() -> Treemap<K, V> { @Empty }
|
||||
|
||||
/// 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 {
|
||||
@Empty => Node(@k, @v, @Empty, @Empty),
|
||||
@Node(@copy kk, vv, left, right) => cond!(
|
||||
(k < kk) { Node(@kk, vv, insert(left, k, v), right) }
|
||||
(k == kk) { Node(@kk, @v, left, right) }
|
||||
_ { Node(@kk, vv, left, insert(right, k, v)) }
|
||||
@Node(kk, vv, left, right) => cond!(
|
||||
(k < *kk) { Node(kk, vv, insert(left, k, v), right) }
|
||||
(k == *kk) { Node(kk, @v, left, right) }
|
||||
_ { 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> {
|
||||
match *m {
|
||||
Empty => None,
|
||||
Node(@ref kk, @copy v, left, right) => cond!(
|
||||
(k == *kk) { Some(v) }
|
||||
Node(kk, v, left, right) => cond!(
|
||||
(k == *kk) { Some(copy *v) }
|
||||
(k < *kk) { find(left, k) }
|
||||
_ { find(right, k) }
|
||||
)
|
||||
|
|
|
@ -171,7 +171,7 @@ fn is_arg(arg: &str) -> bool {
|
|||
fn name_str(nm: &Name) -> ~str {
|
||||
return match *nm {
|
||||
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
|
||||
*/
|
||||
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 {
|
||||
for names.each |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] {
|
||||
let mut acc: ~[~str] = ~[];
|
||||
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;
|
||||
}
|
||||
|
@ -429,7 +429,7 @@ pub fn opt_maybe_str(mm: &Matches, nm: &str) -> Option<~str> {
|
|||
let vals = opt_vals(mm, nm);
|
||||
if vec::len::<Optval>(vals) == 0u { return None::<~str>; }
|
||||
return match vals[0] {
|
||||
Val(copy s) => Some(s),
|
||||
Val(ref s) => Some(copy *s),
|
||||
_ => 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> {
|
||||
let vals = opt_vals(mm, nm);
|
||||
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)) }
|
||||
}
|
||||
|
||||
|
@ -701,7 +701,7 @@ mod tests {
|
|||
let opts = ~[reqopt("test")];
|
||||
let rs = getopts(args, opts);
|
||||
match rs {
|
||||
Err(copy f) => check_fail_type(f, OptionMissing_),
|
||||
Err(f) => check_fail_type(f, OptionMissing_),
|
||||
_ => fail!()
|
||||
}
|
||||
}
|
||||
|
@ -712,7 +712,7 @@ mod tests {
|
|||
let opts = ~[reqopt("test")];
|
||||
let rs = getopts(args, opts);
|
||||
match rs {
|
||||
Err(copy f) => check_fail_type(f, ArgumentMissing_),
|
||||
Err(f) => check_fail_type(f, ArgumentMissing_),
|
||||
_ => fail!()
|
||||
}
|
||||
}
|
||||
|
@ -723,7 +723,7 @@ mod tests {
|
|||
let opts = ~[reqopt("test")];
|
||||
let rs = getopts(args, opts);
|
||||
match rs {
|
||||
Err(copy f) => check_fail_type(f, OptionDuplicated_),
|
||||
Err(f) => check_fail_type(f, OptionDuplicated_),
|
||||
_ => fail!()
|
||||
}
|
||||
}
|
||||
|
@ -748,7 +748,7 @@ mod tests {
|
|||
let opts = ~[reqopt("t")];
|
||||
let rs = getopts(args, opts);
|
||||
match rs {
|
||||
Err(copy f) => check_fail_type(f, OptionMissing_),
|
||||
Err(f) => check_fail_type(f, OptionMissing_),
|
||||
_ => fail!()
|
||||
}
|
||||
}
|
||||
|
@ -759,7 +759,7 @@ mod tests {
|
|||
let opts = ~[reqopt("t")];
|
||||
let rs = getopts(args, opts);
|
||||
match rs {
|
||||
Err(copy f) => check_fail_type(f, ArgumentMissing_),
|
||||
Err(f) => check_fail_type(f, ArgumentMissing_),
|
||||
_ => fail!()
|
||||
}
|
||||
}
|
||||
|
@ -770,7 +770,7 @@ mod tests {
|
|||
let opts = ~[reqopt("t")];
|
||||
let rs = getopts(args, opts);
|
||||
match rs {
|
||||
Err(copy f) => check_fail_type(f, OptionDuplicated_),
|
||||
Err(f) => check_fail_type(f, OptionDuplicated_),
|
||||
_ => fail!()
|
||||
}
|
||||
}
|
||||
|
@ -808,7 +808,7 @@ mod tests {
|
|||
let opts = ~[optopt("test")];
|
||||
let rs = getopts(args, opts);
|
||||
match rs {
|
||||
Err(copy f) => check_fail_type(f, ArgumentMissing_),
|
||||
Err(f) => check_fail_type(f, ArgumentMissing_),
|
||||
_ => fail!()
|
||||
}
|
||||
}
|
||||
|
@ -819,7 +819,7 @@ mod tests {
|
|||
let opts = ~[optopt("test")];
|
||||
let rs = getopts(args, opts);
|
||||
match rs {
|
||||
Err(copy f) => check_fail_type(f, OptionDuplicated_),
|
||||
Err(f) => check_fail_type(f, OptionDuplicated_),
|
||||
_ => fail!()
|
||||
}
|
||||
}
|
||||
|
@ -855,7 +855,7 @@ mod tests {
|
|||
let opts = ~[optopt("t")];
|
||||
let rs = getopts(args, opts);
|
||||
match rs {
|
||||
Err(copy f) => check_fail_type(f, ArgumentMissing_),
|
||||
Err(f) => check_fail_type(f, ArgumentMissing_),
|
||||
_ => fail!()
|
||||
}
|
||||
}
|
||||
|
@ -866,7 +866,7 @@ mod tests {
|
|||
let opts = ~[optopt("t")];
|
||||
let rs = getopts(args, opts);
|
||||
match rs {
|
||||
Err(copy f) => check_fail_type(f, OptionDuplicated_),
|
||||
Err(f) => check_fail_type(f, OptionDuplicated_),
|
||||
_ => fail!()
|
||||
}
|
||||
}
|
||||
|
@ -901,7 +901,7 @@ mod tests {
|
|||
let opts = ~[optflag("test")];
|
||||
let rs = getopts(args, opts);
|
||||
match rs {
|
||||
Err(copy f) => {
|
||||
Err(f) => {
|
||||
error!(fail_str(copy f));
|
||||
check_fail_type(f, UnexpectedArgument_);
|
||||
}
|
||||
|
@ -915,7 +915,7 @@ mod tests {
|
|||
let opts = ~[optflag("test")];
|
||||
let rs = getopts(args, opts);
|
||||
match rs {
|
||||
Err(copy f) => check_fail_type(f, OptionDuplicated_),
|
||||
Err(f) => check_fail_type(f, OptionDuplicated_),
|
||||
_ => fail!()
|
||||
}
|
||||
}
|
||||
|
@ -963,7 +963,7 @@ mod tests {
|
|||
let opts = ~[optflag("t")];
|
||||
let rs = getopts(args, opts);
|
||||
match rs {
|
||||
Err(copy f) => check_fail_type(f, OptionDuplicated_),
|
||||
Err(f) => check_fail_type(f, OptionDuplicated_),
|
||||
_ => fail!()
|
||||
}
|
||||
}
|
||||
|
@ -1066,7 +1066,7 @@ mod tests {
|
|||
let opts = ~[optmulti("test")];
|
||||
let rs = getopts(args, opts);
|
||||
match rs {
|
||||
Err(copy f) => check_fail_type(f, ArgumentMissing_),
|
||||
Err(f) => check_fail_type(f, ArgumentMissing_),
|
||||
_ => fail!()
|
||||
}
|
||||
}
|
||||
|
@ -1119,7 +1119,7 @@ mod tests {
|
|||
let opts = ~[optmulti("t")];
|
||||
let rs = getopts(args, opts);
|
||||
match rs {
|
||||
Err(copy f) => check_fail_type(f, ArgumentMissing_),
|
||||
Err(f) => check_fail_type(f, ArgumentMissing_),
|
||||
_ => fail!()
|
||||
}
|
||||
}
|
||||
|
@ -1147,7 +1147,7 @@ mod tests {
|
|||
let opts = ~[optmulti("t")];
|
||||
let rs = getopts(args, opts);
|
||||
match rs {
|
||||
Err(copy f) => check_fail_type(f, UnrecognizedOption_),
|
||||
Err(f) => check_fail_type(f, UnrecognizedOption_),
|
||||
_ => fail!()
|
||||
}
|
||||
}
|
||||
|
@ -1158,7 +1158,7 @@ mod tests {
|
|||
let opts = ~[optmulti("test")];
|
||||
let rs = getopts(args, opts);
|
||||
match rs {
|
||||
Err(copy f) => check_fail_type(f, UnrecognizedOption_),
|
||||
Err(f) => check_fail_type(f, UnrecognizedOption_),
|
||||
_ => fail!()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1384,7 +1384,7 @@ mod tests {
|
|||
|
||||
for items.each |item| {
|
||||
match *item {
|
||||
(copy key, copy value) => { d.insert(key, value); },
|
||||
(ref key, ref value) => { d.insert(copy *key, copy *value); },
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ pub fn tail<T:Copy>(ls: @List<T>) -> @List<T> {
|
|||
/// Returns the first element of a list
|
||||
pub fn head<T:Copy>(ls: @List<T>) -> T {
|
||||
match *ls {
|
||||
Cons(copy hd, _) => hd,
|
||||
Cons(ref hd, _) => copy *hd,
|
||||
// makes me sad
|
||||
_ => 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> {
|
||||
match *l {
|
||||
Nil => return m,
|
||||
Cons(copy x, xs) => {
|
||||
Cons(ref x, xs) => {
|
||||
let rest = append(xs, m);
|
||||
return @Cons(x, rest);
|
||||
return @Cons(copy *x, rest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -278,7 +278,7 @@ pub mod v6 {
|
|||
pub fn parse_addr(ip: &str) -> IpAddr {
|
||||
match try_parse_addr(ip) {
|
||||
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> {
|
||||
|
|
|
@ -595,7 +595,7 @@ pub fn accept(new_conn: TcpNewConnection)
|
|||
}
|
||||
// UNSAFE LIBUV INTERACTION END
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -223,7 +223,7 @@ pub fn run_tests_console(opts: &TestOpts,
|
|||
}
|
||||
TeWait(ref test) => st.out.write_str(
|
||||
fmt!("test %s ... ", test.name.to_str())),
|
||||
TeResult(copy test, result) => {
|
||||
TeResult(test, result) => {
|
||||
match st.log_out {
|
||||
Some(f) => write_log(f, copy result, &test),
|
||||
None => ()
|
||||
|
@ -504,9 +504,8 @@ pub fn filter_tests(
|
|||
filtered = if opts.filter.is_none() {
|
||||
filtered
|
||||
} else {
|
||||
let filter_str =
|
||||
match opts.filter {
|
||||
option::Some(copy f) => f,
|
||||
let filter_str = match opts.filter {
|
||||
option::Some(ref f) => copy *f,
|
||||
option::None => ~""
|
||||
};
|
||||
|
||||
|
@ -866,7 +865,7 @@ mod tests {
|
|||
fn first_free_arg_should_be_a_filter() {
|
||||
let args = ~[~"progname", ~"filter"];
|
||||
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")
|
||||
};
|
||||
assert!("filter" == (copy opts.filter).get());
|
||||
|
@ -876,7 +875,7 @@ mod tests {
|
|||
fn parse_ignored_flag() {
|
||||
let args = ~[~"progname", ~"filter", ~"--ignored"];
|
||||
let opts = match parse_opts(args) {
|
||||
either::Left(copy o) => o,
|
||||
either::Left(o) => o,
|
||||
_ => fail!("Malformed arg in parse_ignored_flag")
|
||||
};
|
||||
assert!((opts.run_ignored));
|
||||
|
|
|
@ -275,10 +275,12 @@ priv fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {
|
|||
let mut i = 0u;
|
||||
let len = strs.len();
|
||||
while i < len {
|
||||
let &(needle, value) = &strs[i];
|
||||
|
||||
if match_str(ss, pos, needle) {
|
||||
return Some((value, pos + str::len(needle)));
|
||||
match strs[i] { // can't use let due to stage0 bugs
|
||||
(ref needle, value) => {
|
||||
if match_str(ss, pos, *needle) {
|
||||
return Some((value, pos + str::len(*needle)));
|
||||
}
|
||||
}
|
||||
}
|
||||
i += 1u;
|
||||
}
|
||||
|
@ -1007,7 +1009,7 @@ mod tests {
|
|||
== Err(~"Invalid time"));
|
||||
|
||||
match strptime("Fri Feb 13 15:31:30 2009", format) {
|
||||
Err(copy e) => fail!(e),
|
||||
Err(e) => fail!(e),
|
||||
Ok(ref tm) => {
|
||||
assert!(tm.tm_sec == 30_i32);
|
||||
assert!(tm.tm_min == 31_i32);
|
||||
|
@ -1027,7 +1029,7 @@ mod tests {
|
|||
fn test(s: &str, format: &str) -> bool {
|
||||
match strptime(s, format) {
|
||||
Ok(ref tm) => tm.strftime(format) == str::to_owned(s),
|
||||
Err(copy e) => fail!(e)
|
||||
Err(e) => fail!(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -375,8 +375,8 @@ pub mod write {
|
|||
|
||||
pub fn run_ndk(sess: Session, assembly: &Path, object: &Path) {
|
||||
let cc_prog: ~str = match &sess.opts.android_cross_path {
|
||||
&Some(copy path) => {
|
||||
fmt!("%s/bin/arm-linux-androideabi-gcc", path)
|
||||
&Some(ref path) => {
|
||||
fmt!("%s/bin/arm-linux-androideabi-gcc", *path)
|
||||
}
|
||||
&None => {
|
||||
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,
|
||||
// so we add a condition to make it use gcc.
|
||||
let cc_prog: ~str = match sess.opts.linker {
|
||||
Some(copy linker) => linker,
|
||||
Some(ref linker) => copy *linker,
|
||||
None => {
|
||||
if sess.targ_cfg.os == session::os_android {
|
||||
match &sess.opts.android_cross_path {
|
||||
&Some(copy path) => {
|
||||
fmt!("%s/bin/arm-linux-androideabi-gcc", path)
|
||||
&Some(ref path) => {
|
||||
fmt!("%s/bin/arm-linux-androideabi-gcc", *path)
|
||||
}
|
||||
&None => {
|
||||
sess.fatal("need Android NDK path for linking \
|
||||
|
|
|
@ -956,8 +956,8 @@ mod test {
|
|||
fn test_switch_implies_cfg_test() {
|
||||
let matches =
|
||||
&match getopts([~"--test"], optgroups()) {
|
||||
Ok(copy m) => m,
|
||||
Err(copy f) => fail!("test_switch_implies_cfg_test: %s", getopts::fail_str(f))
|
||||
Ok(m) => m,
|
||||
Err(f) => fail!("test_switch_implies_cfg_test: %s", getopts::fail_str(f))
|
||||
};
|
||||
let sessopts = build_session_options(
|
||||
@~"rustc", matches, diagnostic::emit);
|
||||
|
@ -972,8 +972,8 @@ mod test {
|
|||
fn test_switch_implies_cfg_test_unless_cfg_test() {
|
||||
let matches =
|
||||
&match getopts([~"--test", ~"--cfg=test"], optgroups()) {
|
||||
Ok(copy m) => m,
|
||||
Err(copy f) => {
|
||||
Ok(m) => m,
|
||||
Err(f) => {
|
||||
fail!("test_switch_implies_cfg_test_unless_cfg_test: %s", getopts::fail_str(f));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -141,10 +141,10 @@ fn visit_crate(e: @mut Env, c: &ast::crate) {
|
|||
|
||||
fn visit_view_item(e: @mut Env, i: @ast::view_item) {
|
||||
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: %?",
|
||||
ident, meta_items);
|
||||
let cnum = resolve_crate(e, ident, meta_items, @~"", i.span);
|
||||
ident, *meta_items);
|
||||
let cnum = resolve_crate(e, ident, copy *meta_items, @~"", i.span);
|
||||
cstore::add_extern_mod_stmt_cnum(e.cstore, id, cnum);
|
||||
}
|
||||
_ => ()
|
||||
|
|
|
@ -623,7 +623,7 @@ pub impl GatherLoanCtxt {
|
|||
cmt, mutbl, scope_r);
|
||||
}
|
||||
}
|
||||
ast::bind_by_copy | ast::bind_infer => {
|
||||
ast::bind_infer => {
|
||||
// No borrows here, but there may be moves
|
||||
if self.bccx.is_move(pat.id) {
|
||||
gather_moves::gather_move_from_pat(
|
||||
|
|
|
@ -827,7 +827,6 @@ pub fn check_legality_of_move_bindings(cx: @MatchCheckCtxt,
|
|||
for pats.each |pat| {
|
||||
do pat_bindings(def_map, *pat) |bm, id, span, _path| {
|
||||
match bm {
|
||||
bind_by_copy => {}
|
||||
bind_by_ref(_) => {
|
||||
by_ref_span = Some(span);
|
||||
}
|
||||
|
|
|
@ -71,7 +71,6 @@ pub fn check_crate(tcx: ty::ctxt,
|
|||
current_item: -1
|
||||
};
|
||||
let visit = visit::mk_vt(@visit::Visitor {
|
||||
visit_arm: check_arm,
|
||||
visit_expr: check_expr,
|
||||
visit_fn: check_fn,
|
||||
visit_ty: check_ty,
|
||||
|
@ -238,19 +237,6 @@ fn check_fn(
|
|||
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>) {
|
||||
debug!("kind::check_expr(%s)", expr_to_str(e, cx.tcx.sess.intr()));
|
||||
|
||||
|
|
|
@ -576,14 +576,18 @@ pub impl VisitContext {
|
|||
|
||||
do pat_bindings(self.tcx.def_map, pat) |bm, id, _span, _path| {
|
||||
let binding_moves = match bm {
|
||||
bind_by_copy => false,
|
||||
bind_by_ref(_) => false,
|
||||
bind_infer => {
|
||||
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)
|
||||
}
|
||||
};
|
||||
|
||||
debug!("pattern binding %?: bm=%?, binding_moves=%b",
|
||||
id, bm, binding_moves);
|
||||
|
||||
if binding_moves {
|
||||
self.move_maps.moves_map.insert(id);
|
||||
}
|
||||
|
|
|
@ -520,12 +520,12 @@ pub impl NameBindings {
|
|||
type_span: Some(sp)
|
||||
});
|
||||
}
|
||||
Some(copy type_def) => {
|
||||
Some(type_def) => {
|
||||
self.type_def = Some(TypeNsDef {
|
||||
privacy: privacy,
|
||||
module_def: Some(module_),
|
||||
type_span: Some(sp),
|
||||
.. type_def
|
||||
type_def: type_def.type_def
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -577,12 +577,12 @@ pub impl NameBindings {
|
|||
type_span: Some(sp)
|
||||
});
|
||||
}
|
||||
Some(copy type_def) => {
|
||||
Some(type_def) => {
|
||||
self.type_def = Some(TypeNsDef {
|
||||
privacy: privacy,
|
||||
type_def: Some(def),
|
||||
type_span: Some(sp),
|
||||
.. type_def
|
||||
module_def: type_def.module_def
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1566,7 +1566,7 @@ pub impl Resolver {
|
|||
match def {
|
||||
def_mod(def_id) | def_foreign_mod(def_id) => {
|
||||
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) \
|
||||
already created module");
|
||||
module_def.def_id = Some(def_id);
|
||||
|
@ -1745,7 +1745,7 @@ pub impl Resolver {
|
|||
NormalModuleKind,
|
||||
dummy_sp());
|
||||
}
|
||||
Some(copy type_ns_def)
|
||||
Some(type_ns_def)
|
||||
if type_ns_def.module_def.is_none() => {
|
||||
debug!("(building reduced graph for external crate) \
|
||||
autovivifying missing module def %s",
|
||||
|
@ -1812,7 +1812,7 @@ pub impl Resolver {
|
|||
let type_module;
|
||||
match child_name_bindings.type_def {
|
||||
Some(TypeNsDef {
|
||||
module_def: Some(copy module_def),
|
||||
module_def: Some(module_def),
|
||||
_
|
||||
}) => {
|
||||
// We already have a module. This
|
||||
|
@ -2445,7 +2445,7 @@ pub impl Resolver {
|
|||
None => {
|
||||
// Continue.
|
||||
}
|
||||
Some(copy value_target) => {
|
||||
Some(value_target) => {
|
||||
dest_import_resolution.value_target =
|
||||
Some(value_target);
|
||||
}
|
||||
|
@ -2454,7 +2454,7 @@ pub impl Resolver {
|
|||
None => {
|
||||
// Continue.
|
||||
}
|
||||
Some(copy type_target) => {
|
||||
Some(type_target) => {
|
||||
dest_import_resolution.type_target =
|
||||
Some(type_target);
|
||||
}
|
||||
|
@ -2566,7 +2566,7 @@ pub impl Resolver {
|
|||
// Check to see whether there are type bindings, and, if
|
||||
// so, whether there is a module within.
|
||||
match target.bindings.type_def {
|
||||
Some(copy type_def) => {
|
||||
Some(type_def) => {
|
||||
match type_def.module_def {
|
||||
None => {
|
||||
// Not a module.
|
||||
|
@ -5170,12 +5170,6 @@ pub impl Resolver {
|
|||
descr: &str) {
|
||||
match pat_binding_mode {
|
||||
bind_infer => {}
|
||||
bind_by_copy => {
|
||||
self.session.span_err(
|
||||
pat.span,
|
||||
fmt!("cannot use `copy` binding mode with %s",
|
||||
descr));
|
||||
}
|
||||
bind_by_ref(*) => {
|
||||
self.session.span_err(
|
||||
pat.span,
|
||||
|
@ -5316,7 +5310,7 @@ pub fn resolve_crate(session: Session,
|
|||
-> CrateMap {
|
||||
let resolver = @mut Resolver(session, lang_items, crate);
|
||||
resolver.resolve();
|
||||
let @Resolver{def_map, export_map2, trait_map, _} = resolver;
|
||||
let Resolver{def_map, export_map2, trait_map, _} = copy *resolver;
|
||||
CrateMap {
|
||||
def_map: def_map,
|
||||
exp_map2: export_map2,
|
||||
|
|
|
@ -1640,7 +1640,7 @@ fn create_bindings_map(bcx: block, pat: @ast::pat) -> BindingsMap {
|
|||
|
||||
let llmatch, trmode;
|
||||
match bm {
|
||||
ast::bind_by_copy | ast::bind_infer => {
|
||||
ast::bind_infer => {
|
||||
// in this case, the final type of the variable will be T,
|
||||
// but during matching we need to store a *T as explained
|
||||
// above
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -308,7 +308,7 @@ pub impl CoherenceChecker {
|
|||
implementation =
|
||||
self.create_impl_from_item(item);
|
||||
}
|
||||
Some(copy existing_implementation) => {
|
||||
Some(existing_implementation) => {
|
||||
implementation = existing_implementation;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1933,7 +1933,7 @@ mod tests {
|
|||
#[test]
|
||||
fn file_reader_not_exist() {
|
||||
match io::file_reader(&Path("not a file")) {
|
||||
result::Err(copy e) => {
|
||||
result::Err(e) => {
|
||||
assert_eq!(e, ~"error opening not a file");
|
||||
}
|
||||
result::Ok(_) => fail!()
|
||||
|
@ -1974,7 +1974,7 @@ mod tests {
|
|||
#[test]
|
||||
fn file_writer_bad_name() {
|
||||
match io::file_writer(&Path("?/?"), []) {
|
||||
result::Err(copy e) => {
|
||||
result::Err(e) => {
|
||||
assert!(str::starts_with(e, "error opening"));
|
||||
}
|
||||
result::Ok(_) => fail!()
|
||||
|
@ -1984,7 +1984,7 @@ mod tests {
|
|||
#[test]
|
||||
fn buffered_file_writer_bad_name() {
|
||||
match io::buffered_file_writer(&Path("?/?")) {
|
||||
result::Err(copy e) => {
|
||||
result::Err(e) => {
|
||||
assert!(str::starts_with(e, "error opening"));
|
||||
}
|
||||
result::Ok(_) => fail!()
|
||||
|
|
|
@ -341,7 +341,7 @@ pub impl<T:Copy> Option<T> {
|
|||
#[inline(always)]
|
||||
fn get(self) -> T {
|
||||
match self {
|
||||
Some(copy x) => return x,
|
||||
Some(x) => return x,
|
||||
None => fail!("option::get none")
|
||||
}
|
||||
}
|
||||
|
@ -349,7 +349,7 @@ pub impl<T:Copy> Option<T> {
|
|||
/// Returns the contained value or a default
|
||||
#[inline(always)]
|
||||
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.
|
||||
|
@ -366,7 +366,7 @@ pub impl<T:Copy + Zero> Option<T> {
|
|||
/// Returns the contained value or zero (for this type)
|
||||
#[inline(always)]
|
||||
fn get_or_zero(self) -> T {
|
||||
match self { Some(copy x) => x, None => Zero::zero() }
|
||||
match self { Some(x) => x, None => Zero::zero() }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -774,9 +774,9 @@ impl GenericPath for WindowsPath {
|
|||
|
||||
/* if rhs has a host set, then the whole thing wins */
|
||||
match other.host {
|
||||
Some(copy host) => {
|
||||
Some(ref host) => {
|
||||
return WindowsPath {
|
||||
host: Some(host),
|
||||
host: Some(copy *host),
|
||||
device: copy other.device,
|
||||
is_absolute: true,
|
||||
components: copy other.components,
|
||||
|
@ -787,10 +787,10 @@ impl GenericPath for WindowsPath {
|
|||
|
||||
/* if rhs has a device set, then a part wins */
|
||||
match other.device {
|
||||
Some(copy device) => {
|
||||
Some(ref device) => {
|
||||
return WindowsPath {
|
||||
host: None,
|
||||
device: Some(device),
|
||||
device: Some(copy *device),
|
||||
is_absolute: true,
|
||||
components: copy other.components,
|
||||
};
|
||||
|
|
|
@ -40,7 +40,7 @@ pub enum Result<T, U> {
|
|||
#[inline(always)]
|
||||
pub fn get<T:Copy,U>(res: &Result<T, U>) -> T {
|
||||
match *res {
|
||||
Ok(copy t) => t,
|
||||
Ok(ref t) => copy *t,
|
||||
Err(ref 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)]
|
||||
pub fn get_err<T, U: Copy>(res: &Result<T, U>) -> U {
|
||||
match *res {
|
||||
Err(copy u) => u,
|
||||
Err(ref u) => copy *u,
|
||||
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>)
|
||||
-> Either<T, U> {
|
||||
match *res {
|
||||
Ok(copy res) => either::Right(res),
|
||||
Err(copy fail_) => either::Left(fail_)
|
||||
Ok(ref res) => either::Right(copy *res),
|
||||
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> {
|
||||
match *res {
|
||||
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)
|
||||
-> Result<T, F> {
|
||||
match *res {
|
||||
Ok(copy t) => Ok(t),
|
||||
Ok(ref t) => Ok(copy *t),
|
||||
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));
|
||||
for ts.each |t| {
|
||||
match op(t) {
|
||||
Ok(copy v) => vs.push(v),
|
||||
Err(copy u) => return Err(u)
|
||||
Ok(v) => vs.push(v),
|
||||
Err(u) => return Err(u)
|
||||
}
|
||||
}
|
||||
return Ok(vs);
|
||||
|
@ -319,8 +319,8 @@ pub fn map_opt<T,U:Copy,V:Copy>(
|
|||
match *o_t {
|
||||
None => Ok(None),
|
||||
Some(ref t) => match op(t) {
|
||||
Ok(copy v) => Ok(Some(v)),
|
||||
Err(copy e) => Err(e)
|
||||
Ok(v) => Ok(Some(v)),
|
||||
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;
|
||||
while i < n {
|
||||
match op(&ss[i],&ts[i]) {
|
||||
Ok(copy v) => vs.push(v),
|
||||
Err(copy u) => return Err(u)
|
||||
Ok(v) => vs.push(v),
|
||||
Err(u) => return Err(u)
|
||||
}
|
||||
i += 1u;
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ pub fn iter_vec2<S,T,U:Copy>(ss: &[S], ts: &[T],
|
|||
while i < n {
|
||||
match op(&ss[i],&ts[i]) {
|
||||
Ok(()) => (),
|
||||
Err(copy u) => return Err(u)
|
||||
Err(u) => return Err(u)
|
||||
}
|
||||
i += 1u;
|
||||
}
|
||||
|
|
|
@ -257,7 +257,6 @@ pub struct field_pat {
|
|||
|
||||
#[deriving(Eq, Encodable, Decodable)]
|
||||
pub enum binding_mode {
|
||||
bind_by_copy,
|
||||
bind_by_ref(mutability),
|
||||
bind_infer
|
||||
}
|
||||
|
@ -265,13 +264,13 @@ pub enum binding_mode {
|
|||
impl to_bytes::IterBytes for binding_mode {
|
||||
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
|
||||
match *self {
|
||||
bind_by_copy => 0u8.iter_bytes(lsb0, f),
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
@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 }
|
||||
}
|
||||
|
||||
|
|
|
@ -560,7 +560,7 @@ impl AstBuilder for @ExtCtxt {
|
|||
self.pat(span, ast::pat_lit(expr))
|
||||
}
|
||||
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,
|
||||
|
|
|
@ -62,11 +62,11 @@ fn iter_bytes_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @
|
|||
Struct(ref 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
|
||||
// iteration function.
|
||||
let discriminant = match variant.node.disr_expr {
|
||||
Some(copy d)=> d,
|
||||
Some(d)=> d,
|
||||
None => cx.expr_uint(span, index)
|
||||
};
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ fn rand_substructure(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr {
|
|||
summary: &Either<uint, ~[ident]>,
|
||||
rand_call: &fn() -> @expr) -> @expr {
|
||||
match *summary {
|
||||
Left(copy count) => {
|
||||
Left(count) => {
|
||||
if count == 0 {
|
||||
cx.expr_ident(span, ctor_ident)
|
||||
} else {
|
||||
|
|
|
@ -58,8 +58,8 @@ pub fn expand_file(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree])
|
|||
base::check_zero_tts(cx, sp, tts, "file!");
|
||||
|
||||
let topmost = topmost_expn_info(cx.backtrace().get());
|
||||
let Loc { file: @FileMap { name: filename, _ }, _ } =
|
||||
cx.codemap().lookup_char_pos(topmost.call_site.lo);
|
||||
let loc = cx.codemap().lookup_char_pos(topmost.call_site.lo);
|
||||
let filename = copy loc.file.name;
|
||||
base::MRExpr(cx.expr_str(topmost.call_site, filename))
|
||||
}
|
||||
|
||||
|
|
|
@ -423,7 +423,7 @@ pub fn parse_nt(p: &Parser, name: &str) -> nonterminal {
|
|||
},
|
||||
"block" => token::nt_block(p.parse_block()),
|
||||
"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()),
|
||||
"ty" => token::nt_ty(p.parse_ty(false /* no need to disambiguate*/)),
|
||||
// this could be handled like a token, since it is one
|
||||
|
|
|
@ -207,8 +207,8 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
|
|||
} else { /* repeat */
|
||||
r.stack.idx = 0u;
|
||||
r.repeat_idx[r.repeat_idx.len() - 1u] += 1u;
|
||||
match r.stack.sep {
|
||||
Some(copy tk) => {
|
||||
match copy r.stack.sep {
|
||||
Some(tk) => {
|
||||
r.cur_tok = tk; /* repeat same span, I guess */
|
||||
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
|
||||
with a `tt_tok`, even though it won't happen */
|
||||
match r.stack.forest[r.stack.idx] {
|
||||
tt_delim(copy tts) => {
|
||||
match copy r.stack.forest[r.stack.idx] {
|
||||
tt_delim(tts) => {
|
||||
r.stack = @mut TtFrame {
|
||||
forest: @mut tts,
|
||||
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
|
||||
}
|
||||
tt_tok(sp, copy tok) => {
|
||||
tt_tok(sp, tok) => {
|
||||
r.cur_span = sp;
|
||||
r.cur_tok = tok;
|
||||
r.stack.idx += 1u;
|
||||
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);
|
||||
match lockstep_iter_size(&t, r) {
|
||||
lis_unconstrained => {
|
||||
|
|
|
@ -487,7 +487,7 @@ mod test {
|
|||
let parser = string_to_parser(@~"b");
|
||||
assert_eq!(parser.parse_pat(false),
|
||||
@ast::pat{id:1, // fixme
|
||||
node: ast::pat_ident(ast::bind_by_copy,
|
||||
node: ast::pat_ident(ast::bind_infer,
|
||||
@ast::Path{
|
||||
span:sp(0,1),
|
||||
global:false,
|
||||
|
@ -516,7 +516,7 @@ mod test {
|
|||
2),
|
||||
span:sp(4,7)},
|
||||
pat: @ast::pat{id:1,
|
||||
node: ast::pat_ident(ast::bind_by_copy,
|
||||
node: ast::pat_ident(ast::bind_infer,
|
||||
@ast::Path{
|
||||
span:sp(0,1),
|
||||
global:false,
|
||||
|
@ -553,7 +553,7 @@ mod test {
|
|||
span:sp(10,13)},
|
||||
pat: @ast::pat{id:1, // fixme
|
||||
node: ast::pat_ident(
|
||||
ast::bind_by_copy,
|
||||
ast::bind_infer,
|
||||
@ast::Path{
|
||||
span:sp(6,7),
|
||||
global:false,
|
||||
|
|
|
@ -18,7 +18,7 @@ use ast::{TyBareFn, TyClosure};
|
|||
use ast::{RegionTyParamBound, TraitTyParamBound};
|
||||
use ast::{provided, public, purity};
|
||||
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::{crate, crate_cfg, decl, decl_item};
|
||||
use ast::{decl_local, default_blk, deref, div, enum_def, explicit_self};
|
||||
|
@ -131,11 +131,11 @@ at INTERPOLATED tokens */
|
|||
macro_rules! maybe_whole_expr (
|
||||
($p:expr) => (
|
||||
match *($p).token {
|
||||
INTERPOLATED(token::nt_expr(copy e)) => {
|
||||
INTERPOLATED(token::nt_expr(e)) => {
|
||||
$p.bump();
|
||||
return e;
|
||||
}
|
||||
INTERPOLATED(token::nt_path(copy pt)) => {
|
||||
INTERPOLATED(token::nt_path(pt)) => {
|
||||
$p.bump();
|
||||
return $p.mk_expr(
|
||||
($p).span.lo,
|
||||
|
@ -150,8 +150,8 @@ macro_rules! maybe_whole_expr (
|
|||
|
||||
macro_rules! maybe_whole (
|
||||
($p:expr, $constructor:ident) => (
|
||||
match *($p).token {
|
||||
INTERPOLATED(token::$constructor(copy x)) => {
|
||||
match copy *($p).token {
|
||||
INTERPOLATED(token::$constructor(x)) => {
|
||||
$p.bump();
|
||||
return x;
|
||||
}
|
||||
|
@ -159,8 +159,8 @@ macro_rules! maybe_whole (
|
|||
}
|
||||
);
|
||||
(deref $p:expr, $constructor:ident) => (
|
||||
match *($p).token {
|
||||
INTERPOLATED(token::$constructor(copy x)) => {
|
||||
match copy *($p).token {
|
||||
INTERPOLATED(token::$constructor(x)) => {
|
||||
$p.bump();
|
||||
return copy *x;
|
||||
}
|
||||
|
@ -168,8 +168,8 @@ macro_rules! maybe_whole (
|
|||
}
|
||||
);
|
||||
(Some $p:expr, $constructor:ident) => (
|
||||
match *($p).token {
|
||||
INTERPOLATED(token::$constructor(copy x)) => {
|
||||
match copy *($p).token {
|
||||
INTERPOLATED(token::$constructor(x)) => {
|
||||
$p.bump();
|
||||
return Some(x);
|
||||
}
|
||||
|
@ -177,8 +177,8 @@ macro_rules! maybe_whole (
|
|||
}
|
||||
);
|
||||
(iovi $p:expr, $constructor:ident) => (
|
||||
match *($p).token {
|
||||
INTERPOLATED(token::$constructor(copy x)) => {
|
||||
match copy *($p).token {
|
||||
INTERPOLATED(token::$constructor(x)) => {
|
||||
$p.bump();
|
||||
return iovi_item(x);
|
||||
}
|
||||
|
@ -186,8 +186,8 @@ macro_rules! maybe_whole (
|
|||
}
|
||||
);
|
||||
(pair_empty $p:expr, $constructor:ident) => (
|
||||
match *($p).token {
|
||||
INTERPOLATED(token::$constructor(copy x)) => {
|
||||
match copy *($p).token {
|
||||
INTERPOLATED(token::$constructor(x)) => {
|
||||
$p.bump();
|
||||
return (~[], x);
|
||||
}
|
||||
|
@ -825,7 +825,7 @@ pub impl Parser {
|
|||
let pat = if require_name || self.is_named_argument() {
|
||||
self.parse_arg_mode();
|
||||
is_mutbl = self.eat_keyword(keywords::Mut);
|
||||
let pat = self.parse_pat(false);
|
||||
let pat = self.parse_pat();
|
||||
self.expect(&token::COLON);
|
||||
pat
|
||||
} else {
|
||||
|
@ -853,7 +853,7 @@ pub impl Parser {
|
|||
fn parse_fn_block_arg(&self) -> arg_or_capture_item {
|
||||
self.parse_arg_mode();
|
||||
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) {
|
||||
self.parse_ty(false)
|
||||
} else {
|
||||
|
@ -1992,28 +1992,29 @@ pub impl Parser {
|
|||
// them as the lambda arguments
|
||||
let e = self.parse_expr_res(RESTRICT_NO_BAR_OR_DOUBLEBAR_OP);
|
||||
match e.node {
|
||||
expr_call(f, /*bad*/ copy args, NoSugar) => {
|
||||
expr_call(f, ref args, NoSugar) => {
|
||||
let block = self.parse_lambda_block_expr();
|
||||
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
|
||||
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))
|
||||
}
|
||||
expr_method_call(f, i, /*bad*/ copy tps,
|
||||
/*bad*/ copy args, NoSugar) => {
|
||||
expr_method_call(f, i, ref tps, ref args, NoSugar) => {
|
||||
let block = self.parse_lambda_block_expr();
|
||||
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
|
||||
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_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 last_arg = self.mk_expr(block.span.lo, block.span.hi,
|
||||
ctor(block));
|
||||
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_paren(*) => {
|
||||
|
@ -2162,7 +2163,7 @@ pub impl Parser {
|
|||
fn parse_pats(&self) -> ~[@pat] {
|
||||
let mut pats = ~[];
|
||||
loop {
|
||||
pats.push(self.parse_pat(true));
|
||||
pats.push(self.parse_pat());
|
||||
if *self.token == token::BINOP(token::OR) { self.bump(); }
|
||||
else { return pats; }
|
||||
};
|
||||
|
@ -2170,7 +2171,6 @@ pub impl Parser {
|
|||
|
||||
fn parse_pat_vec_elements(
|
||||
&self,
|
||||
refutable: bool
|
||||
) -> (~[@pat], Option<@pat>, ~[@pat]) {
|
||||
let mut before = ~[];
|
||||
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 {
|
||||
match subpat {
|
||||
@ast::pat { node: pat_wild, _ } => (),
|
||||
|
@ -2214,7 +2214,7 @@ pub impl Parser {
|
|||
}
|
||||
|
||||
// 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 etc = false;
|
||||
let mut first = true;
|
||||
|
@ -2244,7 +2244,7 @@ pub impl Parser {
|
|||
let subpat;
|
||||
if *self.token == token::COLON {
|
||||
self.bump();
|
||||
subpat = self.parse_pat(refutable);
|
||||
subpat = self.parse_pat();
|
||||
} else {
|
||||
subpat = @ast::pat {
|
||||
id: self.get_id(),
|
||||
|
@ -2257,10 +2257,8 @@ pub impl Parser {
|
|||
return (fields, etc);
|
||||
}
|
||||
|
||||
// parse a pattern. The 'refutable' argument
|
||||
// appears to control whether the binding_mode
|
||||
// 'bind_infer' or 'bind_by_copy' is used.
|
||||
fn parse_pat(&self, refutable: bool) -> @pat {
|
||||
// parse a pattern.
|
||||
fn parse_pat(&self) -> @pat {
|
||||
maybe_whole!(self, nt_pat);
|
||||
|
||||
let lo = self.span.lo;
|
||||
|
@ -2272,7 +2270,7 @@ pub impl Parser {
|
|||
// parse @pat
|
||||
token::AT => {
|
||||
self.bump();
|
||||
let sub = self.parse_pat(refutable);
|
||||
let sub = self.parse_pat();
|
||||
hi = sub.span.hi;
|
||||
// HACK: parse @"..." as a literal of a vstore @str
|
||||
pat = match sub.node {
|
||||
|
@ -2295,7 +2293,7 @@ pub impl Parser {
|
|||
token::TILDE => {
|
||||
// parse ~pat
|
||||
self.bump();
|
||||
let sub = self.parse_pat(refutable);
|
||||
let sub = self.parse_pat();
|
||||
hi = sub.span.hi;
|
||||
// HACK: parse ~"..." as a literal of a vstore ~str
|
||||
pat = match sub.node {
|
||||
|
@ -2319,7 +2317,7 @@ pub impl Parser {
|
|||
// parse &pat
|
||||
let lo = self.span.lo;
|
||||
self.bump();
|
||||
let sub = self.parse_pat(refutable);
|
||||
let sub = self.parse_pat();
|
||||
hi = sub.span.hi;
|
||||
// HACK: parse &"..." as a literal of a borrowed str
|
||||
pat = match sub.node {
|
||||
|
@ -2340,7 +2338,7 @@ pub impl Parser {
|
|||
}
|
||||
token::LBRACE => {
|
||||
self.bump();
|
||||
let (_, _) = self.parse_pat_fields(refutable);
|
||||
let (_, _) = self.parse_pat_fields();
|
||||
hi = self.span.hi;
|
||||
self.bump();
|
||||
self.obsolete(*self.span, ObsoleteRecordPattern);
|
||||
|
@ -2358,11 +2356,11 @@ pub impl Parser {
|
|||
let expr = self.mk_expr(lo, hi, expr_lit(lit));
|
||||
pat = pat_lit(expr);
|
||||
} else {
|
||||
let mut fields = ~[self.parse_pat(refutable)];
|
||||
let mut fields = ~[self.parse_pat()];
|
||||
if self.look_ahead(1) != token::RPAREN {
|
||||
while *self.token == token::COMMA {
|
||||
self.bump();
|
||||
fields.push(self.parse_pat(refutable));
|
||||
fields.push(self.parse_pat());
|
||||
}
|
||||
}
|
||||
if fields.len() == 1 { self.expect(&token::COMMA); }
|
||||
|
@ -2375,7 +2373,7 @@ pub impl Parser {
|
|||
// parse [pat,pat,...] as vector pattern
|
||||
self.bump();
|
||||
let (before, slice, after) =
|
||||
self.parse_pat_vec_elements(refutable);
|
||||
self.parse_pat_vec_elements();
|
||||
hi = self.span.hi;
|
||||
self.expect(&token::RBRACKET);
|
||||
pat = ast::pat_vec(before, slice, after);
|
||||
|
@ -2405,15 +2403,13 @@ pub impl Parser {
|
|||
} else if self.eat_keyword(keywords::Ref) {
|
||||
// parse ref pat
|
||||
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) {
|
||||
// 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 {
|
||||
// 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;
|
||||
match self.look_ahead(1) {
|
||||
token::LPAREN | token::LBRACKET | token::LT |
|
||||
|
@ -2434,12 +2430,12 @@ pub impl Parser {
|
|||
let sub;
|
||||
if self.eat(&token::AT) {
|
||||
// parse foo @ pat
|
||||
sub = Some(self.parse_pat(refutable));
|
||||
sub = Some(self.parse_pat());
|
||||
} else {
|
||||
// or just foo
|
||||
sub = None;
|
||||
}
|
||||
pat = pat_ident(binding_mode, name, sub);
|
||||
pat = pat_ident(bind_infer, name, sub);
|
||||
} else {
|
||||
// parse an enum pat
|
||||
let enum_path = self.parse_path_with_tps(true);
|
||||
|
@ -2447,7 +2443,7 @@ pub impl Parser {
|
|||
token::LBRACE => {
|
||||
self.bump();
|
||||
let (fields, etc) =
|
||||
self.parse_pat_fields(refutable);
|
||||
self.parse_pat_fields();
|
||||
self.bump();
|
||||
pat = pat_struct(enum_path, fields, etc);
|
||||
}
|
||||
|
@ -2468,7 +2464,7 @@ pub impl Parser {
|
|||
seq_sep_trailing_disallowed(
|
||||
token::COMMA
|
||||
),
|
||||
|p| p.parse_pat(refutable)
|
||||
|p| p.parse_pat()
|
||||
);
|
||||
pat = pat_enum(enum_path, Some(args));
|
||||
}
|
||||
|
@ -2478,7 +2474,7 @@ pub impl Parser {
|
|||
// it could still be either an enum
|
||||
// or an identifier pattern, resolve
|
||||
// will sort it out:
|
||||
pat = pat_ident(binding_mode,
|
||||
pat = pat_ident(bind_infer,
|
||||
enum_path,
|
||||
None);
|
||||
} else {
|
||||
|
@ -2500,7 +2496,6 @@ pub impl Parser {
|
|||
// used by the copy foo and ref foo patterns to give a good
|
||||
// error message when parsing mistakes like ref foo(a,b)
|
||||
fn parse_pat_ident(&self,
|
||||
refutable: bool,
|
||||
binding_mode: ast::binding_mode)
|
||||
-> ast::pat_ {
|
||||
if !is_plain_ident(&*self.token) {
|
||||
|
@ -2510,7 +2505,7 @@ pub impl Parser {
|
|||
// why a path here, and not just an identifier?
|
||||
let name = self.parse_path_without_tps();
|
||||
let sub = if self.eat(&token::AT) {
|
||||
Some(self.parse_pat(refutable))
|
||||
Some(self.parse_pat())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
@ -2533,7 +2528,7 @@ pub impl Parser {
|
|||
// parse a local variable declaration
|
||||
fn parse_local(&self, is_mutbl: bool) -> @local {
|
||||
let lo = self.span.lo;
|
||||
let pat = self.parse_pat(false);
|
||||
let pat = self.parse_pat();
|
||||
let mut ty = @Ty {
|
||||
id: self.get_id(),
|
||||
node: ty_infer,
|
||||
|
@ -2760,7 +2755,7 @@ pub impl Parser {
|
|||
match stmt.node {
|
||||
stmt_expr(e, stmt_id) => {
|
||||
// expression without semicolon
|
||||
match *self.token {
|
||||
match copy *self.token {
|
||||
token::SEMI => {
|
||||
self.bump();
|
||||
stmts.push(@codemap::spanned {
|
||||
|
@ -2770,7 +2765,7 @@ pub impl Parser {
|
|||
token::RBRACE => {
|
||||
expr = Some(e);
|
||||
}
|
||||
copy t => {
|
||||
t => {
|
||||
if classify::stmt_ends_with_semi(stmt) {
|
||||
self.fatal(
|
||||
fmt!(
|
||||
|
@ -2880,7 +2875,7 @@ pub impl Parser {
|
|||
token::MOD_SEP | token::IDENT(*) => {
|
||||
let obsolete_bound = match *self.token {
|
||||
token::MOD_SEP => false,
|
||||
token::IDENT(copy sid, _) => {
|
||||
token::IDENT(sid, _) => {
|
||||
match *self.id_to_str(sid) {
|
||||
~"send" |
|
||||
~"copy" |
|
||||
|
|
|
@ -1537,9 +1537,6 @@ pub fn print_pat(s: @ps, pat: @ast::pat, refutable: bool) {
|
|||
word_nbsp(s, "ref");
|
||||
print_mutability(s, mutbl);
|
||||
}
|
||||
ast::bind_by_copy => {
|
||||
word_nbsp(s, "copy");
|
||||
}
|
||||
ast::bind_infer => {}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue