Skip to content

Allow a ref field to refer to a ref struct type #9152

Answered by jaredpar
Delsin-Yu asked this question in Q&A
Discussion options

You must be logged in to vote

There is no way to have a mutable ref to a ref struct without adding explicit lifetimes to the language. At the moment there are no plans for doing that. It would be a rather significant syntax update, even if we got it in through annotations in attributes, and it would need significant justification. That hasn't manifested.

I think it's likely that we will get ref readonly to ref struct in .NET 11 or soon after. That is mostly an exercise in proving it's safe, updating a few rules and removing a few errors in the compiler. From there experts can use unsafe to get mutable access to the value in the cases they are able to convince themselves the lifetimes are correct.

The Roslyn team memb…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
3 replies
@timcassell
Comment options

@jaredpar
Comment options

Answer selected by Delsin-Yu
@RikkiGibson
Comment options

Comment options

You must be logged in to vote
3 replies
@RikkiGibson
Comment options

@timcassell
Comment options

@RikkiGibson
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants