Related to #7621.
Officially, according to the docs we do not support ref without mut:
Note It is not currently allowed to use mut without ref or vice versa for a function parameter.
I don't know the historical reasons for this restriction. What is obvious is that the checks for it are not done properly.
E.g., in this example:
script;
struct S {}
impl S {
fn method(self, ref _x: u64) { } // <<<<---- No errors.
fn associated_fun(ref _x: u64) { } // <<<<---- No errors.
}
fn ref_pass(ref _x: u64) { } // <<<<---- No error here, but confusing one at call site.
fn main() -> u64 {
let x = 42;
ref_pass(x);
// ^ Cannot pass immutable argument to mutable parameter.
S {}.method(x);
S::associated_fun(x);
x
}
Note that using only mut without ref produces error in all cases, explaining that mut cannot be used without ref.
I am fine with supporting ref without mut assuming the effort is negligible (because we will make ref mut obsolete with references). But we have to properly implement it, document it etc. It must not be that ref without mut "works" in certain cases only because it is not properly checked.
Related to #7621.
Officially, according to the docs we do not support
refwithoutmut:I don't know the historical reasons for this restriction. What is obvious is that the checks for it are not done properly.
E.g., in this example:
Note that using only
mutwithoutrefproduces error in all cases, explaining thatmutcannot be used withoutref.I am fine with supporting
refwithoutmutassuming the effort is negligible (because we will makeref mutobsolete with references). But we have to properly implement it, document it etc. It must not be thatrefwithoutmut"works" in certain cases only because it is not properly checked.