mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-03-01 13:57:21 +00:00
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.
This commit is contained in:
commit
1cf5d7f04c
2 changed files with 15 additions and 0 deletions
|
@ -71,6 +71,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
|
||||||
then {
|
then {
|
||||||
let span = stmt.span.to(if_.span);
|
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_ {
|
let (default_multi_stmts, default) = if let Some(ref else_) = *else_ {
|
||||||
if let hir::ExprKind::Block(ref else_, _) = else_.node {
|
if let hir::ExprKind::Block(ref else_, _) = else_.node {
|
||||||
if let Some(default) = check_assign(cx, canonical_id, else_) {
|
if let Some(default) = check_assign(cx, canonical_id, else_) {
|
||||||
|
|
|
@ -108,4 +108,12 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
baz = 1337;
|
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());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue