diff options
| author | Josh Mcguigan <joshmcg88@gmail.com> | 2019-04-25 19:07:01 -0700 |
|---|---|---|
| committer | Josh Mcguigan <joshmcg88@gmail.com> | 2019-04-25 19:07:01 -0700 |
| commit | 2bbe8be8d0583afb370f01d8afce9d7a38e46a47 (patch) | |
| tree | 924c0ef5b044a170974af9277481da1b4dd7039b | |
| parent | 6ae46a8c4dc6904c1359c823316c02d254fa6f96 (diff) | |
| download | rust-2bbe8be8d0583afb370f01d8afce9d7a38e46a47.tar.gz rust-2bbe8be8d0583afb370f01d8afce9d7a38e46a47.zip | |
useless_let_if_seq handle interior mutability
| -rw-r--r-- | clippy_lints/src/let_if_seq.rs | 7 | ||||
| -rw-r--r-- | tests/ui/let_if_seq.rs | 9 |
2 files changed, 16 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..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()); + } |
