feat(lint): deref and deref_mut method explicit calls#3258
Conversation
|
@mikerite thanks for the feedback. I'll also rename to Could you advise on why travis-ci and appveyor disagree, and which to trust?
edit: updated my local nightly version |
|
Travis and appveyor check if clippy compiles with rustc Currently Travis fails because of (This only gets checked in travis) Also could you leave the requested comment in #3230, after this gets merged? |
| /// let c = a.deref_mut(); | ||
| /// | ||
| /// // excludes | ||
| /// let e = d.deref().unwrap(); |
There was a problem hiding this comment.
Does your lint exclude these cases? Since _.deref().len() gets linted, I have a feeling, that also _.unwrap() will get linted.
There was a problem hiding this comment.
Quite correct - should be the other way round. d.unwrap().deref() would not be linted.
There was a problem hiding this comment.
Could you also add a test for this?
There was a problem hiding this comment.
In a method chain, deref will only be linted if it is the first method in the chain.
There was a problem hiding this comment.
Oh yeah, I missed that, thanks!
|
This lint produces suggestions, that lead to erroneous code: Playground |
|
Hmm, thanks for catching. Technically, we could suggest I need to alter the linting to only pick up on |
|
ping @tommilligan If you don't have the motivation to fix the suggestion (this can take a while to do), you can replace the
|
|
@flip1995 thanks for the ping. I believe my current implementation is actively unhelpful in some circumstances, so I'm not happy releasing it into the wild as is. I'll try to come back and revisit soon |
|
Ping from triage @tommilligan. Do you want to continue working on this? |
|
Ping from triage @tommilligan: It looks like this PR hasn't received any updates in a while, so I'm closing it per our new guidelines. Thank you for your contributions and please feel free to re-open in the future. |
Add lint for explicit deref and deref_mut method calls This PR adds the lint `explicit_deref_method` that suggests replacing `deref()` and `deref_mut()` with `&*a` and `&mut *a`. It doesn't lint inside macros. This PR is the continuation of rust-lang#3258. changelog: Add lint `explicit_deref_method`. Fixes: rust-lang#1566
|
@rustbot label -S-inactive-closed |
This PR adds a lint
deref_method_explicit(all,complexity), which fulfils the above criteria. Matching ui test and output have also been added.I'm not certain how best to handle macro expansions as part of the lint - if a macro contains a
deref()call for instance. If someone could provide a failing testcase for me to work against that would be great.Closes #1566