|
|
Subscribe / Log in / New account

"Trying to represent this API in Rust just doesn't work. The language never lets mutable references alias each other,"

"Trying to represent this API in Rust just doesn't work. The language never lets mutable references alias each other,"

Posted Sep 30, 2025 13:12 UTC (Tue) by daroc (editor, #160859)
In reply to: "Trying to represent this API in Rust just doesn't work. The language never lets mutable references alias each other," by theodorvaryag
Parent article: Comparing Rust to Carbon

Thank you for the detailed example; it's always great to discuss concrete code. See my other comment for a response about the API, but for other readers following along at home:

Unless I'm misunderstanding something, these examples use *mut [u8] at the same time as a *const [u8], which I agree won't cause any problems. The part I thought would be broken is using a &mut [u8] at the same time as a &[u8] pointing to the same memory.

Here's one of your example tests lightly modified to use references instead of pointers:
https://play.rust-lang.org/?version=stable&mode=debug...

Running it via MIRI does show that it triggers undefined behavior.


to post comments


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds