Skip to content

ref_option_ref should not trigger for mutable references #9682

Closed
@michalburger1

Description

@michalburger1

Summary

The lint tells you to use Option<&T> instead of &Option<&T> because the former is Copy so there's no point in passing around references. However, the lint seems to also triggers for &Option<&mut T> and tells you to use Option<&mut T> instead, which is not Copy.

Lint Name

ref_option_ref

Reproducer

I tried this code:

fn foo(arg: &Option<&mut String>) {
    println!("{:?}", arg);
}

I saw this happen:

since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>`

I expected to see this happen:

No lint warnings.

Version

rustc 1.64.0 (a55dd71d5 2022-09-19)
binary: rustc
commit-hash: a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52
commit-date: 2022-09-19
host: x86_64-pc-windows-msvc
release: 1.64.0
LLVM version: 14.0.6

Additional Labels

@rustbot label +l-suggestion-causes-error

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedgood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions