Legal values for a `&T` or `&mut T` where `T` is zero-sized
See original GitHub issueIssue Analytics
- State:
- Created 7 years ago
- Comments:19 (5 by maintainers)
Top Results From Across the Web
Legal values for a Box<T> where T is zero-sized #3 - GitHub
My preference is that any non-null value is a valid pointer to a 0-sized type. Also, for things to make sense, all reborrows...
Read more >Why do zero-sized types cause real allocations in some cases?
Almost every operation with a ZST is a no-op since ZSTs have exactly one value, and therefore no state needs to be considered...
Read more >Rust (Programming Language) | linkedin-skill-assessments-quizzes
It's creating a pointer on the heap that points to a value on the stack. ... What syntax is required to take a...
Read more >ndoffice doesn't allow upload of zero-sized documents - Optiable
When you are using Workshare/Literia Compare, you get the error message that ndOffice doesn't allow zero-size documents.
Read more >Math208 Discrete Mathematics - College of Arts & Sciences
That is, it must be possible to assign a truth value to any compound ... for two 0-1 matrices of the same size...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is the memory model repo, not the soundness repo.
I think that any non-null value should be OK, and that the compiler should correctly propagate that value. It is useful and expected in #[repr©] structs for a ZST before a sized type to have the same address of that field.
In addition, ZSTs have the advantage that they can be passed around as &T and &mut T while not allowing the consumer to move the actual data behind the reference (which may be a variable sized #[repr©] struct). The methods on the ZST T can then cast the reference to a reference to the actual backing data type, and avoid unsafety that would come by allowing moving, for example, the header of a FFI C type. I think patterns like that should be OK, as they solve a real problem, and shouldn’t break anything.
This means that pointers to opaque C structs can be passed around like native rust types behind &T and &mut T, rather than requiring special structs like:
which require a large number of impls on them and don’t provide a nice API.