Skip to content

Improperctypes refactor2.2 - #155359

Merged
rust-bors[bot] merged 4 commits into
rust-lang:mainfrom
niacdoial:improperctypes-refactor2.2
Apr 21, 2026
Merged

Improperctypes refactor2.2#155359
rust-bors[bot] merged 4 commits into
rust-lang:mainfrom
niacdoial:improperctypes-refactor2.2

Conversation

@niacdoial

Copy link
Copy Markdown
Contributor

This is "part 2/3 of 2/3 of 1/2" of the original pull request #134697 (refactor plus overhaul of the ImproperCTypes family of lints)
(all pulls of this series of pulls are supersets of the previous pulls.)
previous pull: #155358
next pull: #146273

This commit splits the lint's visit_type function into multiple functions that focus on specific things:

  • visit_indirection (references, boxes, raw pointers)
  • visit_variant_fields (the list of fields of a struct, enum variant, or union)
  • visit_enum
  • visit_struct_or_union
  • visit_type (most "easy" decisions such as labeling char unsafe are here)

since, during these visits, we often move from an "outer type" to an "inner type" (structs, arrays, pointers, etc...),
two structs have been added to track the current state of a visit:

  • VisitorState tracks the state related to the "original type" being checked (function argument/return, static variable)
  • OuterTyData tracks the data related to the type "immediately outer to the current visited type"

r? petrochenkov (because you asked me to)

@rustbotrustbot 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. labels Apr 15, 2026
@rust-log-analyzer

This comment has been minimized.

@niacdoial
niacdoialforce-pushed the improperctypes-refactor2.2 branch from a439f4d to fa0fcc6CompareApril 15, 2026 21:18
@petrochenkov

Copy link
Copy Markdown
Contributor

Blocked on #155358.
@rustbot blocked

@rustbotrustbot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 16, 2026
@petrochenkov

Copy link
Copy Markdown
Contributor

#155358 has landed, unblocking.
@rustbot author (to rebase)

@rustbotrustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Apr 17, 2026
@rustbot

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@niacdoial
niacdoialforce-pushed the improperctypes-refactor2.2 branch from fa0fcc6 to b2f3002CompareApril 17, 2026 11:38
@rustbot

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@niacdoial

Copy link
Copy Markdown
ContributorAuthor

can't believe I let this amount of time pass between tests being OK and this...
@rustbot review

@rustbotrustbot 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 17, 2026
Comment threadcompiler/rustc_lint/src/types/improper_ctypes.rs Outdated
Comment threadcompiler/rustc_lint/src/types/improper_ctypes.rs
@petrochenkov

petrochenkov commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

This PR moves code around and changes that code in the same commit, this makes it hard to see what's going on.
I'd rather split this to at least 2 commits

  • one mechanically extracting code from fn visit_type to the new functions (code moving)
  • and another for everything else (code changing)
    • this could potentially be split further into smaller single-purpose portions, like introduction of visit_indirection, but I'll leave this to you to decide.

@rustbot author

@rustbotrustbot 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 Apr 20, 2026
Comment threadcompiler/rustc_lint/src/types/improper_ctypes.rs Outdated
Another interal change that shouldn't impact rustc users.
The goal (of this commit and a few afterwards) is to break apart the gigantic
visit_type function into more managable and easily-editable bits that focus
on specific parts of FFI safety.
For now, we break the code specific to enums one side, and
structs/unions on the other, into separate visit_? methods
Another interal change that shouldn't impact rustc users.
the list of simpler type-based decisions made by `visit_type` are
reordered and are given better documentation.
Another interal change that shouldn't impact rustc users.
This time, regroup into `visit_indirections` the code dealing with the
FFI safety of Boxes, Refs and RawPtrs.
@niacdoial
niacdoialforce-pushed the improperctypes-refactor2.2 branch 2 times, most recently from 103a8d0 to 1180e38CompareApril 20, 2026 23:03
@niacdoial

Copy link
Copy Markdown
ContributorAuthor

@rustbot ready

@rustbotrustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 21, 2026
@rustbotrustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 21, 2026
Comment threadcompiler/rustc_lint/src/types/improper_ctypes.rs Outdated
@petrochenkov

Copy link
Copy Markdown
Contributor

Thanks!
r=me with the if simplified #155359 (comment).
@rustbot author

@rustbotrustbot 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 Apr 21, 2026
Another interal change that shouldn't impact rustc users.
Code called outside of `visit_type` (and callees) is moved inside, by
adding new types to properly track the state of a type visitation.
- OuterTyKind tracks the knowledge of the type "directly outside of" the
one being visited (if we are visiting a struct's field, an array's
element, etc)
- RootUseFlags tracks the knowledge of how the "original type being
visited" is used: static variable, function argument/return, etc.
@niacdoial
niacdoialforce-pushed the improperctypes-refactor2.2 branch from 1180e38 to 7bb9851CompareApril 21, 2026 13:08
@petrochenkov

Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors

rust-borsBot commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 7bb9851 has been approved by petrochenkov

It is now in the queue for this repository.

@rust-borsrust-borsBot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 21, 2026
rust-borsBot pushed a commit that referenced this pull request Apr 21, 2026
…uwer
Rollup of 4 pull requests
Successful merges:
- #152611 (Modify error message of importing inherent associated items when `#[feature(import_trait_associated_functions)]` is enabled)
- #155359 (Improperctypes refactor2.2)
- #155036 (Store a PathBuf rather than SerializedModule for cached modules)
- #155554 (add warning message when using x fix)
@rust-bors
rust-borsBot merged commit f21c57d into rust-lang:mainApr 21, 2026
11 checks passed
@rustbotrustbot added this to the 1.97.0 milestone Apr 21, 2026
rust-timer added a commit that referenced this pull request Apr 21, 2026
Rollup merge of #155359 - niacdoial:improperctypes-refactor2.2, r=petrochenkov
Improperctypes refactor2.2
This is "part 2/3 of 2/3 of 1/2" of the original pull request #134697 (refactor plus overhaul of the ImproperCTypes family of lints)
(all pulls of this series of pulls are supersets of the previous pulls.)
previous pull: #155358
next pull: #146273
This commit splits the lint's `visit_type` function into multiple functions that focus on specific things:
- visit_indirection (references, boxes, raw pointers)
- visit_variant_fields (the list of fields of a struct, enum variant, or union)
- visit_enum
- visit_struct_or_union
- visit_type (most "easy" decisions such as labeling `char` unsafe are here)
since, during these visits, we often move from an "outer type" to an "inner type" (structs, arrays, pointers, etc...),
two structs have been added to track the current state of a visit:
- VisitorState tracks the state related to the "original type" being checked (function argument/return, static variable)
- OuterTyData tracks the data related to the type "immediately outer to the current visited type"
r? petrochenkov (because you asked me to)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@niacdoial@rust-log-analyzer@petrochenkov@rustbot