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:
commit
5a11ed7b92
5 changed files with 37 additions and 41 deletions
|
@ -2,14 +2,14 @@ use crate::utils::{
|
||||||
get_trait_def_id, implements_trait, in_macro, in_macro_or_desugar, match_type, paths, snippet_opt,
|
get_trait_def_id, implements_trait, in_macro, in_macro_or_desugar, match_type, paths, snippet_opt,
|
||||||
span_lint_and_then, SpanlessEq,
|
span_lint_and_then, SpanlessEq,
|
||||||
};
|
};
|
||||||
|
use if_chain::if_chain;
|
||||||
use rustc::hir::intravisit::*;
|
use rustc::hir::intravisit::*;
|
||||||
use rustc::hir::*;
|
use rustc::hir::*;
|
||||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use rustc::{declare_lint_pass, declare_tool_lint};
|
use rustc::{declare_lint_pass, declare_tool_lint};
|
||||||
use rustc_data_structures::thin_vec::ThinVec;
|
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use syntax::ast::LitKind;
|
use syntax::ast::LitKind;
|
||||||
use syntax::source_map::{dummy_spanned, Span, DUMMY_SP};
|
use syntax::source_map::Span;
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// **What it does:** Checks for boolean expressions that can be written more
|
/// **What it does:** Checks for boolean expressions that can be written more
|
||||||
|
@ -93,6 +93,18 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&mut self, e: &'v Expr) -> Result<Bool, String> {
|
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
|
// prevent folding of `cfg!` macros and the like
|
||||||
if !in_macro_or_desugar(e.span) {
|
if !in_macro_or_desugar(e.span) {
|
||||||
match &e.node {
|
match &e.node {
|
||||||
|
@ -115,33 +127,18 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
|
||||||
#[allow(clippy::cast_possible_truncation)]
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
return Ok(Bool::Term(n as u8));
|
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 {
|
if_chain! {
|
||||||
hir_id: DUMMY_HIR_ID,
|
if let ExprKind::Binary(e_binop, e_lhs, e_rhs) = &e.node;
|
||||||
span: DUMMY_SP,
|
if implements_ord(self.cx, e_lhs);
|
||||||
attrs: ThinVec::new(),
|
if let ExprKind::Binary(expr_binop, expr_lhs, expr_rhs) = &expr.node;
|
||||||
node: ExprKind::Binary(dummy_spanned(op), lhs.clone(), rhs.clone()),
|
if negate(e_binop.node) == Some(expr_binop.node);
|
||||||
};
|
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e_lhs, expr_lhs);
|
||||||
match binop.node {
|
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e_rhs, expr_rhs);
|
||||||
BinOpKind::Eq => mk_expr(BinOpKind::Ne),
|
then {
|
||||||
BinOpKind::Ne => mk_expr(BinOpKind::Eq),
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
BinOpKind::Gt => mk_expr(BinOpKind::Le),
|
return Ok(Bool::Not(Box::new(Bool::Term(n as u8))));
|
||||||
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))));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let n = self.terminals.len();
|
let n = self.terminals.len();
|
||||||
|
|
|
@ -36,7 +36,7 @@ declare_lint_pass!(DoubleComparisons => [DOUBLE_COMPARISONS]);
|
||||||
impl<'a, 'tcx> DoubleComparisons {
|
impl<'a, 'tcx> DoubleComparisons {
|
||||||
#[allow(clippy::similar_names)]
|
#[allow(clippy::similar_names)]
|
||||||
fn check_binop(self, cx: &LateContext<'a, 'tcx>, op: BinOpKind, lhs: &'tcx Expr, rhs: &'tcx Expr, span: Span) {
|
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)) => {
|
(ExprKind::Binary(lb, llhs, lrhs), ExprKind::Binary(rb, rlhs, rrhs)) => {
|
||||||
(lb.node, llhs, lrhs, rb.node, rlhs, rrhs)
|
(lb.node, llhs, lrhs, rb.node, rlhs, rrhs)
|
||||||
},
|
},
|
||||||
|
|
|
@ -42,7 +42,7 @@ declare_clippy_lint! {
|
||||||
#[allow(clippy::module_name_repetitions)]
|
#[allow(clippy::module_name_repetitions)]
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct MultipleInherentImpl {
|
pub struct MultipleInherentImpl {
|
||||||
impls: FxHashMap<def_id::DefId, (Span, Generics)>,
|
impls: FxHashMap<def_id::DefId, Span>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_lint_pass!(MultipleInherentImpl => [MULTIPLE_INHERENT_IMPL]);
|
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) {
|
fn check_item(&mut self, _: &LateContext<'a, 'tcx>, item: &'tcx Item) {
|
||||||
if let ItemKind::Impl(_, _, _, ref generics, None, _, _) = item.node {
|
if let ItemKind::Impl(_, _, _, ref generics, None, _, _) = item.node {
|
||||||
// Remember for each inherent implementation encoutered its span and generics
|
// Remember for each inherent implementation encoutered its span and generics
|
||||||
self.impls
|
// but filter out implementations that have generic params (type or lifetime)
|
||||||
.insert(item.hir_id.owner_def_id(), (item.span, generics.clone()));
|
if generics.params.len() == 0 {
|
||||||
|
self.impls.insert(item.hir_id.owner_def_id(), item.span);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,10 +68,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MultipleInherentImpl {
|
||||||
.values()
|
.values()
|
||||||
{
|
{
|
||||||
// Filter out implementations that have generic params (type or lifetime)
|
// Filter out implementations that have generic params (type or lifetime)
|
||||||
let mut impl_spans = impls
|
let mut impl_spans = impls.iter().filter_map(|impl_def| self.impls.get(impl_def));
|
||||||
.iter()
|
|
||||||
.filter_map(|impl_def| self.impls.get(impl_def))
|
|
||||||
.filter_map(|(span, generics)| if generics.params.len() == 0 { Some(span) } else { None });
|
|
||||||
if let Some(initial_span) = impl_spans.nth(0) {
|
if let Some(initial_span) = impl_spans.nth(0) {
|
||||||
impl_spans.for_each(|additional_span| {
|
impl_spans.for_each(|additional_span| {
|
||||||
span_lint_and_then(
|
span_lint_and_then(
|
||||||
|
|
|
@ -129,7 +129,7 @@ impl QuestionMark {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
// Check if last expression is a return statement. Then, return the expression
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if block.stmts.len() == 1;
|
if block.stmts.len() == 1;
|
||||||
|
@ -139,7 +139,7 @@ impl QuestionMark {
|
||||||
if let &Some(ref ret_expr) = ret_expr;
|
if let &Some(ref ret_expr) = ret_expr;
|
||||||
|
|
||||||
then {
|
then {
|
||||||
return Some(ret_expr.clone());
|
return Some(ret_expr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ impl QuestionMark {
|
||||||
if block.stmts.len() == 0;
|
if block.stmts.len() == 0;
|
||||||
if let Some(ExprKind::Ret(Some(ret_expr))) = block.expr.as_ref().map(|e| &e.node);
|
if let Some(ExprKind::Ret(Some(ret_expr))) = block.expr.as_ref().map(|e| &e.node);
|
||||||
then {
|
then {
|
||||||
return Some(ret_expr.clone());
|
return Some(ret_expr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
// Get the implemented trait for the current function
|
||||||
let parent_impl = cx.tcx.hir().get_parent_item(hir_id);
|
let parent_impl = cx.tcx.hir().get_parent_item(hir_id);
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if parent_impl != hir::CRATE_HIR_ID;
|
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::Node::Item(item) = cx.tcx.hir().get_by_hir_id(parent_impl);
|
||||||
if let hir::ItemKind::Impl(_, _, _, _, trait_ref, _, _) = &item.node;
|
if let hir::ItemKind::Impl(_, _, _, _, trait_ref, _, _) = &item.node;
|
||||||
then { return trait_ref.clone(); }
|
then { return trait_ref.as_ref(); }
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue