Skip to content

Commit 851e715

Browse files
committed
Don't lint ptr_arg on &mut Cow<_>
1 parent b83c632 commit 851e715

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clippy_lints/src/ptr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
436436
DerefTy::Path,
437437
None,
438438
),
439-
Some(sym::Cow) => {
439+
Some(sym::Cow) if mutability == Mutability::Not => {
440440
let ty_name = name.args
441441
.and_then(|args| {
442442
args.args.iter().find_map(|a| match a {

tests/ui/ptr_arg.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,10 @@ fn two_vecs(a: &mut Vec<u32>, b: &mut Vec<u32>) {
194194
a.push(0);
195195
b.push(1);
196196
}
197+
198+
// Issue #8495
199+
fn cow_conditional_to_mut(a: &mut Cow<str>) {
200+
if a.is_empty() {
201+
a.to_mut().push_str("foo");
202+
}
203+
}

0 commit comments

Comments
 (0)