Closed
Description
I was trying to write some example code to show that rust won't allow more than one
mutable ref to a mutable var. I came up with an example that I thought should generate
a compiler error but did not.
The code appended does not generate a compiler error.
I do get a compiler error when I comment out
*mref2 = 4 and uncomment
*mref1 = 4
I tried this code:
<fn main() {
let mut mutable_int = 100;
let mref1 = &mut mutable_int;
let mref2 = &mut mutable_int;
//*mref1 = 4;
*mref2 = 4;
//assert_eq!(*mref1, *mref2);
}
>
I expected to see this happen: cannot borrow mutable_int
as mutable more than once at a time
Instead, this happened: compiled without error
Meta
rustc --version --verbose
:
<version>
rustc 1.70.0 (90c541806 2023-05-31)
binary: rustc
commit-hash: 90c541806f23a127002de5b4038be731ba1458ca
commit-date: 2023-05-31
host: x86_64-unknown-linux-gnu
release: 1.70.0
LLVM version: 16.0.2
<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary>Backtrace</summary>
<p>
None
<backtrace>