Skip to content

rust-patterns-book: ch04 Lifetime Branding example fails to compile due to borrow checker error #102

@freshBird9527

Description

@freshBird9527

In the section "Lifetime Branding" of Chapter 04 (PhantomData types that carry no data):

https://microsoft.github.io/RustTraining/rust-patterns-book/ch04-phantomdata-types-that-carry-no-data.html#lifetime-branding

the provided example code does not compile as written.

Observed behavior

Compiling the example leads to a borrow checker error:

   Compiling lphantom v0.1.0 (/home/lighthouse/lr/lphantom)
error[E0502]: cannot borrow `arena1` as immutable because it is also borrowed as mutable
  --> src/main.rs:39:20
   |
33 |     let handle1 = arena1.alloc("hello".to_string());
   |                   ------ mutable borrow occurs here
...
39 |     println!("{}", arena1.get(handle1)); // ✅
   |                    ^^^^^^     ------- mutable borrow later used here
   |                    |
   |                    immutable borrow occurs here

For more information about this error, try `rustc --explain E0502`.
error: could not compile `lphantom` (bin "lphantom") due to 1 previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions