How can Rust know if a variable is mutable?

Viewed 479

The following C# code compiles fine:

static readonly List<int> list = new List<int>();
static void Main(string[] args)
{
    list.Add(1);
    list.Add(2);
    list.Add(3);
}

If I write similar code in Rust, it won't compile because it cannot borrow immutable v as mutable:

let v = Vec::new();
v.push(1);
v.push(2);
v.push(3);

How does the push function know v is immutable?

2 Answers
Related