Skip to content

Add an auto-slice-and-ref step to method lookup. Allows ~[T] to work wit... #4133

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

Closed
wants to merge 1 commit into from

Conversation

brson
Copy link
Contributor

@brson brson commented Dec 7, 2012

r? @nikomatsakis

One thing this doesn't handle is borrowing @mut [T] to &self for impls on &[T]. I'm not sure how to deal with that, but it hopefully is not necessary to convert BaseIter to explicit self.

Incidentally, the reason ~mut [T] was working is because that is not a vector type, it is a mutable unique box containing a fixed-length vector.

@nikomatsakis
Copy link
Contributor

My thought for how to support @mut [T] was to modify this code:

               // Then try to borrow to a slice *and* borrow a pointer.
                // NB: we do not try to autoref to a mutable pointer. That would
                // be creating a pointer to a temporary pointer (the borrowed slice),
                // so any update the callee makes to it can't be observed.
                self.search_for_some_kind_of_autorefd_method(
                    AutoBorrowVecRef, autoderefs, [m_imm],
                    |m,r| {
                        let slice_ty = ty::mk_evec(tcx,
                                                   {ty:mt.ty, mutbl:mt.mutbl},
                                                   vstore_slice(r));
                        ty::mk_rptr(tcx, r, {ty:slice_ty, mutbl:m})
                    })

as follows:

               // Then try to borrow to a slice *and* borrow a pointer.
                // NB: we do not try to autoref to a mutable pointer. That would
                // be creating a pointer to a temporary pointer (the borrowed slice),
                // so any update the callee makes to it can't be observed.
                self.search_for_some_kind_of_autorefd_method(
                    AutoBorrowVecRef, autoderefs, [m_mut,m_const,m_imm], /* <-- note: try all 3 */
                    |m,r| {
                        let slice_ty = ty::mk_evec(tcx,
                                                   {ty:mt.ty, mutbl:m}, /* <-- note: mutbl: m */
                                                   vstore_slice(r));
                        ty::mk_rptr(tcx, r, {ty:slice_ty, mutbl:m_imm}) /* <-- note: also m_imm */
                    })

@nikomatsakis
Copy link
Contributor

r+, though you may want to consider the change I suggested above.

@brson brson closed this Dec 8, 2012
RalfJung added a commit to RalfJung/rust that referenced this pull request Jan 19, 2025
Supported fioclex for ioctl on macos
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