Skip to content

view-types: handle field accesses - #165764

Draft
scrabsha wants to merge 10 commits into
rust-lang:mainfrom
scrabsha:view-types/check-field-access
Draft

scrabsha wants to merge 10 commits into
rust-lang:mainfrom
scrabsha:view-types/check-field-access

Conversation

@scrabsha

@scrabsha scrabsha commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

the main idea of this commit is to handle the following code:

let my_struct: &view_type!(MyStruct.{ foo }) = ...;
let foo = my_struct.foo; // ok!
let bar = my_struct.bar; // error!

this plugs quite nicely in the deref step checking, allowing for access to foo on types like &&&&&view_type(MyStruct.{ foo }) as well as types that deref to reference to &view_type!(...)1. tuple structs are also supported.

the first three commits are an attempt to refactor of FnCtxt::check_expr_field. it was quite overwhelming for me to understand how this function works so i figured i could try to make the it easier for the next person that has to look at it. i kept the refactoring split in three commits because i think it eases review (the ui test suite passes for all three commit), but i'm happy to squash them into one, or drop them entirely.

r? oli-obk

over #165694.

@rustbot blocked by #165694.

Note

AI:0 AI:0 I've not used an LLM for any part of this PR, this includes any related work like research.

Footnotes

  1. The reference is needed here because view types are !MetaSized, which does not satisfies the !Sized bound on Deref::Target. ↩

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Nov 10, 2026
@rust-log-analyzer

This comment has been minimized.

@scrabsha
scrabsha force-pushed the view-types/check-field-access branch 2 times, most recently from 3a6417a to b489285 Compare November 12, 2026 08:56
@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. labels Nov 12, 2026
@rust-log-analyzer

This comment has been minimized.

@scrabsha
scrabsha force-pushed the view-types/check-field-access branch 2 times, most recently from 73cdfb4 to 7d7b53b Compare November 12, 2026 15:04
@scrabsha
scrabsha force-pushed the view-types/check-field-access branch 2 times, most recently from 936e861 to ddf89da Compare November 13, 2026 22:12
@rustbot rustbot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 13, 2026
Comment thread tests/ui/view-types/field-access.rs Resolved
Comment thread tests/ui/view-types/field-access.rs Resolved
@rust-bors

This comment has been minimized.

@scrabsha
scrabsha force-pushed the view-types/check-field-access branch from ddf89da to 211c9dd Compare November 19, 2026 15:16
@scrabsha

Copy link
Copy Markdown
Contributor Author

force push contains:

@rust-log-analyzer

This comment has been minimized.

/!\ the #legal revision of field-access.rs has not been updated /!\
/!\ the test suite is has not been updated /!\

the ICE we are currently fixing uses the debug print of view types, which
was `unimplemented!()`, which triggered another ICE. this commit adds an
implementation of `Debug` for `ty::View`, which gives us a much more
interesting backtrace (which is fixed by the next commit).
/!\ the #legal revision still triggers an ICE, but a new one this time
:fire: /!\
@scrabsha
scrabsha force-pushed the view-types/check-field-access branch from 211c9dd to 1375823 Compare November 19, 2026 15:26

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-rustdoc-json Area: Rustdoc JSON backend PG-exploit-mitigations Project group: Exploit mitigations S-blocked Status: Blocked on something else such as an RFC or other implementation work. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants