Tracking Issue for view types
@nikomatsakis is already working on this.
Since Apr 28, 2026.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
This is a tracking issue for experimenting on the concept of view types. The feature gate for the issue is #![feature(view_types)].
Description of the feature
The goal of this feature is to experiment with the concept of view types: allowing the borrow checker to reason about borrows across function calls by having an syntax to express which fields of a struct are used by a function.
This will have the following limitations:
- Usage of view types on
puborpub(...)functions is a hard error. - View groups are not considered at the moment.
- Interaction with pattern types are not considered at the moment.
The goal for now is to support the following:
struct Foo {
a: usize,
b: usize,
}
fn bar(a: &mut view_type!(Foo.{ a }), b: &mut view_type!(Foo.{ b })) {
a.a += 1;
b.b += 1;
}
fn main() {
let mut foo = Foo { a: 0, b: 0 };
bar(&mut foo, &mut foo);
}
The syntax described in Maximally minimal view types, a follow-up is used here, but it will certainly change during the experiment.
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Discussion comments will get marked as off-topic or deleted.
Repeated discussions on the tracking issue may lead to the tracking issue getting locked.
Steps
- Add support for view types
- Parse the syntax
- AST -> HIR lowering
- Validation in the HIR
- HIR -> MIR lowering
- Adjusting the borrow checker
- Figure out a syntax that works well (and ideally that interacts nicely with pattern types)
- Adjust documentation (see instructions on rustc-dev-guide)
- Style updates for any new syntax (nightly-style-procedure)
- Style team decision on new formatting
- Formatting for new syntax has been added to the Style Guide
- (non-blocking) Formatting has been implemented in
rustfmt
- Stabilization PR (see instructions on rustc-dev-guide)
Unresolved Questions
Implementation history
- #155939
- #156016
- #158739
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.