[significant_drop_tightening] Fix #11189
This commit is contained in:
parent
fca1f9aec5
commit
f0a16bb8a3
@ -331,13 +331,13 @@ fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
|
||||
apa.last_method_span = span;
|
||||
}
|
||||
},
|
||||
hir::StmtKind::Semi(expr) => {
|
||||
if has_drop(expr, &apa.first_bind_ident, self.cx) {
|
||||
hir::StmtKind::Semi(semi_expr) => {
|
||||
if has_drop(semi_expr, &apa.first_bind_ident, self.cx) {
|
||||
apa.has_expensive_expr_after_last_attr = false;
|
||||
apa.last_stmt_span = DUMMY_SP;
|
||||
return;
|
||||
}
|
||||
if let hir::ExprKind::MethodCall(_, _, _, span) = expr.kind {
|
||||
if let hir::ExprKind::MethodCall(_, _, _, span) = semi_expr.kind {
|
||||
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
|
||||
&& lcx.tcx.is_diagnostic_item(sym::mem_drop, did)
|
||||
&& 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 {
|
||||
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 {
|
||||
|
@ -58,6 +58,26 @@ pub fn issue_11160() -> bool {
|
||||
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 {
|
||||
let mutex = Mutex::new(1);
|
||||
let lock = mutex.lock().unwrap();
|
||||
|
@ -57,6 +57,26 @@ pub fn issue_11160() -> bool {
|
||||
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 {
|
||||
let mutex = Mutex::new(1);
|
||||
let lock = mutex.lock().unwrap();
|
||||
|
@ -23,7 +23,7 @@ LL + drop(lock);
|
||||
|
|
||||
|
||||
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 | | let mutex = Mutex::new(1i32);
|
||||
@ -43,7 +43,7 @@ LL + drop(lock);
|
||||
|
|
||||
|
||||
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 | | let mutex = Mutex::new(1i32);
|
||||
@ -67,7 +67,7 @@ LL +
|
||||
|
|
||||
|
||||
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 | | let mutex = Mutex::new(vec![1i32]);
|
||||
|
Loading…
Reference in New Issue
Block a user