Skip to content

view-types: handle field accesses - #165764

Merged
rust-bors[bot] merged 8 commits into
rust-lang:mainfrom
scrabsha:view-types/check-field-access
Nov 23, 2026
Merged

rust-bors[bot] merged 8 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

part of #155938.

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 4 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.

@scrabsha
scrabsha force-pushed the view-types/check-field-access branch from 211c9dd to 1375823 Compare November 19, 2026 15:26
@scrabsha
scrabsha force-pushed the view-types/check-field-access branch from 1375823 to d5b8736 Compare November 20, 2026 08:45
@scrabsha
scrabsha marked this pull request as ready for review November 20, 2026 08:46
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 20, 2026
@scrabsha

Copy link
Copy Markdown
Contributor Author

@rustbot label -S-blocked

@rustbot rustbot removed the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Nov 20, 2026
@scrabsha scrabsha mentioned this pull request Nov 20, 2026
4 of 15 tasks

@oli-obk oli-obk left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@bors delegate+

r=me with some extra deduplication

View changes since this review

Comment thread compiler/rustc_hir_typeck/src/expr.rs Resolved
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 23, 2026
@rust-bors

rust-bors Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

✌️ @scrabsha, you can now approve this pull request!

If @oli-obk told you to "r=me" after making some further change, then please make that change and post @bors r=oli-obk.

View changes since this delegation.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 23, 2026
@rustbot

rustbot commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

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

/!\ 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 d5b8736 to 9655251 Compare November 23, 2026 09:58
@scrabsha

Copy link
Copy Markdown
Contributor Author

ci passed ✨

@bors r=oli-obk rollup

@rust-bors

rust-bors Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 9655251 has been approved by oli-obk

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 Nov 23, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 23, 2026
…uwer

Rollup of 6 pull requests

Successful merges:

 - #164918 (Move lint validation to attribute parsing)
 - #166381 (`rust-analyzer` subtree update)
 - #166191 (Enable static-pie on all Musl targets)
 - #166390 (Turn `gca` into a macro 2.0 that expands to `k#gca(..)`)
 - #165764 (view-types: handle field accesses)
 - #166250 (Add a reason suggestion for malformed lint attributes)

Failed merges:

 - #166374 (Undo accidental duplication checking for attributes on macro calls)
@rust-bors
rust-bors Bot merged commit 4197094 into rust-lang:main Nov 23, 2026
25 of 27 checks passed
@rustbot rustbot added this to the 1.102.0 milestone Nov 23, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 23, 2026
Rollup merge of #165764 - scrabsha:view-types/check-field-access, r=oli-obk

view-types: handle field accesses
@scrabsha
scrabsha deleted the view-types/check-field-access branch November 23, 2026 20:30
@rust-timer

Copy link
Copy Markdown
Collaborator

Note

This PR was benchmarked as part of triage of its containing rollup: triage URL.

Finished benchmarking commit (393ed47): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were not yet notified of this PR).

@rustbot label: +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.1% [0.1%, 0.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.6% [-1.2%, -0.1%] 14
All ❌✅ (primary) - - 0

Max RSS (memory usage)

This perf run didn't have relevant results for this metric.

Cycles

Results (secondary 1.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
7.3% [5.5%, 8.9%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.6% [-5.2%, -2.2%] 3
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Artifact size: 406.40 MiB -> 405.75 MiB (-0.16%)

@rustbot rustbot added the perf-regression Performance regression. label Nov 23, 2026
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 perf-regression Performance regression. PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

5 participants