-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
uninit_vec: fix false positive with set_len(0) #9519
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @llogiq (or someone else) soon. Please see the contribution instructions for more information. |
clippy_lints/src/uninit_vec.rs
Outdated
@@ -211,9 +212,12 @@ fn extract_set_len_self<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'_>) -> Opt | |||
} | |||
}); | |||
match expr.kind { | |||
ExprKind::MethodCall(path, self_expr, [_], _) => { | |||
ExprKind::MethodCall(path, self_expr, args, _) => { |
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.
ExprKind::MethodCall(path, self_expr, args, _) => { | |
ExprKind::MethodCall(path, self_expr, [arg], _) => { |
You can match the single arg directly, because all set_len
calls have exactly one argument. This will save you an if let
in is_literal_zero
.
Thank you for the PR. I have only a very small style suggestion, otherwise this looks mergeworthy. |
set_len(0) does not create uninitialized elements. Fixes a false positive with the following pattern: fn copy_slice_into_vec(dst: &mut Vec<u8>, src: &[u8]) { dst.reserve(src.len().saturating_sub(dst.len())); unsafe { dst.set_len(0); std::ptr::copy_nonoverlapping(src.as_ptr(), dst.as_mut_ptr(), src.len()); dst.set_len(src.len()); } }
ce0fb7e
to
49319b4
Compare
Thanks for reviewing! |
Thank you! @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
set_len(0)
does not create uninitialized elements. Fixes a false positive with the following pattern:zulip thread: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/uninit_vec.20and.20set_len.280.29
changelog: FP: [
uninit_vec
]: No longer lintsVec::set_len(0)