Explicit partial self receivers

Having an explicit partial borrow of self in the method signature would be useful under circumstances you need to mutably borrow a subset of the fields in self while having another active mutable borrow to self. Essentially, the borrow checker should only complain about multiple mutable borrows to self if the intersection between two partial mutable borrows of self's fields is not-empty.

struct Test { 
    val0: usize,
    val1: usize,
    val2: String

impl Test {
    pub fn operation(self: &mut Self { val0, val1 }) -> &mut usize {
        *val0 += 1;
        *val1 += 1;

    pub fn concat(self: &mut Self { val0, val2 }) -> &mut String {
        val2.push(format!("{}", *val0});

What do you think?

Niko Matsakis has a blog post about this: After NLL: Interprocedural conflicts

But really this sort of discussion belongs on internals.rust-lang.org, not here.


This has been discussed a number of times on internals. Before opening yet another thread on it, please review past discussions

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.