diff options
| author | bors <bors@rust-lang.org> | 2013-10-27 09:51:21 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-10-27 09:51:21 -0700 |
| commit | 16b8a41531bb0054f05be7a19e0867b8174c83b1 (patch) | |
| tree | 6f41d27ea27c9b34e54a58875131e6a19c16e7cb /src/libsyntax/parse | |
| parent | 950add4e49cc2ac5d60abd6da969392123ddcce0 (diff) | |
| parent | 523a28decc9b165cccded3db754f645ce10c2040 (diff) | |
| download | rust-16b8a41531bb0054f05be7a19e0867b8174c83b1.tar.gz rust-16b8a41531bb0054f05be7a19e0867b8174c83b1.zip | |
auto merge of #10026 : luqmana/rust/mut-pat, r=pcwalton
Fixes #9792.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/parse/obsolete.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 50 |
3 files changed, 17 insertions, 44 deletions
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index fad9eab7542..0de571978a0 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -639,7 +639,7 @@ mod test { assert_eq!(parser.parse_pat(), @ast::Pat{id: ast::DUMMY_NODE_ID, node: ast::PatIdent( - ast::BindInfer, + ast::BindByValue(ast::MutImmutable), ast::Path { span:sp(0,1), global:false, @@ -666,7 +666,6 @@ mod test { id: ast::DUMMY_NODE_ID, node: ast::item_fn(ast::fn_decl{ inputs: ~[ast::arg{ - is_mutbl: false, ty: ast::Ty{id: ast::DUMMY_NODE_ID, node: ast::ty_path(ast::Path{ span:sp(10,13), @@ -685,7 +684,7 @@ mod test { pat: @ast::Pat { id: ast::DUMMY_NODE_ID, node: ast::PatIdent( - ast::BindInfer, + ast::BindByValue(ast::MutImmutable), ast::Path { span:sp(6,7), global:false, diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 8c26793605c..20ad13dace6 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -34,7 +34,6 @@ pub enum ObsoleteSyntax { ObsoleteBareFnType, ObsoleteNamedExternModule, ObsoleteMultipleLocalDecl, - ObsoleteMutWithMultipleBindings, ObsoleteUnsafeExternFn, ObsoleteTraitFuncVisibility, ObsoleteConstPointer, @@ -91,11 +90,6 @@ impl ParserObsoleteMethods for Parser { "instead of e.g. `let a = 1, b = 2`, write \ `let (a, b) = (1, 2)`." ), - ObsoleteMutWithMultipleBindings => ( - "`mut` with multiple bindings", - "use multiple local declarations instead of e.g. `let mut \ - (x, y) = ...`." - ), ObsoleteUnsafeExternFn => ( "unsafe external function", "external functions are always unsafe; remove the `unsafe` \ diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 605e259cf0c..5a5e310e56f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -17,7 +17,7 @@ use ast::{CallSugar, NoSugar, DoSugar}; use ast::{TyBareFn, TyClosure}; use ast::{RegionTyParamBound, TraitTyParamBound}; use ast::{provided, public, purity}; -use ast::{_mod, BiAdd, arg, Arm, Attribute, BindByRef, BindInfer}; +use ast::{_mod, BiAdd, arg, Arm, Attribute, BindByRef, BindByValue}; use ast::{BiBitAnd, BiBitOr, BiBitXor, Block}; use ast::{BlockCheckMode, UnBox}; use ast::{Crate, CrateConfig, Decl, DeclItem}; @@ -1184,15 +1184,8 @@ impl Parser { pub fn is_named_argument(&self) -> bool { let offset = match *self.token { token::BINOP(token::AND) => 1, - token::BINOP(token::MINUS) => 1, token::ANDAND => 1, - token::BINOP(token::PLUS) => { - if self.look_ahead(1, |t| *t == token::BINOP(token::PLUS)) { - 2 - } else { - 1 - } - }, + _ if token::is_keyword(keywords::Mut, self.token) => 1, _ => 0 }; @@ -1210,16 +1203,11 @@ impl Parser { // This version of parse arg doesn't necessarily require // identifier names. pub fn parse_arg_general(&self, require_name: bool) -> arg { - let is_mutbl = self.eat_keyword(keywords::Mut); let pat = if require_name || self.is_named_argument() { debug!("parse_arg_general parse_pat (require_name:{:?})", require_name); let pat = self.parse_pat(); - if is_mutbl && !ast_util::pat_is_ident(pat) { - self.obsolete(*self.span, ObsoleteMutWithMultipleBindings) - } - self.expect(&token::COLON); pat } else { @@ -1232,7 +1220,6 @@ impl Parser { let t = self.parse_ty(false); ast::arg { - is_mutbl: is_mutbl, ty: t, pat: pat, id: ast::DUMMY_NODE_ID, @@ -1246,7 +1233,6 @@ impl Parser { // parse an argument in a lambda header e.g. |arg, arg| pub fn parse_fn_block_arg(&self) -> arg { - let is_mutbl = self.eat_keyword(keywords::Mut); let pat = self.parse_pat(); let t = if self.eat(&token::COLON) { self.parse_ty(false) @@ -1258,7 +1244,6 @@ impl Parser { } }; ast::arg { - is_mutbl: is_mutbl, ty: t, pat: pat, id: ast::DUMMY_NODE_ID @@ -1809,7 +1794,7 @@ impl Parser { return self.mk_mac_expr(lo, hi, mac_invoc_tt(pth, tts, EMPTY_CTXT)); } else if *self.token == token::LBRACE { // This might be a struct literal. - if self.looking_at_record_literal() { + if self.looking_at_struct_literal() { // It's a struct literal. self.bump(); let mut fields = ~[]; @@ -2520,12 +2505,11 @@ impl Parser { } } - // For distingishing between record literals and blocks - fn looking_at_record_literal(&self) -> bool { + // For distingishing between struct literals and blocks + fn looking_at_struct_literal(&self) -> bool { *self.token == token::LBRACE && - (self.look_ahead(1, |t| token::is_keyword(keywords::Mut, t)) || - (self.look_ahead(1, |t| token::is_plain_ident(t)) && - self.look_ahead(2, |t| *t == token::COLON))) + (self.look_ahead(1, |t| token::is_plain_ident(t)) && + self.look_ahead(2, |t| *t == token::COLON)) } fn parse_match_expr(&self) -> @Expr { @@ -2681,7 +2665,7 @@ impl Parser { } else { subpat = @ast::Pat { id: ast::DUMMY_NODE_ID, - node: PatIdent(BindInfer, fieldpath, None), + node: PatIdent(BindByValue(MutImmutable), fieldpath, None), span: *self.last_span }; } @@ -2863,6 +2847,8 @@ impl Parser { } else { pat = PatLit(val); } + } else if self.eat_keyword(keywords::Mut) { + pat = self.parse_pat_ident(BindByValue(MutMutable)); } else if self.eat_keyword(keywords::Ref) { // parse ref pat let mutbl = self.parse_mutability(); @@ -2891,7 +2877,7 @@ impl Parser { // or just foo sub = None; } - pat = PatIdent(BindInfer, name, sub); + pat = PatIdent(BindByValue(MutImmutable), name, sub); } else { // parse an enum pat let enum_path = self.parse_path(LifetimeAndTypesWithColons) @@ -2935,7 +2921,7 @@ impl Parser { // it could still be either an enum // or an identifier pattern, resolve // will sort it out: - pat = PatIdent(BindInfer, + pat = PatIdent(BindByValue(MutImmutable), enum_path, None); } else { @@ -2989,14 +2975,10 @@ impl Parser { } // parse a local variable declaration - fn parse_local(&self, is_mutbl: bool) -> @Local { + fn parse_local(&self) -> @Local { let lo = self.span.lo; let pat = self.parse_pat(); - if is_mutbl && !ast_util::pat_is_ident(pat) { - self.obsolete(*self.span, ObsoleteMutWithMultipleBindings) - } - let mut ty = Ty { id: ast::DUMMY_NODE_ID, node: ty_infer, @@ -3005,7 +2987,6 @@ impl Parser { if self.eat(&token::COLON) { ty = self.parse_ty(false); } let init = self.parse_initializer(); @ast::Local { - is_mutbl: is_mutbl, ty: ty, pat: pat, init: init, @@ -3016,11 +2997,10 @@ impl Parser { // parse a "let" stmt fn parse_let(&self) -> @Decl { - let is_mutbl = self.eat_keyword(keywords::Mut); let lo = self.span.lo; - let local = self.parse_local(is_mutbl); + let local = self.parse_local(); while self.eat(&token::COMMA) { - let _ = self.parse_local(is_mutbl); + let _ = self.parse_local(); self.obsolete(*self.span, ObsoleteMultipleLocalDecl); } return @spanned(lo, self.last_span.hi, DeclLocal(local)); |
