Skip to content
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

Add a special case for CStr/CString in the improper_ctypes lint #120176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Flying-Toast
Copy link
Contributor

Instead of saying to "consider adding a #[repr(C)] or #[repr(transparent)] attribute to this struct", we now tell users to "Use *const ffi::c_char instead, and pass the value from CStr::as_ptr()" when the type involved is a CStr or a CString.

Inspired by a conversation on the #beginners Discord channel.

@rustbot
Copy link
Collaborator

rustbot commented Jan 20, 2024

r? @cjgillot

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 20, 2024
@Flying-Toast Flying-Toast force-pushed the cstr_in_ffi_lint branch 2 times, most recently from 5868441 to e607e99 Compare January 21, 2024 17:20
Copy link
Contributor

@asquared31415 asquared31415 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there could be better suggestions that use binding.as_ptr() instead of CStr::as_ptr? I don't think it really matters though.

tests/ui/lint/lint-ctypes-cstr.rs Show resolved Hide resolved
tests/ui/lint/lint-ctypes-cstr.rs Show resolved Hide resolved
@Flying-Toast
Copy link
Contributor Author

I wonder if there could be better suggestions that use binding.as_ptr() instead of CStr::as_ptr? I don't think it really matters though.

binding.as_ptr() would require the error to be emitted at a call site, rather than at the definition/declaration though right? Or are you talking about including the literal string "binding" in the error?

@cjgillot cjgillot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 10, 2024
@Flying-Toast Flying-Toast force-pushed the cstr_in_ffi_lint branch 2 times, most recently from d80eb55 to 889a1fb Compare March 18, 2024 21:42
@Flying-Toast
Copy link
Contributor Author

r? @cjgillot

@rustbot
Copy link
Collaborator

rustbot commented Mar 18, 2024

Could not assign reviewer from: cjgillot.
User(s) cjgillot are either the PR author, already assigned, or on vacation, and there are no other candidates.
Use r? to specify someone else to assign.

@bors
Copy link
Contributor

bors commented Mar 22, 2024

☔ The latest upstream changes (presumably #122852) made this pull request unmergeable. Please resolve the merge conflicts.

@rustbot
Copy link
Collaborator

rustbot commented Mar 23, 2024

Some changes occurred in src/tools/cargo

cc @ehuss

@Flying-Toast
Copy link
Contributor Author

Oops, didn't mean to touch all the submodules

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Instead of saying to "consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct", we now tell users to "Use `*const ffi::c_char` instead, and pass the value from `CStr::as_ptr()`" when the type involved is a `CStr` or a `CString`.

Inspired by a conversation on the #beginners Discord channel.
@Dylan-DPC Dylan-DPC added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants