diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2013-05-29 19:59:33 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2013-05-30 15:20:36 -0400 |
| commit | 7a1a40890d48321c69f66bd07e3a23d5d5ab939a (patch) | |
| tree | 54eb8701f89acc95b05a2de5cfcd5c9be2742a3d /src/libsyntax | |
| parent | 5209709e46ecfac2fd4db527952fe7ef96400801 (diff) | |
| download | rust-7a1a40890d48321c69f66bd07e3a23d5d5ab939a.tar.gz rust-7a1a40890d48321c69f66bd07e3a23d5d5ab939a.zip | |
Remove copy bindings from patterns.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 9 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/iter_bytes.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/rand.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/source_util.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_parser.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/transcribe.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 107 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 3 |
11 files changed, 72 insertions, 81 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index cdd16e5d890..676a57e38da 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -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) + } } } } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index c8cac4ba2d7..deff6dc5ba9 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -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 } } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 2a3c266cfa6..85bebebf0f6 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -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, diff --git a/src/libsyntax/ext/deriving/iter_bytes.rs b/src/libsyntax/ext/deriving/iter_bytes.rs index 64ce6dfbc19..10fb4b8ecd4 100644 --- a/src/libsyntax/ext/deriving/iter_bytes.rs +++ b/src/libsyntax/ext/deriving/iter_bytes.rs @@ -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) }; diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index b2e039786ad..54d31de7c50 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -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 { diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 8a60b239b89..91fad0c22a6 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -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)) } diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 183bc2a77c5..ec63b5a7f74 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -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 diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index cac963727e3..4a6a070df50 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -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 => { diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index eca999231cd..c054bf55274 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -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, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 27dfc2c0a46..29f565851b4 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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" | diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 6a32e535295..f29876b8708 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -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 => {} } } |
