diff options
| author | bors <bors@rust-lang.org> | 2014-09-09 20:16:19 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-09-09 20:16:19 +0000 |
| commit | 651106462c357b71a4ca2c02ba2bfedfc38b0035 (patch) | |
| tree | 79cd7984fb470f273f5907c579a2db5f71296c7e /src/libsyntax | |
| parent | b625d43f8fd2e9a800ca8a419f7d3f5f52604205 (diff) | |
| parent | e5abe15ff55212c60fc4acc9bfc2bc79038507b8 (diff) | |
| download | rust-651106462c357b71a4ca2c02ba2bfedfc38b0035.tar.gz rust-651106462c357b71a4ca2c02ba2bfedfc38b0035.zip | |
auto merge of #17127 : alexcrichton/rust/rollup, r=alexcrichton
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/quote.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/parse/obsolete.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 68 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 2 |
4 files changed, 46 insertions, 33 deletions
diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 0c41db7ecd6..808e671f868 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -766,7 +766,9 @@ fn expand_wrapper(cx: &ExtCtxt, cx.view_use_glob(sp, ast::Inherited, ids_ext(path)) }).collect(); - let stmt_let_ext_cx = cx.stmt_let(sp, false, id_ext("ext_cx"), cx_expr); + // Explicitly borrow to avoid moving from the invoker (#16992) + let cx_expr_borrow = cx.expr_addr_of(sp, cx.expr_deref(sp, cx_expr)); + let stmt_let_ext_cx = cx.stmt_let(sp, false, id_ext("ext_cx"), cx_expr_borrow); cx.expr_block(cx.block_all(sp, uses, vec!(stmt_let_ext_cx), Some(expr))) } diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 5273addf4f5..ec6fd013d08 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -35,6 +35,7 @@ pub enum ObsoleteSyntax { ObsoleteManagedType, ObsoleteManagedExpr, ObsoleteImportRenaming, + ObsoleteSubsliceMatch, } pub trait ParserObsoleteMethods { @@ -87,6 +88,10 @@ impl<'a> ParserObsoleteMethods for parser::Parser<'a> { ObsoleteImportRenaming => ( "`use foo = bar` syntax", "write `use bar as foo` instead" + ), + ObsoleteSubsliceMatch => ( + "subslice match syntax", + "instead of `..xs`, write `xs..` in a pattern" ) }; diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 936cabc54d1..6aff1152f7e 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2858,43 +2858,42 @@ impl<'a> Parser<'a> { let mut before_slice = true; while self.token != token::RBRACKET { - if first { first = false; } - else { self.expect(&token::COMMA); } + if first { + first = false; + } else { + self.expect(&token::COMMA); + } - let mut is_slice = false; if before_slice { if self.token == token::DOTDOT { self.bump(); - is_slice = true; - before_slice = false; - } - } - if is_slice { - if self.token == token::COMMA || self.token == token::RBRACKET { - slice = Some(box(GC) ast::Pat { - id: ast::DUMMY_NODE_ID, - node: PatWild(PatWildMulti), - span: self.span, - }) - } else { - let subpat = self.parse_pat(); - match *subpat { - ast::Pat { node: PatIdent(_, _, _), .. } => { - slice = Some(subpat); - } - ast::Pat { span, .. } => self.span_fatal( - span, "expected an identifier or nothing" - ) + if self.token == token::COMMA || + self.token == token::RBRACKET { + slice = Some(box(GC) ast::Pat { + id: ast::DUMMY_NODE_ID, + node: PatWild(PatWildMulti), + span: self.span, + }); + before_slice = false; + } else { + let _ = self.parse_pat(); + let span = self.span; + self.obsolete(span, ObsoleteSubsliceMatch); } + continue } + } + + let subpat = self.parse_pat(); + if before_slice && self.token == token::DOTDOT { + self.bump(); + slice = Some(subpat); + before_slice = false; + } else if before_slice { + before.push(subpat); } else { - let subpat = self.parse_pat(); - if before_slice { - before.push(subpat); - } else { - after.push(subpat); - } + after.push(subpat); } } @@ -3065,7 +3064,11 @@ impl<'a> Parser<'a> { // These expressions are limited to literals (possibly // preceded by unary-minus) or identifiers. let val = self.parse_literal_maybe_minus(); - if self.eat(&token::DOTDOT) { + if self.token == token::DOTDOT && + self.look_ahead(1, |t| { + *t != token::COMMA && *t != token::RBRACKET + }) { + self.bump(); let end = if is_ident_or_path(&self.token) { let path = self.parse_path(LifetimeAndTypesWithColons) .path; @@ -3106,7 +3109,10 @@ impl<'a> Parser<'a> { } }); - if self.look_ahead(1, |t| *t == token::DOTDOT) { + if self.look_ahead(1, |t| *t == token::DOTDOT) && + self.look_ahead(2, |t| { + *t != token::COMMA && *t != token::RBRACKET + }) { let start = self.parse_expr_res(RESTRICT_NO_BAR_OP); self.eat(&token::DOTDOT); let end = self.parse_expr_res(RESTRICT_NO_BAR_OP); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index d5bc1bfe956..eaeb6aaab8a 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1912,13 +1912,13 @@ impl<'a> State<'a> { |s, p| s.print_pat(&**p))); for p in slice.iter() { if !before.is_empty() { try!(self.word_space(",")); } + try!(self.print_pat(&**p)); match **p { ast::Pat { node: ast::PatWild(ast::PatWildMulti), .. } => { // this case is handled by print_pat } _ => try!(word(&mut self.s, "..")), } - try!(self.print_pat(&**p)); if !after.is_empty() { try!(self.word_space(",")); } } try!(self.commasep(Inconsistent, |
