diff options
| author | kraktus <kraktus@users.noreply.github.com> | 2022-10-21 13:48:41 +0200 |
|---|---|---|
| committer | kraktus <kraktus@users.noreply.github.com> | 2022-10-21 13:48:41 +0200 |
| commit | 615b7617ed3ba1ea44575a9072b17a4bdfb565b2 (patch) | |
| tree | aea9e26b45f5613c7a5afa30c2e56928d0ca7cb8 | |
| parent | 967f172e256802f9bf0ad5718d9c761da18132a9 (diff) | |
| download | rust-615b7617ed3ba1ea44575a9072b17a4bdfb565b2.tar.gz rust-615b7617ed3ba1ea44575a9072b17a4bdfb565b2.zip | |
`ref_option_ref` do not lint when inner reference is mutable
As it makes the `Option` Non Copy
| -rw-r--r-- | clippy_lints/src/ref_option_ref.rs | 3 | ||||
| -rw-r--r-- | tests/ui/ref_option_ref.rs | 5 |
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:?}"); +} |
