-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Incorrect unsafe code example in standard library #77220
Copy link
Copy link
Closed
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
The safety clause on the
Vec::set_lenfunction says that:However, the code example for
std::ptr::copyviolates the second ruleThe
set_lenis called before the values are initialized with the copy.This could be fixed by either making the safety clause for
set_lenmore inclusive, so that as long as you don't use the vector before initializing the values it's considered safe, or by switching thedst.set_len(elts);andptr::copy(ptr, dst.as_mut_ptr(), alts);lines around in the example.