Skip to content

Commit 7f4f79c

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

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

src/libsyntax/parse/parser.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -2966,14 +2966,17 @@ impl<'a> Parser<'a> {
29662966
/// actually, this seems to be the main entry point for
29672967
/// parsing an arbitrary expression.
29682968
pub fn parse_assign_expr(&mut self) -> P<Expr> {
2969-
let lo = self.span.lo;
29702969
let lhs = self.parse_binops();
2970+
self.parse_assign_expr_with(lhs)
2971+
}
2972+
2973+
pub fn parse_assign_expr_with(&mut self, lhs: P<Expr>) -> P<Expr> {
29712974
let restrictions = self.restrictions & RESTRICTION_NO_STRUCT_LITERAL;
29722975
match self.token {
29732976
token::Eq => {
29742977
self.bump();
29752978
let rhs = self.parse_expr_res(restrictions);
2976-
self.mk_expr(lo, rhs.span.hi, ExprAssign(lhs, rhs))
2979+
self.mk_expr(lhs.span.lo, rhs.span.hi, ExprAssign(lhs, rhs))
29772980
}
29782981
token::BinOpEq(op) => {
29792982
self.bump();
@@ -2991,8 +2994,9 @@ impl<'a> Parser<'a> {
29912994
token::Shr => BiShr
29922995
};
29932996
let rhs_span = rhs.span;
2997+
let span = lhs.span;
29942998
let assign_op = self.mk_assign_op(aop, lhs, rhs);
2995-
self.mk_expr(lo, rhs_span.hi, assign_op)
2999+
self.mk_expr(span.lo, rhs_span.hi, assign_op)
29963000
}
29973001
_ => {
29983002
lhs
@@ -3886,8 +3890,9 @@ impl<'a> Parser<'a> {
38863890
let e = self.mk_mac_expr(span.lo,
38873891
span.hi,
38883892
macro.and_then(|m| m.node));
3889-
let e =
3890-
self.parse_dot_or_call_expr_with(e);
3893+
let e = self.parse_dot_or_call_expr_with(e);
3894+
let e = self.parse_more_binops(e, 0);
3895+
let e = self.parse_assign_expr_with(e);
38913896
self.handle_expression_like_statement(
38923897
e,
38933898
ast::DUMMY_NODE_ID,
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)