Skip to content

Commit 3710ec5

Browse files
committed
Auto merge of #4080 - rust-lang:rustup, r=oli-obk
Rustup to rustc 1.36.0-nightly (acc7e65 2019-05-10) Fixes breakages from rust-lang/rust#59288 Not finished yet, help appreciated. Todo: - [x] Needs to build - [x] Util should handle DropTemps, #4080 (comment) - [x] Author lint should spit out higher::if_block checks - [x] Unsure what to do in consts.rs - [x] Needs to pass tests
2 parents c74aac9 + 19cfb84 commit 3710ec5

24 files changed

+136
-104
lines changed

clippy_lints/src/block_in_if_condition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const COMPLEX_BLOCK_MESSAGE: &str = "in an 'if' condition, avoid complex blocks
7272

7373
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
7474
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
75-
if let ExprKind::If(check, then, _) = &expr.node {
75+
if let Some((check, then, _)) = higher::if_block(&expr) {
7676
if let ExprKind::Block(block, _) = &check.node {
7777
if block.rules == DefaultBlock {
7878
if block.stmts.is_empty() {

clippy_lints/src/consts.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(clippy::float_cmp)]
22

3-
use crate::utils::{clip, sext, unsext};
3+
use crate::utils::{clip, higher, sext, unsext};
44
use if_chain::if_chain;
55
use rustc::hir::def::{DefKind, Res};
66
use rustc::hir::*;
@@ -15,7 +15,6 @@ use std::convert::TryFrom;
1515
use std::convert::TryInto;
1616
use std::hash::{Hash, Hasher};
1717
use syntax::ast::{FloatTy, LitKind};
18-
use syntax::ptr::P;
1918
use syntax_pos::symbol::{LocalInternedString, Symbol};
2019

2120
/// A `LitKind`-like enum to fold constant `Expr`s into.
@@ -222,10 +221,12 @@ pub struct ConstEvalLateContext<'a, 'tcx: 'a> {
222221
impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
223222
/// Simple constant folding: Insert an expression, get a constant or none.
224223
pub fn expr(&mut self, e: &Expr) -> Option<Constant> {
224+
if let Some((ref cond, ref then, otherwise)) = higher::if_block(&e) {
225+
return self.ifthenelse(cond, then, otherwise);
226+
}
225227
match e.node {
226228
ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id),
227229
ExprKind::Block(ref block, _) => self.block(block),
228-
ExprKind::If(ref cond, ref then, ref otherwise) => self.ifthenelse(cond, then, otherwise),
229230
ExprKind::Lit(ref lit) => Some(lit_to_constant(&lit.node, self.tables.expr_ty(e))),
230231
ExprKind::Array(ref vec) => self.multi(vec).map(Constant::Vec),
231232
ExprKind::Tup(ref tup) => self.multi(tup).map(Constant::Tuple),
@@ -358,10 +359,10 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
358359
}
359360
}
360361

361-
fn ifthenelse(&mut self, cond: &Expr, then: &P<Expr>, otherwise: &Option<P<Expr>>) -> Option<Constant> {
362+
fn ifthenelse(&mut self, cond: &Expr, then: &Expr, otherwise: Option<&Expr>) -> Option<Constant> {
362363
if let Some(Constant::Bool(b)) = self.expr(cond) {
363364
if b {
364-
self.expr(&**then)
365+
self.expr(&*then)
365366
} else {
366367
otherwise.as_ref().and_then(|expr| self.expr(expr))
367368
}

clippy_lints/src/copies.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{get_parent_expr, in_macro, snippet, span_lint_and_then, span_note_and_lint};
1+
use crate::utils::{get_parent_expr, higher, in_macro, snippet, span_lint_and_then, span_note_and_lint};
22
use crate::utils::{SpanlessEq, SpanlessHash};
33
use rustc::hir::*;
44
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@@ -109,13 +109,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste {
109109
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
110110
if !in_macro(expr.span) {
111111
// skip ifs directly in else, it will be checked in the parent if
112-
if let Some(&Expr {
113-
node: ExprKind::If(_, _, Some(ref else_expr)),
114-
..
115-
}) = get_parent_expr(cx, expr)
116-
{
117-
if else_expr.hir_id == expr.hir_id {
118-
return;
112+
if let Some(expr) = get_parent_expr(cx, expr) {
113+
if let Some((_, _, Some(ref else_expr))) = higher::if_block(&expr) {
114+
if else_expr.hir_id == expr.hir_id {
115+
return;
116+
}
119117
}
120118
}
121119

@@ -236,7 +234,7 @@ fn if_sequence(mut expr: &Expr) -> (SmallVec<[&Expr; 1]>, SmallVec<[&Block; 1]>)
236234
let mut conds = SmallVec::new();
237235
let mut blocks: SmallVec<[&Block; 1]> = SmallVec::new();
238236

239-
while let ExprKind::If(ref cond, ref then_expr, ref else_expr) = expr.node {
237+
while let Some((ref cond, ref then_expr, ref else_expr)) = higher::if_block(&expr) {
240238
conds.push(&**cond);
241239
if let ExprKind::Block(ref block, _) = then_expr.node {
242240
blocks.push(block);

clippy_lints/src/entry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::utils::SpanlessEq;
2-
use crate::utils::{get_item_name, match_type, paths, snippet, span_lint_and_then, walk_ptrs_ty};
2+
use crate::utils::{get_item_name, higher, match_type, paths, snippet, span_lint_and_then, walk_ptrs_ty};
33
use if_chain::if_chain;
44
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
55
use rustc::hir::*;
@@ -41,7 +41,7 @@ declare_lint_pass!(HashMapPass => [MAP_ENTRY]);
4141

4242
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapPass {
4343
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
44-
if let ExprKind::If(ref check, ref then_block, ref else_block) = expr.node {
44+
if let Some((ref check, ref then_block, ref else_block)) = higher::if_block(&expr) {
4545
if let ExprKind::Unary(UnOp::UnNot, ref check) = check.node {
4646
if let Some((ty, map, key)) = check_cond(cx, check) {
4747
// in case of `if !m.contains_key(&k) { m.insert(k, v); }`

clippy_lints/src/implicit_return.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@ impl ImplicitReturn {
7474
Self::lint(cx, expr.span, break_expr.span, "change `break` to `return` as shown");
7575
}
7676
},
77-
ExprKind::If(.., if_expr, else_expr) => {
78-
Self::expr_match(cx, if_expr);
79-
80-
if let Some(else_expr) = else_expr {
81-
Self::expr_match(cx, else_expr);
82-
}
83-
},
8477
ExprKind::Match(.., arms, source) => {
8578
let check_all_arms = match source {
8679
MatchSource::IfLetDesugar {

clippy_lints/src/let_if_seq.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{snippet, span_lint_and_then};
1+
use crate::utils::{higher, snippet, span_lint_and_then};
22
use if_chain::if_chain;
33
use rustc::hir;
44
use rustc::hir::def::Res;
@@ -63,7 +63,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
6363
if let hir::StmtKind::Local(ref local) = stmt.node;
6464
if let hir::PatKind::Binding(mode, canonical_id, ident, None) = local.pat.node;
6565
if let hir::StmtKind::Expr(ref if_) = expr.node;
66-
if let hir::ExprKind::If(ref cond, ref then, ref else_) = if_.node;
66+
if let Some((ref cond, ref then, ref else_)) = higher::if_block(&if_);
6767
if !used_in_expr(cx, canonical_id, cond);
6868
if let hir::ExprKind::Block(ref then, _) = then.node;
6969
if let Some(value) = check_assign(cx, canonical_id, &*then);

clippy_lints/src/loops.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -686,14 +686,6 @@ fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult {
686686
| ExprKind::Assign(ref e1, ref e2)
687687
| ExprKind::AssignOp(_, ref e1, ref e2)
688688
| ExprKind::Index(ref e1, ref e2) => never_loop_expr_all(&mut [&**e1, &**e2].iter().cloned(), main_loop_id),
689-
ExprKind::If(ref e, ref e2, ref e3) => {
690-
let e1 = never_loop_expr(e, main_loop_id);
691-
let e2 = never_loop_expr(e2, main_loop_id);
692-
let e3 = e3
693-
.as_ref()
694-
.map_or(NeverLoopResult::Otherwise, |e| never_loop_expr(e, main_loop_id));
695-
combine_seq(e1, combine_branches(e2, e3))
696-
},
697689
ExprKind::Loop(ref b, _, _) => {
698690
// Break can come from the inner loop so remove them.
699691
absorb_break(&never_loop_block(b, main_loop_id))
@@ -2204,7 +2196,7 @@ fn is_loop(expr: &Expr) -> bool {
22042196

22052197
fn is_conditional(expr: &Expr) -> bool {
22062198
match expr.node {
2207-
ExprKind::If(..) | ExprKind::Match(..) => true,
2199+
ExprKind::Match(..) => true,
22082200
_ => false,
22092201
}
22102202
}

clippy_lints/src/methods/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,6 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
12661266
hir::ExprKind::Call(..)
12671267
| hir::ExprKind::MethodCall(..)
12681268
// These variants are debatable or require further examination
1269-
| hir::ExprKind::If(..)
12701269
| hir::ExprKind::Match(..)
12711270
| hir::ExprKind::Block{ .. } => true,
12721271
_ => false,

clippy_lints/src/methods/unnecessary_filter_map.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@ fn check_expression<'a, 'tcx: 'a>(
8989
(false, false)
9090
}
9191
},
92-
// There must be an else_arm or there will be a type error
93-
hir::ExprKind::If(_, ref if_arm, Some(ref else_arm)) => {
94-
let if_check = check_expression(cx, arg_id, if_arm);
95-
let else_check = check_expression(cx, arg_id, else_arm);
96-
(if_check.0 | else_check.0, if_check.1 | else_check.1)
97-
},
9892
hir::ExprKind::Match(_, ref arms, _) => {
9993
let mut found_mapping = false;
10094
let mut found_filtering = false;

clippy_lints/src/needless_bool.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! This lint is **warn** by default
44
55
use crate::utils::sugg::Sugg;
6-
use crate::utils::{in_macro, span_lint, span_lint_and_sugg};
6+
use crate::utils::{higher, in_macro, span_lint, span_lint_and_sugg};
77
use rustc::hir::*;
88
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
99
use rustc::{declare_lint_pass, declare_tool_lint};
@@ -59,7 +59,7 @@ declare_lint_pass!(NeedlessBool => [NEEDLESS_BOOL]);
5959
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool {
6060
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
6161
use self::Expression::*;
62-
if let ExprKind::If(ref pred, ref then_block, Some(ref else_expr)) = e.node {
62+
if let Some((ref pred, ref then_block, Some(ref else_expr))) = higher::if_block(&e) {
6363
let reduce = |ret, not| {
6464
let mut applicability = Applicability::MachineApplicable;
6565
let snip = Sugg::hir_with_applicability(cx, pred, "<predicate>", &mut applicability);
@@ -119,7 +119,7 @@ fn parent_node_is_if_expr<'a, 'b>(expr: &Expr, cx: &LateContext<'a, 'b>) -> bool
119119
let parent_node = cx.tcx.hir().get_by_hir_id(parent_id);
120120

121121
if let rustc::hir::Node::Expr(e) = parent_node {
122-
if let ExprKind::If(_, _, _) = e.node {
122+
if higher::if_block(&e).is_some() {
123123
return true;
124124
}
125125
}

0 commit comments

Comments
 (0)