Skip to content

Idiomatic: Simplify example in method resolution slide#3166

Open
randomPoison wants to merge 1 commit into
google:mainfrom
randomPoison:method-resolution-slide-simplify
Open

Idiomatic: Simplify example in method resolution slide#3166
randomPoison wants to merge 1 commit into
google:mainfrom
randomPoison:method-resolution-slide-simplify

Conversation

@randomPoison

Copy link
Copy Markdown
Contributor

The example in the speaker notes can be a bit simpler, i.e. we can do & instead of &mut and get the same effect. I also cut the comment down to reduce verbosity.

@mgeisler mgeisler enabled auto-merge (squash) April 20, 2026 21:46
`&mut self` has a higher priority than `&self`, the one used by the inherent
method.
Demonstrate: Change the call to `(&-1i32).count_ones()` and demonstrate that
the trait method is now called instead.

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 not sure that this new example demonstrates the rule described above. Could you help me understand? The difference is the method receiver expression, value -1i32 vs. reference &-1i32. The list above that describes the rule does not talk about that axis?

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