Skip to content

feat(trusted_asref): new lint#17288

Open
niklasf wants to merge 1 commit into
rust-lang:masterfrom
niklasf:feat/trusted-asref
Open

feat(trusted_asref): new lint#17288
niklasf wants to merge 1 commit into
rust-lang:masterfrom
niklasf:feat/trusted-asref

Conversation

@niklasf

@niklasf niklasf commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Closes #10323.

Example:

unsafe { ffi(generic_bytes.as_ref().as_ptr(), generic_bytes.as_ref().len()) }

may be broken by pathological AsRef implementations using interior mutability.

While not all such uses are actually unsound (maybe ffi() does not actually require consistent arguments here, or maybe all possible AsRef implementations come from the same crate), the generated warnings should always be actionable and possibly prevent subtle soundness issues in the future.

Scanned crates.io and found 85 candidate crates, of which I so far manually confirmed 5/5 to be actually unsound. Intend to review more and individually submit fixes.

changelog: new lint: [trusted_asref]

@rustbot rustbot added needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jun 21, 2026
@rustbot

rustbot commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

r? @dswij

rustbot has assigned @dswij.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 8 candidates
  • 8 candidates expanded to 8 candidates
  • Random selection from Jarcho, dswij, llogiq, samueltardieu

@rustbot

This comment has been minimized.

@github-actions

github-actions Bot commented Jun 21, 2026

Copy link
Copy Markdown

Lintcheck changes for 0e8af49

Lint Added Removed Changed
clippy::trusted_asref 4 0 0

This comment will be updated if you push new changes

@niklasf niklasf changed the title feat(trusted_asref): new lint (closes #10323) feat(trusted_asref): new lint Jun 21, 2026
@niklasf niklasf force-pushed the feat/trusted-asref branch 2 times, most recently from fd691fc to 48e97ef Compare June 21, 2026 18:03
@niklasf

niklasf commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

Btw. looks like the lintcheck findings from the pinned redox version were already fixed quite a while ago.

@niklasf niklasf force-pushed the feat/trusted-asref branch from 48e97ef to 0b4194e Compare June 21, 2026 21:28
@niklasf niklasf force-pushed the feat/trusted-asref branch from 0b4194e to 0e8af49 Compare June 22, 2026 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unsafe { ffi(generic_bytes.as_ref().as_ptr(), generic_bytes.as_ref().len()) } trusts AsRef impl

3 participants