Why is this legal?

⚓ Rust    📅 2026-04-23    👤 surdeus    👁️ 3      

surdeus

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Why is this legal?

The implementation of binary heaps in std uses a Hole type. It stores a &mut [T], but one of the elements in this slice becomes temporarily invalid (it is repaired in the Drop implementation). Why is it okay to have a reference (as opposed to a pointer)? Does the existence of the reference imply the elements of the slice are valid? The code never reads the invalid element of the slice

6 posts - 4 participants

Read full topic

🏷️ Rust_feed