Skip to content

account-info: Add comment to assign - #920

Merged
febo merged 1 commit into
anza-xyz:masterfrom
febo:assign-comment
Sep 1, 2026
Merged

febo merged 1 commit into
anza-xyz:masterfrom
febo:assign-comment

Conversation

@febo

@febo febo commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Problem

The assign method currently unsafely writes to self.owner through a read-only shared reference. When the method is used with other active references, the compiler might generate arbitrarily incorrect code (UB).

Solution

Add comments to highlight the potential footgun when using this method.

@febo

febo commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

@joncinque Not sure whether we should take advantage of breaking changes and make the method unsafe or not. It is unsafe on the AccountView type.

@febo
febo requested a review from joncinque September 1, 2026 08:40
@febo
febo marked this pull request as ready for review September 1, 2026 10:59

@joncinque joncinque left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm happy with landing this as is to start, since it's true that the behavior is potentially dangerous.

Would marking it unsafe solve the problem though? I think we should also change the function to take in &mut self and allow the compiler to see if there are any outstanding borrows at the time.

What do you think?

@febo

febo commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

I'm happy with landing this as is to start, since it's true that the behavior is potentially dangerous.

Would marking it unsafe solve the problem though? I think we should also change the function to take in &mut self and allow the compiler to see if there are any outstanding borrows at the time.

What do you think?

Oh, that is a good point. AccountView also requires &mut self. Unfortunately none of these changes would really solve the issue, since duplicated accounts share the same reference. But I think it is the best we can with the current design.

@joncinque

Copy link
Copy Markdown
Collaborator

Ah right that's a good point... in that case, let's do whatever is easiest for now, since the long-term plan is to deprecate and remove the whole crate.

@febo
febo merged commit 04729a0 into anza-xyz:master Sep 1, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants