Fix: remove unnecessary unsafe of ErasedBundleTemplate::apply - #25279
Open
yilin0518 wants to merge 1 commit into
Open
Fix: remove unnecessary unsafe of ErasedBundleTemplate::apply#25279yilin0518 wants to merge 1 commit into
yilin0518 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
ErasedBundleTemplate::applyinbevy_scenewas declaredunsafe fn, but its# Safetycontract was stale and unenforceable. The documented precondition referenced abundle_writerparameter that this method does not have — the wording seems copied from ErasedComponentTemplate::apply, which does take abundle_writer: &mut BundleWriterand uses it inside an unsafe call. On ErasedBundleTemplate::apply there is nobundle_writer, so the stated caller-side obligation cannot be satisfied or verified.The default blanket impl only performs safe operations:
build_templateandEntityWorldMut::insertare both safe, so theunsafemarker imposed a caller obligation the body never needed.Solution
Drop the unnecessary
unsafeand remove the stale# Safetydocumentation, since no real caller-verifiable invariant exists for this method:Testing
The computer I use don't install the msvc, so I use the following command to test
cargo +nightly-x86_64-pc-windows-gnu build -p bevy_scene: Successfully buildcargo +nightly-x86_64-pc-windows-gnu test -p bevy_scene: Pass