deprecate assign_ops lint

This commit is contained in:
Jonathan Goodman 2018-08-09 14:14:12 -05:00
parent 99a087bea5
commit 160b41dae3
5 changed files with 51 additions and 169 deletions

View file

@ -7,25 +7,6 @@ use rustc::{declare_lint, lint_array};
use if_chain::if_chain;
use syntax::ast;
/// **What it does:** Checks for compound assignment operations (`+=` and
/// similar).
///
/// **Why is this bad?** Projects with many developers from languages without
/// those operations may find them unreadable and not worth their weight.
///
/// **Known problems:** Types implementing `OpAssign` don't necessarily
/// implement `Op`.
///
/// **Example:**
/// ```rust
/// a += 1;
/// ```
declare_clippy_lint! {
pub ASSIGN_OPS,
restriction,
"any compound assignment operation"
}
/// **What it does:** Checks for `a = a op b` or `a = b commutative_op a`
/// patterns.
///
@ -73,7 +54,7 @@ pub struct AssignOps;
impl LintPass for AssignOps {
fn get_lints(&self) -> LintArray {
lint_array!(ASSIGN_OPS, ASSIGN_OP_PATTERN, MISREFACTORED_ASSIGN_OP)
lint_array!(ASSIGN_OP_PATTERN, MISREFACTORED_ASSIGN_OP)
}
}
@ -81,16 +62,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
match expr.node {
hir::ExprKind::AssignOp(op, ref lhs, ref rhs) => {
span_lint_and_then(cx, ASSIGN_OPS, expr.span, "assign operation detected", |db| {
let lhs = &sugg::Sugg::hir(cx, lhs, "..");
let rhs = &sugg::Sugg::hir(cx, rhs, "..");
db.span_suggestion(
expr.span,
"replace it with",
format!("{} = {}", lhs, sugg::make_binop(higher::binop(op.node), lhs, rhs)),
);
});
if let hir::ExprKind::Binary(binop, ref l, ref r) = rhs.node {
if op.node == binop.node {
let lint = |assignee: &hir::Expr, rhs_other: &hir::Expr| {

View file

@ -82,3 +82,13 @@ declare_deprecated_lint! {
pub MISALIGNED_TRANSMUTE,
"this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr"
}
/// **What it does:** Nothing. This lint has been deprecated.
///
/// **Deprecation reason:** This lint is too subjective, not having a good reason for being in clippy.
/// Additionally, compound assignment operators may be overloaded separately from their non-assigning
/// counterparts, so this lint may suggest a change in behavior or the code may not compile.
declare_deprecated_lint! {
pub ASSIGN_OPS,
"using compound assignment operators (e.g. `+=`) is harmless"
}

View file

@ -261,6 +261,10 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>) {
"misaligned_transmute",
"this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr",
);
store.register_removed(
"assign_ops",
"using compound assignment operators (e.g. `+=`) is harmless",
);
// end deprecated lints, do not remove this comment, its used in `update_lints`
reg.register_late_lint_pass(box serde_api::Serde);
@ -406,7 +410,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>) {
reg.register_lint_group("clippy_restriction", vec![
arithmetic::FLOAT_ARITHMETIC,
arithmetic::INTEGER_ARITHMETIC,
assign_ops::ASSIGN_OPS,
else_if_without_else::ELSE_IF_WITHOUT_ELSE,
indexing_slicing::INDEXING_SLICING,
inherent_impl::MULTIPLE_INHERENT_IMPL,