Skip to content

Commit 5a11ed7

Browse files
committed
Auto merge of #4223 - mikerite:fix-breakage-2019-06-21, r=flip1995
Fix breakage due to #61968 <!-- Thank you for making Clippy better! We're collecting our changelog from pull request descriptions. If your PR only updates to the latest nightly, you can leave the `changelog` entry as `none`. Otherwise, please write a short comment explaining your change. If your PR fixes an issue, you can add "fixes #issue_number" into this PR description. This way the issue will be automatically closed when your PR is merged. If you added a new lint, here's a checklist for things that will be checked during review or continuous integration. - [ ] Followed [lint naming conventions][lint_naming] - [ ] Added passing UI tests (including committed `.stderr` file) - [ ] `cargo test` passes locally - [ ] Executed `util/dev update_lints` - [ ] Added lint documentation - [ ] Run `cargo fmt` Note that you can skip the above if you are just opening a WIP PR in order to get feedback. Delete this line and everything above before opening your PR --> changelog: none
2 parents 7db5d0e + ca2ba97 commit 5a11ed7

File tree

5 files changed

+37
-41
lines changed

5 files changed

+37
-41
lines changed

clippy_lints/src/booleans.rs

+25-28
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ use crate::utils::{
22
get_trait_def_id, implements_trait, in_macro, in_macro_or_desugar, match_type, paths, snippet_opt,
33
span_lint_and_then, SpanlessEq,
44
};
5+
use if_chain::if_chain;
56
use rustc::hir::intravisit::*;
67
use rustc::hir::*;
78
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
89
use rustc::{declare_lint_pass, declare_tool_lint};
9-
use rustc_data_structures::thin_vec::ThinVec;
1010
use rustc_errors::Applicability;
1111
use syntax::ast::LitKind;
12-
use syntax::source_map::{dummy_spanned, Span, DUMMY_SP};
12+
use syntax::source_map::Span;
1313

1414
declare_clippy_lint! {
1515
/// **What it does:** Checks for boolean expressions that can be written more
@@ -93,6 +93,18 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
9393
}
9494

9595
fn run(&mut self, e: &'v Expr) -> Result<Bool, String> {
96+
fn negate(bin_op_kind: BinOpKind) -> Option<BinOpKind> {
97+
match bin_op_kind {
98+
BinOpKind::Eq => Some(BinOpKind::Ne),
99+
BinOpKind::Ne => Some(BinOpKind::Eq),
100+
BinOpKind::Gt => Some(BinOpKind::Le),
101+
BinOpKind::Ge => Some(BinOpKind::Lt),
102+
BinOpKind::Lt => Some(BinOpKind::Ge),
103+
BinOpKind::Le => Some(BinOpKind::Gt),
104+
_ => None,
105+
}
106+
}
107+
96108
// prevent folding of `cfg!` macros and the like
97109
if !in_macro_or_desugar(e.span) {
98110
match &e.node {
@@ -115,33 +127,18 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
115127
#[allow(clippy::cast_possible_truncation)]
116128
return Ok(Bool::Term(n as u8));
117129
}
118-
let negated = match &e.node {
119-
ExprKind::Binary(binop, lhs, rhs) => {
120-
if !implements_ord(self.cx, lhs) {
121-
continue;
122-
}
123130

124-
let mk_expr = |op| Expr {
125-
hir_id: DUMMY_HIR_ID,
126-
span: DUMMY_SP,
127-
attrs: ThinVec::new(),
128-
node: ExprKind::Binary(dummy_spanned(op), lhs.clone(), rhs.clone()),
129-
};
130-
match binop.node {
131-
BinOpKind::Eq => mk_expr(BinOpKind::Ne),
132-
BinOpKind::Ne => mk_expr(BinOpKind::Eq),
133-
BinOpKind::Gt => mk_expr(BinOpKind::Le),
134-
BinOpKind::Ge => mk_expr(BinOpKind::Lt),
135-
BinOpKind::Lt => mk_expr(BinOpKind::Ge),
136-
BinOpKind::Le => mk_expr(BinOpKind::Gt),
137-
_ => continue,
138-
}
139-
},
140-
_ => continue,
141-
};
142-
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(&negated, expr) {
143-
#[allow(clippy::cast_possible_truncation)]
144-
return Ok(Bool::Not(Box::new(Bool::Term(n as u8))));
131+
if_chain! {
132+
if let ExprKind::Binary(e_binop, e_lhs, e_rhs) = &e.node;
133+
if implements_ord(self.cx, e_lhs);
134+
if let ExprKind::Binary(expr_binop, expr_lhs, expr_rhs) = &expr.node;
135+
if negate(e_binop.node) == Some(expr_binop.node);
136+
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e_lhs, expr_lhs);
137+
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e_rhs, expr_rhs);
138+
then {
139+
#[allow(clippy::cast_possible_truncation)]
140+
return Ok(Bool::Not(Box::new(Bool::Term(n as u8))));
141+
}
145142
}
146143
}
147144
let n = self.terminals.len();

clippy_lints/src/double_comparison.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ declare_lint_pass!(DoubleComparisons => [DOUBLE_COMPARISONS]);
3636
impl<'a, 'tcx> DoubleComparisons {
3737
#[allow(clippy::similar_names)]
3838
fn check_binop(self, cx: &LateContext<'a, 'tcx>, op: BinOpKind, lhs: &'tcx Expr, rhs: &'tcx Expr, span: Span) {
39-
let (lkind, llhs, lrhs, rkind, rlhs, rrhs) = match (lhs.node.clone(), rhs.node.clone()) {
39+
let (lkind, llhs, lrhs, rkind, rlhs, rrhs) = match (&lhs.node, &rhs.node) {
4040
(ExprKind::Binary(lb, llhs, lrhs), ExprKind::Binary(rb, rlhs, rrhs)) => {
4141
(lb.node, llhs, lrhs, rb.node, rlhs, rrhs)
4242
},

clippy_lints/src/inherent_impl.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ declare_clippy_lint! {
4242
#[allow(clippy::module_name_repetitions)]
4343
#[derive(Default)]
4444
pub struct MultipleInherentImpl {
45-
impls: FxHashMap<def_id::DefId, (Span, Generics)>,
45+
impls: FxHashMap<def_id::DefId, Span>,
4646
}
4747

4848
impl_lint_pass!(MultipleInherentImpl => [MULTIPLE_INHERENT_IMPL]);
@@ -51,8 +51,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MultipleInherentImpl {
5151
fn check_item(&mut self, _: &LateContext<'a, 'tcx>, item: &'tcx Item) {
5252
if let ItemKind::Impl(_, _, _, ref generics, None, _, _) = item.node {
5353
// Remember for each inherent implementation encoutered its span and generics
54-
self.impls
55-
.insert(item.hir_id.owner_def_id(), (item.span, generics.clone()));
54+
// but filter out implementations that have generic params (type or lifetime)
55+
if generics.params.len() == 0 {
56+
self.impls.insert(item.hir_id.owner_def_id(), item.span);
57+
}
5658
}
5759
}
5860

@@ -66,10 +68,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MultipleInherentImpl {
6668
.values()
6769
{
6870
// Filter out implementations that have generic params (type or lifetime)
69-
let mut impl_spans = impls
70-
.iter()
71-
.filter_map(|impl_def| self.impls.get(impl_def))
72-
.filter_map(|(span, generics)| if generics.params.len() == 0 { Some(span) } else { None });
71+
let mut impl_spans = impls.iter().filter_map(|impl_def| self.impls.get(impl_def));
7372
if let Some(initial_span) = impl_spans.nth(0) {
7473
impl_spans.for_each(|additional_span| {
7574
span_lint_and_then(

clippy_lints/src/question_mark.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl QuestionMark {
129129
}
130130
}
131131

132-
fn return_expression(block: &Block) -> Option<P<Expr>> {
132+
fn return_expression(block: &Block) -> Option<&P<Expr>> {
133133
// Check if last expression is a return statement. Then, return the expression
134134
if_chain! {
135135
if block.stmts.len() == 1;
@@ -139,7 +139,7 @@ impl QuestionMark {
139139
if let &Some(ref ret_expr) = ret_expr;
140140

141141
then {
142-
return Some(ret_expr.clone());
142+
return Some(ret_expr);
143143
}
144144
}
145145

@@ -148,7 +148,7 @@ impl QuestionMark {
148148
if block.stmts.len() == 0;
149149
if let Some(ExprKind::Ret(Some(ret_expr))) = block.expr.as_ref().map(|e| &e.node);
150150
then {
151-
return Some(ret_expr.clone());
151+
return Some(ret_expr);
152152
}
153153
}
154154

clippy_lints/src/utils/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,14 @@ pub fn implements_trait<'a, 'tcx>(
315315
/// }
316316
/// }
317317
/// ```
318-
pub fn trait_ref_of_method(cx: &LateContext<'_, '_>, hir_id: HirId) -> Option<TraitRef> {
318+
pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'_, 'tcx>, hir_id: HirId) -> Option<&'tcx TraitRef> {
319319
// Get the implemented trait for the current function
320320
let parent_impl = cx.tcx.hir().get_parent_item(hir_id);
321321
if_chain! {
322322
if parent_impl != hir::CRATE_HIR_ID;
323323
if let hir::Node::Item(item) = cx.tcx.hir().get_by_hir_id(parent_impl);
324324
if let hir::ItemKind::Impl(_, _, _, _, trait_ref, _, _) = &item.node;
325-
then { return trait_ref.clone(); }
325+
then { return trait_ref.as_ref(); }
326326
}
327327
None
328328
}

0 commit comments

Comments
 (0)