Skip to content

Commit 76fbb35

Browse files
committed
Auto merge of #21079 - huonw:chained-cmp-tweaks, r=pnkfelix
First commit is mindless groundwork for the second one, to make the spans (arguably) nicer. ### before ``` require-parens-for-chained-comparison.rs:14:20: 14:22 error: Chained comparison operators require parentheses require-parens-for-chained-comparison.rs:14 false == false == false; ^~ require-parens-for-chained-comparison.rs:17:16: 17:17 error: Chained comparison operators require parentheses require-parens-for-chained-comparison.rs:17 false == 0 < 2; ^ require-parens-for-chained-comparison.rs:20:8: 20:9 error: Chained comparison operators require parentheses require-parens-for-chained-comparison.rs:20 f<X>(); ^ require-parens-for-chained-comparison.rs:20:8: 20:9 help: Use ::< instead of < if you meant to specify type arguments. require-parens-for-chained-comparison.rs:20 f<X>(); ^ ``` ### after ``` require-parens-for-chained-comparison.rs:14:11: 14:22 error: chained comparison operators require parentheses require-parens-for-chained-comparison.rs:14 false == false == false; ^~~~~~~~~~~ require-parens-for-chained-comparison.rs:17:11: 17:17 error: chained comparison operators require parentheses require-parens-for-chained-comparison.rs:17 false == 0 < 2; ^~~~~~ require-parens-for-chained-comparison.rs:20:6: 20:9 error: chained comparison operators require parentheses require-parens-for-chained-comparison.rs:20 f<X>(); ^~~ require-parens-for-chained-comparison.rs:20:6: 20:9 help: use `::<...>` instead of `<...>` if you meant to specify type arguments require-parens-for-chained-comparison.rs:20 f<X>(); ^~~ ```
2 parents 0430a43 + ec790d6 commit 76fbb35

File tree

22 files changed

+79
-74
lines changed

22 files changed

+79
-74
lines changed

src/librustc/lint/builtin.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64};
4444
use syntax::{abi, ast, ast_map};
4545
use syntax::ast_util::is_shift_binop;
4646
use syntax::attr::{self, AttrMetaMethods};
47-
use syntax::codemap::{Span, DUMMY_SP};
47+
use syntax::codemap::{self, Span, DUMMY_SP};
4848
use syntax::parse::token;
4949
use syntax::ast::{TyIs, TyUs, TyI8, TyU8, TyI16, TyU16, TyI32, TyU32, TyI64, TyU64};
5050
use syntax::ast_util;
@@ -185,7 +185,7 @@ impl LintPass for TypeLimits {
185185
"comparison is useless due to type limits");
186186
}
187187

188-
if is_shift_binop(binop) {
188+
if is_shift_binop(binop.node) {
189189
let opt_ty_bits = match ty::expr_ty(cx.tcx, &**l).sty {
190190
ty::ty_int(t) => Some(int_ty_bits(t, cx.sess().target.int_type)),
191191
ty::ty_uint(t) => Some(uint_ty_bits(t, cx.sess().target.uint_type)),
@@ -272,7 +272,7 @@ impl LintPass for TypeLimits {
272272

273273
fn is_valid<T:cmp::PartialOrd>(binop: ast::BinOp, v: T,
274274
min: T, max: T) -> bool {
275-
match binop {
275+
match binop.node {
276276
ast::BiLt => v > min && v <= max,
277277
ast::BiLe => v >= min && v < max,
278278
ast::BiGt => v >= min && v < max,
@@ -283,13 +283,13 @@ impl LintPass for TypeLimits {
283283
}
284284

285285
fn rev_binop(binop: ast::BinOp) -> ast::BinOp {
286-
match binop {
286+
codemap::respan(binop.span, match binop.node {
287287
ast::BiLt => ast::BiGt,
288288
ast::BiLe => ast::BiGe,
289289
ast::BiGt => ast::BiLt,
290290
ast::BiGe => ast::BiLe,
291-
_ => binop
292-
}
291+
_ => return binop
292+
})
293293
}
294294

295295
// for int & uint, be conservative with the warnings, so that the
@@ -382,7 +382,7 @@ impl LintPass for TypeLimits {
382382
}
383383

384384
fn is_comparison(binop: ast::BinOp) -> bool {
385-
match binop {
385+
match binop.node {
386386
ast::BiEq | ast::BiLt | ast::BiLe |
387387
ast::BiNe | ast::BiGe | ast::BiGt => true,
388388
_ => false

src/librustc/middle/cfg/construct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
372372
expr_exit
373373
}
374374

375-
ast::ExprBinary(op, ref l, ref r) if ast_util::lazy_binop(op) => {
375+
ast::ExprBinary(op, ref l, ref r) if ast_util::lazy_binop(op.node) => {
376376
//
377377
// [pred]
378378
// |

src/librustc/middle/const_eval.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result<const_val, St
400400
match (eval_const_expr_partial(tcx, &**a),
401401
eval_const_expr_partial(tcx, &**b)) {
402402
(Ok(const_float(a)), Ok(const_float(b))) => {
403-
match op {
403+
match op.node {
404404
ast::BiAdd => Ok(const_float(a + b)),
405405
ast::BiSub => Ok(const_float(a - b)),
406406
ast::BiMul => Ok(const_float(a * b)),
@@ -416,7 +416,7 @@ pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result<const_val, St
416416
}
417417
}
418418
(Ok(const_int(a)), Ok(const_int(b))) => {
419-
match op {
419+
match op.node {
420420
ast::BiAdd => Ok(const_int(a + b)),
421421
ast::BiSub => Ok(const_int(a - b)),
422422
ast::BiMul => Ok(const_int(a * b)),
@@ -443,7 +443,7 @@ pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result<const_val, St
443443
}
444444
}
445445
(Ok(const_uint(a)), Ok(const_uint(b))) => {
446-
match op {
446+
match op.node {
447447
ast::BiAdd => Ok(const_uint(a + b)),
448448
ast::BiSub => Ok(const_uint(a - b)),
449449
ast::BiMul => Ok(const_uint(a * b)),
@@ -471,21 +471,21 @@ pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result<const_val, St
471471
}
472472
// shifts can have any integral type as their rhs
473473
(Ok(const_int(a)), Ok(const_uint(b))) => {
474-
match op {
474+
match op.node {
475475
ast::BiShl => Ok(const_int(a << b as uint)),
476476
ast::BiShr => Ok(const_int(a >> b as uint)),
477477
_ => Err("can't do this op on an int and uint".to_string())
478478
}
479479
}
480480
(Ok(const_uint(a)), Ok(const_int(b))) => {
481-
match op {
481+
match op.node {
482482
ast::BiShl => Ok(const_uint(a << b as uint)),
483483
ast::BiShr => Ok(const_uint(a >> b as uint)),
484484
_ => Err("can't do this op on a uint and int".to_string())
485485
}
486486
}
487487
(Ok(const_bool(a)), Ok(const_bool(b))) => {
488-
Ok(const_bool(match op {
488+
Ok(const_bool(match op.node {
489489
ast::BiAnd => a && b,
490490
ast::BiOr => a || b,
491491
ast::BiBitXor => a ^ b,

src/librustc/middle/expr_use_visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
568568
}
569569

570570
ast::ExprBinary(op, ref lhs, ref rhs) => {
571-
let pass_args = if ast_util::is_by_value_binop(op) {
571+
let pass_args = if ast_util::is_by_value_binop(op.node) {
572572
PassArgs::ByValue
573573
} else {
574574
PassArgs::ByRef

src/librustc/middle/liveness.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
504504
ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
505505
visit::walk_expr(ir, expr);
506506
}
507-
ast::ExprBinary(op, _, _) if ast_util::lazy_binop(op) => {
507+
ast::ExprBinary(op, _, _) if ast_util::lazy_binop(op.node) => {
508508
ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
509509
visit::walk_expr(ir, expr);
510510
}
@@ -1177,7 +1177,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
11771177
self.propagate_through_exprs(&exprs[], succ)
11781178
}
11791179

1180-
ast::ExprBinary(op, ref l, ref r) if ast_util::lazy_binop(op) => {
1180+
ast::ExprBinary(op, ref l, ref r) if ast_util::lazy_binop(op.node) => {
11811181
let r_succ = self.propagate_through_expr(&**r, succ);
11821182

11831183
let ln = self.live_node(expr.id, expr.span);

src/librustc/middle/region.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use util::nodemap::{FnvHashMap, FnvHashSet, NodeMap};
2222
use util::common::can_reach;
2323

2424
use std::cell::RefCell;
25-
use syntax::codemap::Span;
25+
use syntax::codemap::{self, Span};
2626
use syntax::{ast, visit};
2727
use syntax::ast::{Block, Item, FnDecl, NodeId, Arm, Pat, Stmt, Expr, Local};
2828
use syntax::ast_util::{stmt_id};
@@ -496,8 +496,8 @@ fn resolve_expr(visitor: &mut RegionResolutionVisitor, expr: &ast::Expr) {
496496
// scopes, meaning that temporaries cannot outlive them.
497497
// This ensures fixed size stacks.
498498

499-
ast::ExprBinary(ast::BiAnd, _, ref r) |
500-
ast::ExprBinary(ast::BiOr, _, ref r) => {
499+
ast::ExprBinary(codemap::Spanned { node: ast::BiAnd, .. }, _, ref r) |
500+
ast::ExprBinary(codemap::Spanned { node: ast::BiOr, .. }, _, ref r) => {
501501
// For shortcircuiting operators, mark the RHS as a terminating
502502
// scope since it only executes conditionally.
503503
terminating(r.id);

src/librustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5716,7 +5716,7 @@ pub fn is_binopable<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>, op: ast::BinOp) -> bool
57165716
static opcat_mod: int = 8;
57175717

57185718
fn opcat(op: ast::BinOp) -> int {
5719-
match op {
5719+
match op.node {
57205720
ast::BiAdd => opcat_add,
57215721
ast::BiSub => opcat_sub,
57225722
ast::BiMul => opcat_mult,

src/librustc_back/svh.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ mod svh_visitor {
231231
SawExprCall,
232232
SawExprMethodCall,
233233
SawExprTup,
234-
SawExprBinary(ast::BinOp),
234+
SawExprBinary(ast::BinOp_),
235235
SawExprUnary(ast::UnOp),
236236
SawExprLit(ast::Lit_),
237237
SawExprCast,
@@ -241,7 +241,7 @@ mod svh_visitor {
241241
SawExprClosure,
242242
SawExprBlock,
243243
SawExprAssign,
244-
SawExprAssignOp(ast::BinOp),
244+
SawExprAssignOp(ast::BinOp_),
245245
SawExprIndex,
246246
SawExprRange,
247247
SawExprPath,
@@ -262,7 +262,7 @@ mod svh_visitor {
262262
ExprCall(..) => SawExprCall,
263263
ExprMethodCall(..) => SawExprMethodCall,
264264
ExprTup(..) => SawExprTup,
265-
ExprBinary(op, _, _) => SawExprBinary(op),
265+
ExprBinary(op, _, _) => SawExprBinary(op.node),
266266
ExprUnary(op, _) => SawExprUnary(op),
267267
ExprLit(ref lit) => SawExprLit(lit.node.clone()),
268268
ExprCast(..) => SawExprCast,
@@ -273,7 +273,7 @@ mod svh_visitor {
273273
ExprClosure(..) => SawExprClosure,
274274
ExprBlock(..) => SawExprBlock,
275275
ExprAssign(..) => SawExprAssign,
276-
ExprAssignOp(op, _, _) => SawExprAssignOp(op),
276+
ExprAssignOp(op, _, _) => SawExprAssignOp(op.node),
277277
ExprField(_, id) => SawExprField(content(id.node)),
278278
ExprTupField(_, id) => SawExprTupField(id.node),
279279
ExprIndex(..) => SawExprIndex,

src/librustc_trans/trans/base.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ pub fn compare_scalar_types<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
540540
lhs: ValueRef,
541541
rhs: ValueRef,
542542
t: Ty<'tcx>,
543-
op: ast::BinOp)
543+
op: ast::BinOp_)
544544
-> Result<'blk, 'tcx> {
545545
let f = |&: a| Result::new(cx, compare_scalar_values(cx, lhs, rhs, a, op));
546546

@@ -561,7 +561,7 @@ pub fn compare_scalar_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
561561
lhs: ValueRef,
562562
rhs: ValueRef,
563563
nt: scalar_type,
564-
op: ast::BinOp)
564+
op: ast::BinOp_)
565565
-> ValueRef {
566566
let _icx = push_ctxt("compare_scalar_values");
567567
fn die(cx: Block) -> ! {
@@ -635,7 +635,7 @@ pub fn compare_simd_types<'blk, 'tcx>(
635635
not supported for floating point SIMD types")
636636
},
637637
ty::ty_uint(_) | ty::ty_int(_) => {
638-
let cmp = match op {
638+
let cmp = match op.node {
639639
ast::BiEq => llvm::IntEQ,
640640
ast::BiNe => llvm::IntNE,
641641
ast::BiLt => llvm::IntSLT,
@@ -823,7 +823,7 @@ pub fn cast_shift_rhs<F, G>(op: ast::BinOp,
823823
G: FnOnce(ValueRef, Type) -> ValueRef,
824824
{
825825
// Shifts may have any size int on the rhs
826-
if ast_util::is_shift_binop(op) {
826+
if ast_util::is_shift_binop(op.node) {
827827
let mut rhs_llty = val_ty(rhs);
828828
let mut lhs_llty = val_ty(lhs);
829829
if rhs_llty.kind() == Vector { rhs_llty = rhs_llty.element_type() }
@@ -852,7 +852,7 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>(
852852
rhs: ValueRef,
853853
rhs_t: Ty<'tcx>)
854854
-> Block<'blk, 'tcx> {
855-
let (zero_text, overflow_text) = if divrem == ast::BiDiv {
855+
let (zero_text, overflow_text) = if divrem.node == ast::BiDiv {
856856
("attempted to divide by zero",
857857
"attempted to divide with overflow")
858858
} else {

src/librustc_trans/trans/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr) -> ValueRef {
310310
let ty = ty::expr_ty(cx.tcx(), &**e1);
311311
let is_float = ty::type_is_fp(ty);
312312
let signed = ty::type_is_signed(ty);
313-
return match b {
313+
return match b.node {
314314
ast::BiAdd => {
315315
if is_float { llvm::LLVMConstFAdd(te1, te2) }
316316
else { llvm::LLVMConstAdd(te1, te2) }

0 commit comments

Comments
 (0)