Skip to content

Improperctypes refactor2.2#155359

Open
niacdoial wants to merge 2 commits intorust-lang:mainfrom
niacdoial:improperctypes-refactor2.2
Open

Improperctypes refactor2.2#155359
niacdoial wants to merge 2 commits intorust-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)

Another interal change that shouldn't impact rustc users.
To prepare for the upcoming split of visit_type, we reorganise the instances
of `cx.tcx.try_normalize_erasing_regions(cx.typing_env(), ty).unwrap_or(ty)`
into a helper function outside of the main structs.
@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. labels Apr 15, 2026
@rust-log-analyzer

This comment has been minimized.

Another interal change that shouldn't impact rustc users.
The goal is to break apart the gigantic visit_type function into more
managable and easily-editable bits that focus on specific parts of FFI safety.
In particular, all matters linked to indirections (RawPtr,Ref,boxes) are
grouped in a single function.
@niacdoial niacdoial force-pushed the improperctypes-refactor2.2 branch from a439f4d to fa0fcc6 Compare April 15, 2026 21:18
@petrochenkov
Copy link
Copy Markdown
Contributor

Blocked on #155358.
@rustbot blocked

@rustbot rustbot 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-blocked Status: Blocked on something else such as an RFC or other implementation work. T-compiler Relevant 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