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

+7-7
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

+1-1
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

+6-6
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

+1-1
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

+2-2
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

+3-3
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

+1-1
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

+4-4
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

+5-5
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

+1-1
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) }

src/librustc_trans/trans/expr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ fn trans_rvalue_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
11321132
let rhs_datum = unpack_datum!(bcx, trans(bcx, &**rhs));
11331133
trans_overloaded_op(bcx, expr, MethodCall::expr(expr.id), lhs,
11341134
vec![(rhs_datum, rhs.id)], Some(dest),
1135-
!ast_util::is_by_value_binop(op)).bcx
1135+
!ast_util::is_by_value_binop(op.node)).bcx
11361136
}
11371137
ast::ExprUnary(op, ref subexpr) => {
11381138
// if not overloaded, would be RvalueDatumExpr
@@ -1676,7 +1676,7 @@ fn trans_eager_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
16761676
let binop_debug_loc = binop_expr.debug_loc();
16771677

16781678
let mut bcx = bcx;
1679-
let val = match op {
1679+
let val = match op.node {
16801680
ast::BiAdd => {
16811681
if is_float {
16821682
FAdd(bcx, lhs, rhs, binop_debug_loc)
@@ -1739,7 +1739,7 @@ fn trans_eager_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
17391739
}
17401740
ast::BiEq | ast::BiNe | ast::BiLt | ast::BiGe | ast::BiLe | ast::BiGt => {
17411741
if ty::type_is_scalar(rhs_t) {
1742-
unpack_result!(bcx, base::compare_scalar_types(bcx, lhs, rhs, rhs_t, op))
1742+
unpack_result!(bcx, base::compare_scalar_types(bcx, lhs, rhs, rhs_t, op.node))
17431743
} else if is_simd {
17441744
base::compare_simd_types(bcx, lhs, rhs, intype, ty::simd_size(tcx, lhs_t), op)
17451745
} else {
@@ -1811,7 +1811,7 @@ fn trans_binary<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
18111811
// if overloaded, would be RvalueDpsExpr
18121812
assert!(!ccx.tcx().method_map.borrow().contains_key(&MethodCall::expr(expr.id)));
18131813

1814-
match op {
1814+
match op.node {
18151815
ast::BiAnd => {
18161816
trans_lazy_binop(bcx, expr, lazy_and, lhs, rhs)
18171817
}

src/librustc_typeck/check/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -2859,7 +2859,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
28592859
let lhs_t = structurally_resolved_type(fcx, lhs.span,
28602860
fcx.expr_ty(&*lhs));
28612861

2862-
if ty::type_is_integral(lhs_t) && ast_util::is_shift_binop(op) {
2862+
if ty::type_is_integral(lhs_t) && ast_util::is_shift_binop(op.node) {
28632863
// Shift is a special case: rhs must be uint, no matter what lhs is
28642864
check_expr(fcx, &**rhs);
28652865
let rhs_ty = fcx.expr_ty(&**rhs);
@@ -2887,7 +2887,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
28872887
demand::suptype(fcx, expr.span, tvar, lhs_t);
28882888
check_expr_has_type(fcx, &**rhs, tvar);
28892889

2890-
let result_t = match op {
2890+
let result_t = match op.node {
28912891
ast::BiEq | ast::BiNe | ast::BiLt | ast::BiLe | ast::BiGe |
28922892
ast::BiGt => {
28932893
if ty::type_is_simd(tcx, lhs_t) {
@@ -2898,7 +2898,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
28982898
operation `{}` not \
28992899
supported for floating \
29002900
point SIMD vector `{}`",
2901-
ast_util::binop_to_string(op),
2901+
ast_util::binop_to_string(op.node),
29022902
actual)
29032903
},
29042904
lhs_t,
@@ -2919,7 +2919,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
29192919
return;
29202920
}
29212921

2922-
if op == ast::BiOr || op == ast::BiAnd {
2922+
if op.node == ast::BiOr || op.node == ast::BiAnd {
29232923
// This is an error; one of the operands must have the wrong
29242924
// type
29252925
fcx.write_error(expr.id);
@@ -2928,7 +2928,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
29282928
|actual| {
29292929
format!("binary operation `{}` cannot be applied \
29302930
to type `{}`",
2931-
ast_util::binop_to_string(op),
2931+
ast_util::binop_to_string(op.node),
29322932
actual)
29332933
},
29342934
lhs_t,
@@ -2945,7 +2945,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
29452945
operation `{}=` \
29462946
cannot be applied to \
29472947
type `{}`",
2948-
ast_util::binop_to_string(op),
2948+
ast_util::binop_to_string(op.node),
29492949
actual)
29502950
},
29512951
lhs_t,
@@ -2968,7 +2968,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
29682968
rhs: &P<ast::Expr>) -> Ty<'tcx> {
29692969
let tcx = fcx.ccx.tcx;
29702970
let lang = &tcx.lang_items;
2971-
let (name, trait_did) = match op {
2971+
let (name, trait_did) = match op.node {
29722972
ast::BiAdd => ("add", lang.add_trait()),
29732973
ast::BiSub => ("sub", lang.sub_trait()),
29742974
ast::BiMul => ("mul", lang.mul_trait()),
@@ -2994,10 +2994,10 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
29942994
trait_did, lhs_expr, Some(rhs), || {
29952995
fcx.type_error_message(ex.span, |actual| {
29962996
format!("binary operation `{}` cannot be applied to type `{}`",
2997-
ast_util::binop_to_string(op),
2997+
ast_util::binop_to_string(op.node),
29982998
actual)
29992999
}, lhs_resolved_t, None)
3000-
}, if ast_util::is_by_value_binop(op) { AutorefArgs::No } else { AutorefArgs::Yes })
3000+
}, if ast_util::is_by_value_binop(op.node) { AutorefArgs::No } else { AutorefArgs::Yes })
30013001
}
30023002

30033003
fn check_user_unop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,

src/librustc_typeck/check/regionck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
564564
},
565565

566566
ast::ExprBinary(op, ref lhs, ref rhs) if has_method_map => {
567-
let implicitly_ref_args = !ast_util::is_by_value_binop(op);
567+
let implicitly_ref_args = !ast_util::is_by_value_binop(op.node);
568568

569569
// As `expr_method_call`, but the call is via an
570570
// overloaded op. Note that we (sadly) currently use an

0 commit comments

Comments
 (0)