about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-10-21 20:19:30 +0000
committerbors <bors@rust-lang.org>2022-10-21 20:19:30 +0000
commitb72e451310d65ddf69441a641e2ebd6886c813b8 (patch)
tree0ed219e19c2bb0e08f8de2f903d1c91202993c86
parentb2e5a719bbe4e337757b6d39363df2c801da4a60 (diff)
parent615b7617ed3ba1ea44575a9072b17a4bdfb565b2 (diff)
downloadrust-b72e451310d65ddf69441a641e2ebd6886c813b8.tar.gz
rust-b72e451310d65ddf69441a641e2ebd6886c813b8.zip
Auto merge of #9684 - kraktus:ref_option_ref, r=xFrednet
`ref_option_ref` do not lint when inner reference is mutable

changelog: FP: [`ref_option_ref`]: No longer lints if the inner reference is mutable

fix https://github.com/rust-lang/rust-clippy/issues/9682
-rw-r--r--clippy_lints/src/ref_option_ref.rs3
-rw-r--r--tests/ui/ref_option_ref.rs5
2 files changed, 7 insertions, 1 deletions
diff --git a/clippy_lints/src/ref_option_ref.rs b/clippy_lints/src/ref_option_ref.rs
index 42514f861be..f21b3ea6c3b 100644
--- a/clippy_lints/src/ref_option_ref.rs
+++ b/clippy_lints/src/ref_option_ref.rs
@@ -52,7 +52,8 @@ impl<'tcx> LateLintPass<'tcx> for RefOptionRef {
                 GenericArg::Type(inner_ty) => Some(inner_ty),
                 _ => None,
             });
-            if let TyKind::Rptr(_, _) = inner_ty.kind;
+            if let TyKind::Rptr(_, ref inner_mut_ty) = inner_ty.kind;
+            if inner_mut_ty.mutbl == Mutability::Not;
 
             then {
                 span_lint_and_sugg(
diff --git a/tests/ui/ref_option_ref.rs b/tests/ui/ref_option_ref.rs
index 2df45c927d7..e487799e152 100644
--- a/tests/ui/ref_option_ref.rs
+++ b/tests/ui/ref_option_ref.rs
@@ -45,3 +45,8 @@ impl RefOptTrait for u32 {
 fn main() {
     let x: &Option<&u32> = &None;
 }
+
+fn issue9682(arg: &Option<&mut String>) {
+    // Should not lint, as the inner ref is mutable making it non `Copy`
+    println!("{arg:?}");
+}