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

lint type &Option<&T> #1377

Closed
oli-obk opened this issue Dec 6, 2016 · 4 comments
Closed

lint type &Option<&T> #1377

oli-obk opened this issue Dec 6, 2016 · 4 comments
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-unnecessary Lint: Warn about unnecessary code T-middle Type: Probably requires verifiying types

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Dec 6, 2016

since & is Copy, just suggest to use Option<&T>

@oli-obk oli-obk added L-unnecessary Lint: Warn about unnecessary code good-first-issue These issues are a good way to get started with Clippy A-lint Area: New lints T-middle Type: Probably requires verifiying types labels Dec 6, 2016
@clarfonthey
Copy link

clarfonthey commented Dec 8, 2016

This applies to &mut Option<&mut T> too, because as_ref and as_mut exist. Ditto for Result.

@shepmaster
Copy link
Member

This applies to &mut Option<&mut T> too

Does it though? With a &mut Option<T>, I could mem::replace or mem::swap it with a completely different option, or call Option::take on it, which does the same thing internally.

@clarfonthey
Copy link

@shepmaster I think you misunderstood; &mut Option<&mut T> should be written as Option<&mut T>, not &mut Option<T>. This is very similar to writing &&T instead of &T.

@Manishearth
Copy link
Member

I think you misunderstood; &mut Option<&mut T> should be written as Option<&mut T>, not &mut Option.

@shepmaster's comment still applies. You cannot set the shared Option to None with Option<&mut T>

bors added a commit that referenced this issue Nov 3, 2020
Add lint 'ref_option_ref' #1377

This lint checks for usage of `&Option<&T>` which can be simplified as `Option<&T>` as suggested in #1377.

This WIP PR is here to get feedback on the lint as there's more cases to be handled:
* statics/consts,
* associated types,
* type alias,
* function/method parameter/return,
* ADT definitions (struct/tuple struct fields, enum variants)

changelog: Add 'ref_option_ref' lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-unnecessary Lint: Warn about unnecessary code T-middle Type: Probably requires verifiying types
Projects
None yet
Development

No branches or pull requests

5 participants