Auto merge of #4223 - mikerite:fix-breakage-2019-06-21, r=flip1995

Fix breakage due to rust-lang/rust#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
This commit is contained in:
bors 2019-06-21 10:33:53 +00:00
commit 5a11ed7b92
5 changed files with 37 additions and 41 deletions

View File

@ -2,14 +2,14 @@
get_trait_def_id, implements_trait, in_macro, in_macro_or_desugar, match_type, paths, snippet_opt,
span_lint_and_then, SpanlessEq,
};
use if_chain::if_chain;
use rustc::hir::intravisit::*;
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_data_structures::thin_vec::ThinVec;
use rustc_errors::Applicability;
use syntax::ast::LitKind;
use syntax::source_map::{dummy_spanned, Span, DUMMY_SP};
use syntax::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for boolean expressions that can be written more
@ -93,6 +93,18 @@ fn extract(&mut self, op: BinOpKind, a: &[&'v Expr], mut v: Vec<Bool>) -> Result
}
fn run(&mut self, e: &'v Expr) -> Result<Bool, String> {
fn negate(bin_op_kind: BinOpKind) -> Option<BinOpKind> {
match bin_op_kind {
BinOpKind::Eq => Some(BinOpKind::Ne),
BinOpKind::Ne => Some(BinOpKind::Eq),
BinOpKind::Gt => Some(BinOpKind::Le),
BinOpKind::Ge => Some(BinOpKind::Lt),
BinOpKind::Lt => Some(BinOpKind::Ge),
BinOpKind::Le => Some(BinOpKind::Gt),
_ => None,
}
}
// prevent folding of `cfg!` macros and the like
if !in_macro_or_desugar(e.span) {
match &e.node {
@ -115,33 +127,18 @@ fn run(&mut self, e: &'v Expr) -> Result<Bool, String> {
#[allow(clippy::cast_possible_truncation)]
return Ok(Bool::Term(n as u8));
}
let negated = match &e.node {
ExprKind::Binary(binop, lhs, rhs) => {
if !implements_ord(self.cx, lhs) {
continue;
}
let mk_expr = |op| Expr {
hir_id: DUMMY_HIR_ID,
span: DUMMY_SP,
attrs: ThinVec::new(),
node: ExprKind::Binary(dummy_spanned(op), lhs.clone(), rhs.clone()),
};
match binop.node {
BinOpKind::Eq => mk_expr(BinOpKind::Ne),
BinOpKind::Ne => mk_expr(BinOpKind::Eq),
BinOpKind::Gt => mk_expr(BinOpKind::Le),
BinOpKind::Ge => mk_expr(BinOpKind::Lt),
BinOpKind::Lt => mk_expr(BinOpKind::Ge),
BinOpKind::Le => mk_expr(BinOpKind::Gt),
_ => continue,
}
},
_ => continue,
};
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(&negated, expr) {
#[allow(clippy::cast_possible_truncation)]
return Ok(Bool::Not(Box::new(Bool::Term(n as u8))));
if_chain! {
if let ExprKind::Binary(e_binop, e_lhs, e_rhs) = &e.node;
if implements_ord(self.cx, e_lhs);
if let ExprKind::Binary(expr_binop, expr_lhs, expr_rhs) = &expr.node;
if negate(e_binop.node) == Some(expr_binop.node);
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e_lhs, expr_lhs);
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e_rhs, expr_rhs);
then {
#[allow(clippy::cast_possible_truncation)]
return Ok(Bool::Not(Box::new(Bool::Term(n as u8))));
}
}
}
let n = self.terminals.len();

View File

@ -36,7 +36,7 @@
impl<'a, 'tcx> DoubleComparisons {
#[allow(clippy::similar_names)]
fn check_binop(self, cx: &LateContext<'a, 'tcx>, op: BinOpKind, lhs: &'tcx Expr, rhs: &'tcx Expr, span: Span) {
let (lkind, llhs, lrhs, rkind, rlhs, rrhs) = match (lhs.node.clone(), rhs.node.clone()) {
let (lkind, llhs, lrhs, rkind, rlhs, rrhs) = match (&lhs.node, &rhs.node) {
(ExprKind::Binary(lb, llhs, lrhs), ExprKind::Binary(rb, rlhs, rrhs)) => {
(lb.node, llhs, lrhs, rb.node, rlhs, rrhs)
},

View File

@ -42,7 +42,7 @@
#[allow(clippy::module_name_repetitions)]
#[derive(Default)]
pub struct MultipleInherentImpl {
impls: FxHashMap<def_id::DefId, (Span, Generics)>,
impls: FxHashMap<def_id::DefId, Span>,
}
impl_lint_pass!(MultipleInherentImpl => [MULTIPLE_INHERENT_IMPL]);
@ -51,8 +51,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MultipleInherentImpl {
fn check_item(&mut self, _: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if let ItemKind::Impl(_, _, _, ref generics, None, _, _) = item.node {
// Remember for each inherent implementation encoutered its span and generics
self.impls
.insert(item.hir_id.owner_def_id(), (item.span, generics.clone()));
// but filter out implementations that have generic params (type or lifetime)
if generics.params.len() == 0 {
self.impls.insert(item.hir_id.owner_def_id(), item.span);
}
}
}
@ -66,10 +68,7 @@ fn check_crate_post(&mut self, cx: &LateContext<'a, 'tcx>, krate: &'tcx Crate) {
.values()
{
// Filter out implementations that have generic params (type or lifetime)
let mut impl_spans = impls
.iter()
.filter_map(|impl_def| self.impls.get(impl_def))
.filter_map(|(span, generics)| if generics.params.len() == 0 { Some(span) } else { None });
let mut impl_spans = impls.iter().filter_map(|impl_def| self.impls.get(impl_def));
if let Some(initial_span) = impl_spans.nth(0) {
impl_spans.for_each(|additional_span| {
span_lint_and_then(

View File

@ -129,7 +129,7 @@ fn expression_returns_none(cx: &LateContext<'_, '_>, expression: &Expr) -> bool
}
}
fn return_expression(block: &Block) -> Option<P<Expr>> {
fn return_expression(block: &Block) -> Option<&P<Expr>> {
// Check if last expression is a return statement. Then, return the expression
if_chain! {
if block.stmts.len() == 1;
@ -139,7 +139,7 @@ fn return_expression(block: &Block) -> Option<P<Expr>> {
if let &Some(ref ret_expr) = ret_expr;
then {
return Some(ret_expr.clone());
return Some(ret_expr);
}
}
@ -148,7 +148,7 @@ fn return_expression(block: &Block) -> Option<P<Expr>> {
if block.stmts.len() == 0;
if let Some(ExprKind::Ret(Some(ret_expr))) = block.expr.as_ref().map(|e| &e.node);
then {
return Some(ret_expr.clone());
return Some(ret_expr);
}
}

View File

@ -315,14 +315,14 @@ pub fn implements_trait<'a, 'tcx>(
/// }
/// }
/// ```
pub fn trait_ref_of_method(cx: &LateContext<'_, '_>, hir_id: HirId) -> Option<TraitRef> {
pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'_, 'tcx>, hir_id: HirId) -> Option<&'tcx TraitRef> {
// Get the implemented trait for the current function
let parent_impl = cx.tcx.hir().get_parent_item(hir_id);
if_chain! {
if parent_impl != hir::CRATE_HIR_ID;
if let hir::Node::Item(item) = cx.tcx.hir().get_by_hir_id(parent_impl);
if let hir::ItemKind::Impl(_, _, _, _, trait_ref, _, _) = &item.node;
then { return trait_ref.clone(); }
then { return trait_ref.as_ref(); }
}
None
}