Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useless_let_if_seq handle interior mutability #4035

Merged
merged 2 commits into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}