diff options
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/generic/mod.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 19 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 4 |
7 files changed, 28 insertions, 23 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 7111fe3af1f..25a30b5e8e2 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -13,7 +13,7 @@ pub use self::AsmDialect::*; pub use self::AttrStyle::*; pub use self::BindingMode::*; -pub use self::BinOp::*; +pub use self::BinOp_::*; pub use self::BlockCheckMode::*; pub use self::CaptureClause::*; pub use self::Decl_::*; @@ -582,7 +582,7 @@ pub enum Mutability { } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] -pub enum BinOp { +pub enum BinOp_ { BiAdd, BiSub, BiMul, @@ -603,6 +603,8 @@ pub enum BinOp { BiGt, } +pub type BinOp = Spanned<BinOp_>; + #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum UnOp { UnUniq, diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index cf0aac5bf4a..5aeea47ac60 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -46,7 +46,7 @@ pub fn stmt_id(s: &Stmt) -> NodeId { } } -pub fn binop_to_string(op: BinOp) -> &'static str { +pub fn binop_to_string(op: BinOp_) -> &'static str { match op { BiAdd => "+", BiSub => "-", @@ -69,7 +69,7 @@ pub fn binop_to_string(op: BinOp) -> &'static str { } } -pub fn lazy_binop(b: BinOp) -> bool { +pub fn lazy_binop(b: BinOp_) -> bool { match b { BiAnd => true, BiOr => true, @@ -77,7 +77,7 @@ pub fn lazy_binop(b: BinOp) -> bool { } } -pub fn is_shift_binop(b: BinOp) -> bool { +pub fn is_shift_binop(b: BinOp_) -> bool { match b { BiShl => true, BiShr => true, @@ -85,7 +85,7 @@ pub fn is_shift_binop(b: BinOp) -> bool { } } -pub fn is_comparison_binop(b: BinOp) -> bool { +pub fn is_comparison_binop(b: BinOp_) -> bool { match b { BiEq | BiLt | BiLe | BiNe | BiGt | BiGe => true, _ => false @@ -93,7 +93,7 @@ pub fn is_comparison_binop(b: BinOp) -> bool { } /// Returns `true` if the binary operator takes its arguments by value -pub fn is_by_value_binop(b: BinOp) -> bool { +pub fn is_by_value_binop(b: BinOp_) -> bool { match b { BiAdd | BiSub | BiMul | BiDiv | BiRem | BiBitXor | BiBitAnd | BiBitOr | BiShl | BiShr => { true @@ -319,7 +319,7 @@ pub fn struct_field_visibility(field: ast::StructField) -> Visibility { } /// Maps a binary operator to its precedence -pub fn operator_prec(op: ast::BinOp) -> usize { +pub fn operator_prec(op: ast::BinOp_) -> usize { match op { // 'as' sits here with 12 BiMul | BiDiv | BiRem => 11us, diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 92619cf42e4..2b3a7212683 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -106,7 +106,7 @@ pub trait AstBuilder { fn expr_ident(&self, span: Span, id: ast::Ident) -> P<ast::Expr>; fn expr_self(&self, span: Span) -> P<ast::Expr>; - fn expr_binary(&self, sp: Span, op: ast::BinOp, + fn expr_binary(&self, sp: Span, op: ast::BinOp_, lhs: P<ast::Expr>, rhs: P<ast::Expr>) -> P<ast::Expr>; fn expr_deref(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr>; fn expr_unary(&self, sp: Span, op: ast::UnOp, e: P<ast::Expr>) -> P<ast::Expr>; @@ -561,9 +561,9 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.expr_ident(span, special_idents::self_) } - fn expr_binary(&self, sp: Span, op: ast::BinOp, + fn expr_binary(&self, sp: Span, op: ast::BinOp_, lhs: P<ast::Expr>, rhs: P<ast::Expr>) -> P<ast::Expr> { - self.expr(sp, ast::ExprBinary(op, lhs, rhs)) + self.expr(sp, ast::ExprBinary(Spanned { node: op, span: sp }, lhs, rhs)) } fn expr_deref(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> { diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index 272b0464010..f8812f4d28d 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -1449,7 +1449,7 @@ pub fn cs_same_method_fold<F>(use_foldl: bool, /// Use a given binop to combine the result of calling the derived method /// on all the fields. #[inline] -pub fn cs_binop(binop: ast::BinOp, base: P<Expr>, +pub fn cs_binop(binop: ast::BinOp_, base: P<Expr>, enum_nonmatch_f: EnumNonMatchCollapsedFunc, cx: &mut ExtCtxt, trait_span: Span, substructure: &Substructure) -> P<Expr> { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e59dbe52b76..759e5e8229a 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2840,6 +2840,7 @@ impl<'a> Parser<'a> { self.expected_tokens.push(TokenType::Operator); + let cur_op_span = self.span; let cur_opt = self.token.to_binop(); match cur_opt { Some(cur_op) => { @@ -2853,7 +2854,7 @@ impl<'a> Parser<'a> { let rhs = self.parse_more_binops(expr, cur_prec + 1); let lhs_span = lhs.span; let rhs_span = rhs.span; - let binary = self.mk_binary(cur_op, lhs, rhs); + let binary = self.mk_binary(codemap::respan(cur_op_span, cur_op), lhs, rhs); let bin = self.mk_expr(lhs_span.lo, rhs_span.hi, binary); self.parse_more_binops(bin, min_prec) } else { @@ -2877,16 +2878,17 @@ impl<'a> Parser<'a> { /// Produce an error if comparison operators are chained (RFC #558). /// We only need to check lhs, not rhs, because all comparison ops /// have same precedence and are left-associative - fn check_no_chained_comparison(&mut self, lhs: &Expr, outer_op: ast::BinOp) { + fn check_no_chained_comparison(&mut self, lhs: &Expr, outer_op: ast::BinOp_) { debug_assert!(ast_util::is_comparison_binop(outer_op)); match lhs.node { - ExprBinary(op, _, _) if ast_util::is_comparison_binop(op) => { - let op_span = self.span; + ExprBinary(op, _, _) if ast_util::is_comparison_binop(op.node) => { + // respan to include both operators + let op_span = mk_sp(op.span.lo, self.span.hi); self.span_err(op_span, - "Chained comparison operators require parentheses"); - if op == BiLt && outer_op == BiGt { + "chained comparison operators require parentheses"); + if op.node == BiLt && outer_op == BiGt { self.span_help(op_span, - "use ::< instead of < if you meant to specify type arguments"); + "use `::<...>` instead of `<...>` if you meant to specify type arguments"); } } _ => {} @@ -2919,6 +2921,7 @@ impl<'a> Parser<'a> { pub fn parse_assign_expr_with(&mut self, lhs: P<Expr>) -> P<Expr> { let restrictions = self.restrictions & RESTRICTION_NO_STRUCT_LITERAL; + let op_span = self.span; match self.token { token::Eq => { self.bump(); @@ -2942,7 +2945,7 @@ impl<'a> Parser<'a> { }; let rhs_span = rhs.span; let span = lhs.span; - let assign_op = self.mk_assign_op(aop, lhs, rhs); + let assign_op = self.mk_assign_op(codemap::respan(op_span, aop), lhs, rhs); self.mk_expr(span.lo, rhs_span.hi, assign_op) } // A range expression, either `expr..expr` or `expr..`. diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index a129fd19d94..ac694afac6b 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -249,7 +249,7 @@ impl Token { } /// Maps a token to its corresponding binary operator. - pub fn to_binop(&self) -> Option<ast::BinOp> { + pub fn to_binop(&self) -> Option<ast::BinOp_> { match *self { BinOp(Star) => Some(ast::BiMul), BinOp(Slash) => Some(ast::BiDiv), diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index d1cd7631c82..699b4f43b14 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1627,7 +1627,7 @@ impl<'a> State<'a> { rhs: &ast::Expr) -> IoResult<()> { try!(self.print_expr(lhs)); try!(space(&mut self.s)); - try!(self.word_space(ast_util::binop_to_string(op))); + try!(self.word_space(ast_util::binop_to_string(op.node))); self.print_expr(rhs) } @@ -1795,7 +1795,7 @@ impl<'a> State<'a> { ast::ExprAssignOp(op, ref lhs, ref rhs) => { try!(self.print_expr(&**lhs)); try!(space(&mut self.s)); - try!(word(&mut self.s, ast_util::binop_to_string(op))); + try!(word(&mut self.s, ast_util::binop_to_string(op.node))); try!(self.word_space("=")); try!(self.print_expr(&**rhs)); } |
