From 2bbe8be8d0583afb370f01d8afce9d7a38e46a47 Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Thu, 25 Apr 2019 19:07:01 -0700 Subject: [PATCH 1/2] useless_let_if_seq handle interior mutability --- clippy_lints/src/let_if_seq.rs | 7 +++++++ tests/ui/let_if_seq.rs | 9 +++++++++ 2 files changed, 16 insertions(+) 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..e5195011702 100644 --- a/tests/ui/let_if_seq.rs +++ b/tests/ui/let_if_seq.rs @@ -108,4 +108,13 @@ 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()); + } From bb12d59551c046d288801264a56560321d10bf35 Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Thu, 25 Apr 2019 19:41:23 -0700 Subject: [PATCH 2/2] cargo fmt --- tests/ui/let_if_seq.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/ui/let_if_seq.rs b/tests/ui/let_if_seq.rs index e5195011702..802beeb4be6 100644 --- a/tests/ui/let_if_seq.rs +++ b/tests/ui/let_if_seq.rs @@ -116,5 +116,4 @@ fn main() { val = Cell::new(2); } println!("{}", val.get()); - }