-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Allow immutable access of &mut struct field through &self #9629
Comments
There is a high chance I'm just plain wrong and it's impossible for a good reason. |
Relevant testcase for denying this: |
I think we could permit immutable or const borrows of It is not the case that |
See #9953 for an additional test case. |
I have been thinking about this lately and have come to the conclusion that it is best to consider an
and then you have an |
Assigning myself. |
Note there is a subtle condition to get right, analogous to #8624: If we have x: |
cc me |
…[T]> This method is the mutable version of ImmutableVector::split. It is a DoubleEndedIterator, making mut_rsplit irrelevent. The size_hint method is not optimal because of rust-lang#9629. At the same time, clarify *split* iterator doc.
I've renamed `MutableVector::mut_split(at)` to `MutableVector::mut_split_at(at)` to be coherent with ImmutableVector. As specified in the commit log, The `size_hint` method is not optimal because of #9629.
Should this be closed given that it was fixed by PR #10787? |
@ziad-exabeam yep, thanks! |
This field is no longer necessary now that rust-lang#9629 is fixed since we can just access the length of the remaining slice directly.
Update the next() method to just return self.v in the case that we've reached the last element that the iterator will yield. This produces equivalent behavior as before, but without the cost of updating the field. Update the size_hint() method to return a better hint now that rust-lang#9629 is fixed.
…crichton 3 minor clean-ups now that #9629 is fixed: * Update MutChunkIter to remove the ```remainder``` that existed just to allow the size_hint() method to be implemented. This is no longer necessary since we can just access the length of the slice directly. * Update MutSplitIterator to address the FIXME in its size_hint() method. This method was only partially implemented due to the issue. Also, implement a minor optimization in the case that its the last iteration. * Update ByRef iterator to implement the size_hint() method. I noticed that MutSplitIterator returns an empty slice if called on an empty slice. I don't know if this is intended or not, but I left the ```finished``` field in-place to preserve this behavior. @TeXitoi @blake2-ppc
…ble-loc, r=pcwalton Repair a rather embarassingly obvious hole that I created as part of #9629. In particular, prevent `&mut` borrows of data in an aliasable location. This used to be prevented through the restrictions mechanism, but in #9629 I modified those rules incorrectly. r? @pcwalton Fixes #11913
Replace manual let else patterns with let else Clears the codebase from places where the lint added by rust-lang#8437 is firing, by adopting let else. changelog: none
I can access a
&mut int
through a& &mut int
pointer:But not access a
&mut
struct field through&self
:The use case is precisely
Ref
above, in essence, I want to implement a "by-ref" (by mutable ref) adaptor for iterators. And it works fine for implementingIterator::next
but not forIterator::size_hint
for the reason above.The text was updated successfully, but these errors were encountered: