-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Suggest Cstr::count_bytes in strlen_on_c_strings
#16323
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
base: master
Are you sure you want to change the base?
Conversation
|
@Tigls CI is failing on fmt check |
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.
Could you please add tests below/at the considered MSRV, and inside/outside const contexts?
| && let ExprKind::MethodCall(path, self_arg, [], _) = recv.kind | ||
| && !recv.span.from_expansion() | ||
| && path.ident.name == sym::as_ptr | ||
| && self.msrv.meets(cx, msrvs::CONST_BLOCKS) |
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.
What is the link between .count_bytes() and CONST_BLOCKS?
Also:
- If the MSRV isn't met, the previous suggestion should still apply.
- Different MSRV apply in and outside a
constcontext.
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.
yeah, I didn't know I can add new names to MSRV enum, thought they are kind of fixed code names for versions.
But makes sense, all fixed now.
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.
Don't forget to add tests for all combinations of MSRV/const contexts. You can look at how it's done in other tests by looking for the #[clippy::msrv] attribute.
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.
Looks like I can't call the libc::strlen in the const context. Since it is an FFI function, which is linked at runtime, it just won't compile. Does it mean I can safely remove the msrv branch for const context and keep only the branch for non-const contex, since the user won't be able to compile it anyway?
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.
@samueltardieu let me know if you had time to have a look and close this
|
Reminder, once the PR becomes ready for a review, use |
|
@rustbot ready |
Closes #16308
changelog: [
strlen_on_c_strings]: changes suggestion to use CStr::count_bytes()