Skip to content

Commit 2383a9c

Browse files
committed
rollup merge of rust-lang#20099: P1start/parse-more-macro-ops
Closes rust-lang#20093.
2 parents f6438cf + 5cf72ff commit 2383a9c

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2976,14 +2976,17 @@ impl<'a> Parser<'a> {
29762976
/// actually, this seems to be the main entry point for
29772977
/// parsing an arbitrary expression.
29782978
pub fn parse_assign_expr(&mut self) -> P<Expr> {
2979-
let lo = self.span.lo;
29802979
let lhs = self.parse_binops();
2980+
self.parse_assign_expr_with(lhs)
2981+
}
2982+
2983+
pub fn parse_assign_expr_with(&mut self, lhs: P<Expr>) -> P<Expr> {
29812984
let restrictions = self.restrictions & RESTRICTION_NO_STRUCT_LITERAL;
29822985
match self.token {
29832986
token::Eq => {
29842987
self.bump();
29852988
let rhs = self.parse_expr_res(restrictions);
2986-
self.mk_expr(lo, rhs.span.hi, ExprAssign(lhs, rhs))
2989+
self.mk_expr(lhs.span.lo, rhs.span.hi, ExprAssign(lhs, rhs))
29872990
}
29882991
token::BinOpEq(op) => {
29892992
self.bump();
@@ -3001,8 +3004,9 @@ impl<'a> Parser<'a> {
30013004
token::Shr => BiShr
30023005
};
30033006
let rhs_span = rhs.span;
3007+
let span = lhs.span;
30043008
let assign_op = self.mk_assign_op(aop, lhs, rhs);
3005-
self.mk_expr(lo, rhs_span.hi, assign_op)
3009+
self.mk_expr(span.lo, rhs_span.hi, assign_op)
30063010
}
30073011
_ => {
30083012
lhs
@@ -3896,8 +3900,9 @@ impl<'a> Parser<'a> {
38963900
let e = self.mk_mac_expr(span.lo,
38973901
span.hi,
38983902
macro.and_then(|m| m.node));
3899-
let e =
3900-
self.parse_dot_or_call_expr_with(e);
3903+
let e = self.parse_dot_or_call_expr_with(e);
3904+
let e = self.parse_more_binops(e, 0);
3905+
let e = self.parse_assign_expr_with(e);
39013906
self.handle_expression_like_statement(
39023907
e,
39033908
ast::DUMMY_NODE_ID,
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test parsing binary operators after macro invocations.
12+
13+
#![feature(macro_rules)]
14+
15+
macro_rules! id {
16+
($e: expr) => { $e }
17+
}
18+
19+
fn foo() {
20+
id!(1i) + 1;
21+
id![1i] - 1;
22+
id!(1i) * 1;
23+
id![1i] / 1;
24+
id!(1i) % 1;
25+
26+
id!(1i) & 1;
27+
id![1i] | 1;
28+
id!(1i) ^ 1;
29+
30+
let mut x = 1i;
31+
id![x] = 2;
32+
id!(x) += 1;
33+
34+
id!(1f64).clone();
35+
36+
id!([1i, 2, 3])[1];
37+
id![drop](1i);
38+
39+
id!(true) && true;
40+
id![true] || true;
41+
}
42+
43+
fn main() {}

0 commit comments

Comments
 (0)