Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: code generation for mut self methods #616

Merged
merged 2 commits into from
Nov 3, 2021
Merged

Conversation

austinabell
Copy link
Contributor

Closes #615

Probably rare someone would want to modify this structure in place for a view method, which is probably how this wasn't hit before, but good to have this functional

@@ -105,7 +105,7 @@ impl AttrSigInfo {

if let Some(ref receiver) = receiver {
if matches!(method_type, MethodType::Regular) {
if receiver.mutability.is_none() {
if receiver.mutability.is_none() || receiver.reference.is_none() {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure why we can't just have

if receiver.reference.is_none() {

but compilation_tests/payable_view.rs successfully compiles even though its expected not to.

This conditional should just only be checking for mut self and self signatures, where checking for mutability shouldn't matter at all. But somehow also related to pay(&self) signature in payable_vew.rs? Maybe there's some sort of complexity somewhere we're not noticing or I'm probably missing something here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nah this is intentional. This was the point of the PR that mut self was treated as mutating state and tries to write the data after. If you check only for reference, you don't differentiate between mutable and immutable references

Copy link
Member

Choose a reason for hiding this comment

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

Ahh, so I was confused what this whole if block was checking. Thought it was for self and mut self but was actually for the reference versions &self

@austinabell austinabell merged commit 8521e89 into master Nov 3, 2021
@austinabell austinabell deleted the austin/mut_owned_fix branch November 3, 2021 13:34
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.

Require #[init] methods to return Self / mut self methods fail to compile
2 participants