Skip to content

Commit

Permalink
Auto merge of #4035 - JoshMcguigan:useless_let_if_seq-3043, r=oli-obk
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed May 2, 2019
2 parents 2ed0b3b + bb12d59 commit 1cf5d7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions clippy_lints/src/let_if_seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/let_if_seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

0 comments on commit 1cf5d7f

Please sign in to comment.