about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-05-02 07:03:28 +0000
committerbors <bors@rust-lang.org>2019-05-02 07:03:28 +0000
commit1cf5d7f04cc73f99ee19be6b93304666f5845665 (patch)
treec9c18b586553b748bf65a7c73552fff495cab747
parent2ed0b3bfa05c796c6645ed1814cd372e73f45c66 (diff)
parentbb12d59551c046d288801264a56560321d10bf35 (diff)
downloadrust-1cf5d7f04cc73f99ee19be6b93304666f5845665.tar.gz
rust-1cf5d7f04cc73f99ee19be6b93304666f5845665.zip
Auto merge of #4035 - JoshMcguigan:useless_let_if_seq-3043, r=oli-obk
useless_let_if_seq handle interior mutability

fixes #3043

This passes all tests, including a new one specifically dealing with a type with interior mutability. The main thing I'm unsure of is whether the span I used in the call to `is_freeze` is the most appropriate span to use, or if it matters.
-rw-r--r--clippy_lints/src/let_if_seq.rs7
-rw-r--r--tests/ui/let_if_seq.rs8
2 files changed, 15 insertions, 0 deletions
diff --git a/clippy_lints/src/let_if_seq.rs b/clippy_lints/src/let_if_seq.rs
index f5da2d7803e..36ba198de8d 100644
--- a/clippy_lints/src/let_if_seq.rs
+++ b/clippy_lints/src/let_if_seq.rs
@@ -71,6 +71,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
                 then {
                     let span = stmt.span.to(if_.span);
 
+                    let has_interior_mutability = !cx.tables.node_type(canonical_id).is_freeze(
+                        cx.tcx,
+                        cx.param_env,
+                        span
+                    );
+                    if has_interior_mutability { return; }
+
                     let (default_multi_stmts, default) = if let Some(ref else_) = *else_ {
                         if let hir::ExprKind::Block(ref else_, _) = else_.node {
                             if let Some(default) = check_assign(cx, canonical_id, else_) {
diff --git a/tests/ui/let_if_seq.rs b/tests/ui/let_if_seq.rs
index 5bfa32dd56c..802beeb4be6 100644
--- a/tests/ui/let_if_seq.rs
+++ b/tests/ui/let_if_seq.rs
@@ -108,4 +108,12 @@ fn main() {
     }
 
     baz = 1337;
+
+    // issue 3043 - types with interior mutability should not trigger this lint
+    use std::cell::Cell;
+    let mut val = Cell::new(1);
+    if true {
+        val = Cell::new(2);
+    }
+    println!("{}", val.get());
 }