-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Needless borrow lint #884
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
Needless borrow lint #884
Conversation
if let ExprAddrOf(MutImmutable, ref inner) = e.node { | ||
if let TyRef(..) = cx.tcx.expr_ty(inner).sty { | ||
let ty = cx.tcx.expr_ty(e); | ||
let adj_ty = cx.tcx.expr_ty_adjusted(e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are other kinds of adjustment, rustc::ty::Tables::adjustments
+ AdjustDerefRef
would maybe be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's relevant, because I'm testing for &
ops on ref types, any adjustments that can happen, will still happen when you remove the &
op, because it's already a ref type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, I think that might decrease the usefulness of this lint. Because then
let x: &[u8] = &&Vec::new();
would not trigger anymore, even though it should be
let x: &[u8] = &Vec::new();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also test if the adjusted type of inner
is the same as the adjusted type of e
rebased |
1 similar comment
rebased |
@mcarton LGTM, but since you reviewed, I'd like to know if you have any issue that should be resolved before merging. |
rebased |
@oli-obk I’m ready to merge but I just don’t like the name of the lint, |
sgtm |
although sometimes it can be either ;) |
do we have a lint that lints on using |
Good work everyone! |
This lint can be very annoying if it has false positives (which my first naive version had). So give me suggestions to run this on :)
Crates without false positives:
Crates to test:
Crates with false positives: