Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref_option_ref should not trigger for mutable references #9682

Closed
michalburger1 opened this issue Oct 21, 2022 · 5 comments · Fixed by #9684
Closed

ref_option_ref should not trigger for mutable references #9682

michalburger1 opened this issue Oct 21, 2022 · 5 comments · Fixed by #9684
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@michalburger1
Copy link

michalburger1 commented Oct 21, 2022

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

@michalburger1 michalburger1 added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Oct 21, 2022
@rustbot
Copy link
Collaborator

rustbot commented Oct 21, 2022

Error: Label l-suggestion-causes-error can only be set by Rust team members

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

@michalburger1
Copy link
Author

Applying the suggestion would cause an error if you're also trying to use the value in other places (it can't be copied so it will be moved).

@kraktus
Copy link
Contributor

kraktus commented Oct 21, 2022

Can't reproduce on nightly so I assume it's been fixed

@Alexendoo
Copy link
Member

It's a pedantic lint so you'll need to enable it

@Alexendoo Alexendoo added good-first-issue These issues are a good way to get started with Clippy I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied labels Oct 21, 2022
@kraktus
Copy link
Contributor

kraktus commented Oct 21, 2022

right my bad!

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants