On Tue, Feb 4, 2014 at 12:25 PM, Niko Matsakis <n...@alum.mit.edu> wrote:

> Within a single function we are more permissive, I think. I've been
> debating if we should stop that, just for consistency.


I think that'd be too annoying.  I'd rather see Rust going the other way,
and permit calling functions which borrow immutably.
BTW, what's the reason for disallowing that now?   Is this because they
might retain a reference somewhere?   Would it be possible to extend the
type system so we can model this case properly?   In other words, functions
could explicitly declare as effect such as "this function may store in
region 'b a reference into region 'a", (where 'b is the region of the
iterator and 'a is the region of the collection).  Then the caller would
know if it can permit that or not.   Something like:

      pub trait MutableVector<T> {
          fn mut_iter(&'a self) -> 'b MutItems<T> where 'b mut ref 'a {
                  ...
          }
       }

Of course, in order to implement futures they way I want them, we'd also
need an effect saying "something in region 'b needs an exclusive access to
region 'a, so please rope it off completely".

Hmm, is what I am asking for here tantamount to bolting the type system of
Disciple <http://disciple.ouroborus.net/> onto Rust? :-)


There are also
> some bugs concerning closures. I hope to close those soon with my
> patch for #6801.
>

> On Wed, Jan 29, 2014 at 02:39:01PM -0800, Vadim wrote:
> > I've tried to simulate that with iterators, but it seems I can still read
> > the buffer.   This compiles without errors:
> >
> >     let mut buf = [0, ..1024];
> >     let mut iter = buf.mut_iter();
> >     let x = buf[0];
> >     *iter.next().unwrap() = 2; // just to make sure I can mutate via the
> > iterator
>
>
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to