You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently, I was looking at some code in winit and failed to understand this code. There is a cache using Mutex<Option<...>>. The code here tries to either copy the value contained in the cache or fill the cache.
The first part of my problem was that I somehow thought that .as_ref().cloned() does something to the inner contents and not the Option directly
The text was updated successfully, but these errors were encountered:
new lint: `option_as_ref_cloned`
Closes#12009
Adds a new lint that looks for `.as_ref().cloned()` on `Option`s. That's the same as just `.clone()`-ing the option directly.
changelog: new lint: [`option_as_ref_cloned`]
What it does
Search for code doing
.as_ref().cloned()
on anOption<T>
and suggests to just use.clone()
directly.Advantage
Drawbacks
🤷
Example
Self-contained example:
Could be written as:
Recently, I was looking at some code in winit and failed to understand this code. There is a cache using
Mutex<Option<...>>
. The code here tries to either copy the value contained in the cache or fill the cache.The first part of my problem was that I somehow thought that
.as_ref().cloned()
does something to the inner contents and not theOption
directlyThe text was updated successfully, but these errors were encountered: