Rust-clippy: lint type `&Option<&T>`

Created on 6 Dec 2016  路  4Comments  路  Source: rust-lang/rust-clippy

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

A-unnecessary L-lint T-middle good-first-issue hacktoberfest

Most helpful comment

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>

All 4 comments

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

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.

@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.

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>

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dtolnay picture dtolnay  路  20Comments

Manishearth picture Manishearth  路  18Comments

casey picture casey  路  19Comments

Shnatsel picture Shnatsel  路  25Comments

Shnatsel picture Shnatsel  路  23Comments