Repository navigation
Emit a warning around thin &CStr interior mutability breaks #118513
Description
Activity
- addedneeds-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triagingThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triagingA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
on Dec 1, 2023 Quick search shows this is hopefully not very common https://github.com/search?q=language%3Arust+%2F%26.*UnsafeCell%3CCStr%3E%2F&type=code
Incidentally, I wonder if
&UnsafeCell<ThinCStr>itself is sound. I wonder if T-opsem should weigh in on that question. A write could happen and change the size of the memory the reference refers to, and the tag won't be correctly sized - maybe it will be shorter than the memory the reference refers to.&mut ThinCStrmight also have similar issues.Related: my RFC 3536 for
!Sizedthin pointers had to introduce a new?Traitto prevent such types from being used withsize_of_val(). In general the C concept of DSTs (pointer + computed value size) seems to be incompatible with the Rust semantics ofT: ?Sizedandsize_of_val().- removedneeds-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triagingThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
on Dec 2, 2023
From @chorman0773 https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/CStr.20as.20thin.20pointer/near/405432566
Passing an
&UnsafeCell<CStr>tosize_of_valis currently sound because it just returns the length parameter of the fat pointer. After makingCStrthin however,size_of_valwill need to callstrlenon the data. This is not ok in a&UnsafeCellbecause another context could be writing the data, e.g. temporarily overwriting the\0.This seems like something we may be able to emit a warning for?
Thin cstr: #59905
@rustbot label +T-libs +T-compiler +A-diagnostics