mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
Auto merge of #11196 - c410-f3r:let-chain, r=xFrednet
[significant_drop_tightening] Fix #11189 Fix #11189 ``` changelog: FP: [`significant_drop_tightening`]: Consider tuples in drop calls ```
This commit is contained in:
commit
ea21ed7f10
4 changed files with 64 additions and 12 deletions
|
@ -331,13 +331,13 @@ impl<'ap, 'lc, 'others, 'stmt, 'tcx> Visitor<'tcx> for StmtsChecker<'ap, 'lc, 'o
|
||||||
apa.last_method_span = span;
|
apa.last_method_span = span;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
hir::StmtKind::Semi(expr) => {
|
hir::StmtKind::Semi(semi_expr) => {
|
||||||
if has_drop(expr, &apa.first_bind_ident, self.cx) {
|
if has_drop(semi_expr, &apa.first_bind_ident, self.cx) {
|
||||||
apa.has_expensive_expr_after_last_attr = false;
|
apa.has_expensive_expr_after_last_attr = false;
|
||||||
apa.last_stmt_span = DUMMY_SP;
|
apa.last_stmt_span = DUMMY_SP;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let hir::ExprKind::MethodCall(_, _, _, span) = expr.kind {
|
if let hir::ExprKind::MethodCall(_, _, _, span) = semi_expr.kind {
|
||||||
apa.last_method_span = span;
|
apa.last_method_span = span;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -435,14 +435,26 @@ fn has_drop(expr: &hir::Expr<'_>, first_bind_ident: &Ident, lcx: &LateContext<'_
|
||||||
&& let Res::Def(DefKind::Fn, did) = fun_path.res
|
&& let Res::Def(DefKind::Fn, did) = fun_path.res
|
||||||
&& lcx.tcx.is_diagnostic_item(sym::mem_drop, did)
|
&& lcx.tcx.is_diagnostic_item(sym::mem_drop, did)
|
||||||
&& let [first_arg, ..] = args
|
&& let [first_arg, ..] = args
|
||||||
&& let hir::ExprKind::Path(hir::QPath::Resolved(_, arg_path)) = &first_arg.kind
|
|
||||||
&& let [first_arg_ps, .. ] = arg_path.segments
|
|
||||||
{
|
{
|
||||||
&first_arg_ps.ident == first_bind_ident
|
let has_ident = |local_expr: &hir::Expr<'_>| {
|
||||||
|
if let hir::ExprKind::Path(hir::QPath::Resolved(_, arg_path)) = &local_expr.kind
|
||||||
|
&& let [first_arg_ps, .. ] = arg_path.segments
|
||||||
|
&& &first_arg_ps.ident == first_bind_ident
|
||||||
|
{
|
||||||
|
true
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
if has_ident(first_arg) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if let hir::ExprKind::Tup(value) = &first_arg.kind && value.iter().any(has_ident) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_inexpensive_expr(expr: &hir::Expr<'_>) -> bool {
|
fn is_inexpensive_expr(expr: &hir::Expr<'_>) -> bool {
|
||||||
|
|
|
@ -58,6 +58,26 @@ pub fn issue_11160() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn issue_11189() {
|
||||||
|
struct Number {
|
||||||
|
pub value: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn do_something() -> Result<(), ()> {
|
||||||
|
let number = Mutex::new(Number { value: 1 });
|
||||||
|
let number2 = Mutex::new(Number { value: 2 });
|
||||||
|
let number3 = Mutex::new(Number { value: 3 });
|
||||||
|
let mut lock = number.lock().unwrap();
|
||||||
|
let mut lock2 = number2.lock().unwrap();
|
||||||
|
let mut lock3 = number3.lock().unwrap();
|
||||||
|
lock.value += 1;
|
||||||
|
lock2.value += 1;
|
||||||
|
lock3.value += 1;
|
||||||
|
drop((lock, lock2, lock3));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn path_return_can_be_ignored() -> i32 {
|
pub fn path_return_can_be_ignored() -> i32 {
|
||||||
let mutex = Mutex::new(1);
|
let mutex = Mutex::new(1);
|
||||||
let lock = mutex.lock().unwrap();
|
let lock = mutex.lock().unwrap();
|
||||||
|
|
|
@ -57,6 +57,26 @@ pub fn issue_11160() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn issue_11189() {
|
||||||
|
struct Number {
|
||||||
|
pub value: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn do_something() -> Result<(), ()> {
|
||||||
|
let number = Mutex::new(Number { value: 1 });
|
||||||
|
let number2 = Mutex::new(Number { value: 2 });
|
||||||
|
let number3 = Mutex::new(Number { value: 3 });
|
||||||
|
let mut lock = number.lock().unwrap();
|
||||||
|
let mut lock2 = number2.lock().unwrap();
|
||||||
|
let mut lock3 = number3.lock().unwrap();
|
||||||
|
lock.value += 1;
|
||||||
|
lock2.value += 1;
|
||||||
|
lock3.value += 1;
|
||||||
|
drop((lock, lock2, lock3));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn path_return_can_be_ignored() -> i32 {
|
pub fn path_return_can_be_ignored() -> i32 {
|
||||||
let mutex = Mutex::new(1);
|
let mutex = Mutex::new(1);
|
||||||
let lock = mutex.lock().unwrap();
|
let lock = mutex.lock().unwrap();
|
||||||
|
|
|
@ -23,7 +23,7 @@ LL + drop(lock);
|
||||||
|
|
|
|
||||||
|
|
||||||
error: temporary with significant `Drop` can be early dropped
|
error: temporary with significant `Drop` can be early dropped
|
||||||
--> $DIR/significant_drop_tightening.rs:86:13
|
--> $DIR/significant_drop_tightening.rs:106:13
|
||||||
|
|
|
|
||||||
LL | / {
|
LL | / {
|
||||||
LL | | let mutex = Mutex::new(1i32);
|
LL | | let mutex = Mutex::new(1i32);
|
||||||
|
@ -43,7 +43,7 @@ LL + drop(lock);
|
||||||
|
|
|
|
||||||
|
|
||||||
error: temporary with significant `Drop` can be early dropped
|
error: temporary with significant `Drop` can be early dropped
|
||||||
--> $DIR/significant_drop_tightening.rs:107:13
|
--> $DIR/significant_drop_tightening.rs:127:13
|
||||||
|
|
|
|
||||||
LL | / {
|
LL | / {
|
||||||
LL | | let mutex = Mutex::new(1i32);
|
LL | | let mutex = Mutex::new(1i32);
|
||||||
|
@ -67,7 +67,7 @@ LL +
|
||||||
|
|
|
|
||||||
|
|
||||||
error: temporary with significant `Drop` can be early dropped
|
error: temporary with significant `Drop` can be early dropped
|
||||||
--> $DIR/significant_drop_tightening.rs:113:17
|
--> $DIR/significant_drop_tightening.rs:133:17
|
||||||
|
|
|
|
||||||
LL | / {
|
LL | / {
|
||||||
LL | | let mutex = Mutex::new(vec![1i32]);
|
LL | | let mutex = Mutex::new(vec![1i32]);
|
||||||
|
|
Loading…
Reference in a new issue