From 851e715e5a7ac21007b9491c81916e854fbab22c Mon Sep 17 00:00:00 2001 From: Jason Newcomb Date: Wed, 16 Mar 2022 12:00:27 -0400 Subject: [PATCH] Don't lint `ptr_arg` on `&mut Cow<_>` --- clippy_lints/src/ptr.rs | 2 +- tests/ui/ptr_arg.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 9c776437d..ba1997e70 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -436,7 +436,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>( DerefTy::Path, None, ), - Some(sym::Cow) => { + Some(sym::Cow) if mutability == Mutability::Not => { let ty_name = name.args .and_then(|args| { args.args.iter().find_map(|a| match a { diff --git a/tests/ui/ptr_arg.rs b/tests/ui/ptr_arg.rs index 97990fedd..03dd938a2 100644 --- a/tests/ui/ptr_arg.rs +++ b/tests/ui/ptr_arg.rs @@ -194,3 +194,10 @@ fn two_vecs(a: &mut Vec, b: &mut Vec) { a.push(0); b.push(1); } + +// Issue #8495 +fn cow_conditional_to_mut(a: &mut Cow) { + if a.is_empty() { + a.to_mut().push_str("foo"); + } +}