Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

issues with Lifetime branding example

Open
#125 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
rust
Domain
documentation

Research direction

Start in rust-patterns-book/src/ch04-phantomdata-types-that-carry-no-data.md around line 44 and review the Lifetime branding example and its surrounding explanation. Compile both arrangements shown in the issue, then update the example so handles cannot be used with a different arena and verify the intended success and failure cases.

Written by the indexing model from the issue text.

Description

https://github.com/microsoft/RustTraining/blob/278f1d7ee0e5432c1a4e1e4d2a749796f60e7711/rust-patterns-book/src/ch04-phantomdata-types-that-carry-no-data.md?plain=1#L44

The example as written fails to compile when we uncomment the code:

fn main() {
    with_arena(|arena1| {
        let handle1 = arena1.alloc("hello".to_string());
        println!("{}", arena1.get(&handle1)); // ✅

        // Can't use handle1 with a different arena — compile-time error
        with_arena(|arena2| {
            arena2.get(&handle1); // ❌ borrowed data escapes outside of closure
        });
    });
}

If we rearrange the code a bit:

fn main() {
    with_arena(|arena1| {
        // Can't use handle1 with a different arena — compile-time error
        with_arena(|arena2| {
            let handle1 = arena1.alloc("hello".to_string());
            println!("{}", arena1.get(&handle1)); // ✅
            arena2.get(&handle1); // ❌ borrowed data escapes outside of closure
        });
    });
}

This compiles - even though it isn't supposed to.

By moving the brand to the Arena instead of keeping it on the ArenaHandle it works as intended:

/// A handle branded to a specific arena instance.
/// Invariant over 'arena — prevents using a handle from one arena with another.
struct ArenaHandle<'arena> {
    index: usize,
    _phantom: PhantomData<&'arena ()>,
}

/// An arena that brands each handle with its unique lifetime.
struct Arena<'arena> {
    data: RefCell<Vec<String>>,
    _brand: PhantomData<*mut &'arena ()>,
}
Dominant language
Rust
Stars
14.9k
Forks
1.2k
Avg merge
13d 16h
Merged PRs (30d)
3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.