EDIT: Ignore this post. I really messed up the explanation. Better one coming soon

I've discovered a way to infer moves, borrows and clones without any extra work from the user. There's some edge cases to figure out, but I'm confident it's possible, and it'll make an awesome high-level language.

I have it all on a single page, but I'm going to summarise it here as well.

I'd love any feedback!

https://pranabekka.github.io/borrow-infer/

#rust #rustlang #programming

1/?

Borrow inferrer - Pranab’s site

Look at the following Rust snippet. It only has borrows for the specific string type, but no other annotations!

Basically, we remove `&mut` and instead use this style of "assignment to mutate", which can use moves or borrows without us needing to know the details.

2/?

I'm going to change the syntax to differentiate from Rust and fit more.

Here, `list_fn` gets a move or mutable borrow of `list`. But `dbg!`, on the other hand, doesn't return a value for us to assign to `list`, so it receives an immutable borrow.

We've removed the need for `&` and `&mut`!

3/?

A clone occurs whenever you assign to a new variable, for the simple reason that if they were meant to be the same, then there's no reason to create a new variable. In the following example, `list_2` is a copy of `list`.

We've thus completely inferred moves, borrows and clones. I discuss some more cases and benefits of this syntax in the article, but this is the start.

4/?

In summary:

1. Remove `&`, `&mut` and `clone()`
2. Mutate by assigning to the same variable, with hidden moves/borrows for performance
3. Copy/clone on assigning to new variable

I'd love to hear any questions or feedback!

https://pranabekka.github.io/borrow-infer/

Borrow inferrer - Pranab’s site