Skip to content

Commit 1cf5d7f

Browse files
committed
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.
2 parents 2ed0b3b + bb12d59 commit 1cf5d7f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

clippy_lints/src/let_if_seq.rs

+7
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

+8
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,12 @@ 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());
111119
}

0 commit comments

Comments
 (0)