Skip to content

about the borrowing example #71

Open
@trichimtrich

Description

@trichimtrich

Hi, I'm new to Rust and trying the sample in this doc
https://learning-rust.github.io/docs/borrowing/

The code

fn main() {
  let mut a = vec![1, 2, 3];
  let b = &mut a;  //  &mut borrow of `a` starts here
  // some code
b[1] = 123;

  println!("{:?}", a); // trying to access `a` as a shared borrow, so giving an error
}                  //  &mut borrow of `a` ends here

It seems to compile and run fine without any error on my machine

ubt :: testbin ‹master› % rustc --version                      1 ↵
rustc 1.78.0 (9b00956e5 2024-04-29)
ubt :: testbin ‹master› % cargo run
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.00s
     Running `target/debug/testbin`
[1, 123, 3]

Is it intended, or something has changed from the language itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions