-
Notifications
You must be signed in to change notification settings - Fork 1.7k
get_last_with_len
: lint VecDeque
and any deref to slice
#8862
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
Conversation
r? @xFrednet (rust-highfive has picked a reviewer for you, use r? to override) |
r? @Jarcho 🙃 |
// check that recv == lhs_recv `recv.get(lhs_recv.len() - 1)` | ||
&& path_to_local(lhs_recv) == Some(recv_local) | ||
{ | ||
let method = match cx.typeck_results().expr_ty_adjusted(recv).peel_refs().kind() { |
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.
Quick question here. This allows any type which derefs to a VecDeque
or a slice. Is that intentional?
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.
It is yeah
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 know if you want to handle this horrible case or not:
struct Foo(Vec<u32>);
impl Deref for Foo { type Target = Vec<u32>; ... }
impl Foo {
// Only replace `last`, but not `get`
fn last(&self) -> SomeType { ... }
}
I don't think it's necessary to do so. It's kind of a pathological case.
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'm happy to leave that one out, can't imagine it coming up
f2964f2
to
6379276
Compare
Can you add a test for a field access as well just to make sure it doesn't break in the future. Otherwise looks good. @xFrednet I don't know if you want to add anything before merging. |
previously only vecs were supported
6379276
to
8558490
Compare
👍 added |
📌 Commit 8558490 has been approved by |
`get_last_with_len`: lint `VecDeque` and any deref to slice changelog: [`get_last_with_len`]: lint `VecDeque` and any deref to slice Previously only `Vec`s were linted, this will now catch any usages on slices, arrays, etc. It also suggests `.back()` for `VecDeque`s Also moves the lint into `methods/`
💔 Test failed - checks-action_test |
Seems like some CI weirdness. Maybe bors wanted a break ^^ @bors retry |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
changelog: [
get_last_with_len
]: lintVecDeque
and any deref to slicePreviously only
Vec
s were linted, this will now catch any usages on slices, arrays, etc. It also suggests.back()
forVecDeque
sAlso moves the lint into
methods/