diff options
| author | bors <bors@rust-lang.org> | 2020-08-16 21:56:37 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-08-16 21:56:37 +0000 |
| commit | 8332fe81d888aaa081bf85e5695eaabd2624ea73 (patch) | |
| tree | d44d58b8093ea749dd64d37f188c41a9bc7a9e1c /clippy_lints/src/question_mark.rs | |
| parent | 8d0d89adc81be1fa7766ff17aa4f2c6d5e8c69f7 (diff) | |
| parent | 4f4abf4e0640edbb1614f3dcb8ff62e8afc54801 (diff) | |
Auto merge of #5894 - tmiasko:self-assignment, r=Manishearth
Warn about explicit self-assignment
Warn about assignments where left-hand side place expression is the same
as right-hand side value expression. For example, warn about assignment in:
```rust
pub struct Event {
id: usize,
x: i32,
y: i32,
}
pub fn copy_position(a: &mut Event, b: &Event) {
a.x = b.x;
a.y = a.y;
}
```
changelog: New lint `self_assignment`, checks for explicit self-assignments.
Diffstat (limited to 'clippy_lints/src/question_mark.rs')
| -rw-r--r-- | clippy_lints/src/question_mark.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index fb12c565afd..dbc676ae224 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -7,8 +7,8 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use crate::utils::sugg::Sugg; use crate::utils::{ - higher, is_type_diagnostic_item, match_def_path, match_qpath, paths, snippet_with_applicability, - span_lint_and_sugg, SpanlessEq, + eq_expr_value, higher, is_type_diagnostic_item, match_def_path, match_qpath, paths, snippet_with_applicability, + span_lint_and_sugg, }; declare_clippy_lint! { @@ -65,7 +65,7 @@ impl QuestionMark { if let ExprKind::Block(block, None) = &else_.kind; if block.stmts.is_empty(); if let Some(block_expr) = &block.expr; - if SpanlessEq::new(cx).ignore_fn().eq_expr(subject, block_expr); + if eq_expr_value(cx, subject, block_expr); then { replacement = Some(format!("Some({}?)", receiver_str)); } |
