Skip to content

Commit 2bbe8be

Browse files
committed
useless_let_if_seq handle interior mutability
1 parent 6ae46a8 commit 2bbe8be

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

clippy_lints/src/let_if_seq.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
7171
then {
7272
let span = stmt.span.to(if_.span);
7373

74+
let has_interior_mutability = !cx.tables.node_type(canonical_id).is_freeze(
75+
cx.tcx,
76+
cx.param_env,
77+
span
78+
);
79+
if has_interior_mutability { return; }
80+
7481
let (default_multi_stmts, default) = if let Some(ref else_) = *else_ {
7582
if let hir::ExprKind::Block(ref else_, _) = else_.node {
7683
if let Some(default) = check_assign(cx, canonical_id, else_) {

tests/ui/let_if_seq.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,13 @@ fn main() {
108108
}
109109

110110
baz = 1337;
111+
112+
// issue 3043 - types with interior mutability should not trigger this lint
113+
use std::cell::Cell;
114+
let mut val = Cell::new(1);
115+
if true {
116+
val = Cell::new(2);
117+
}
118+
println!("{}", val.get());
119+
111120
}

0 commit comments

Comments
 (0)