Remove implicit object lifetime cast #1
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.
Hi there o/
I'm a member of the Rust Language's Types Team; as part of stabilizing the
arbitrary_self_typesandderive_coerce_pointeefeatures we are changing what raw pointer casts are legal (rust-lang/rust#136702). Specifically, casting*const dyn Trait + 'ato*const dyn Trait + 'bwhere it is not able to be proven that'aoutlives'bwill become an error.Without going into too much detail, the justification for this change is that casting trait object's lifetime bound to a lifetime that lives for a longer time could invalidate the VTable of the trait object, allowing for dispatching to methods that should not be callable. See this example from the linked issue:
Unfortunately, going through the usual "future compatibility warning" process turned out to not be possible as checking lifetime constraints without emitting an error is prohibitively difficult to do in the implementation of the borrow checker. This means that you will never receive an FCW and its associated grace period to update your code to be compatible with the new rules.
I have attempted to update your codebase to the new rules for you so that it will still compile when we make this change. I hope this breakage won't cause you too much trouble and that you might even find the post-migration code to be better than how it was previously :-)
If you have any questions about why this change is required please let me know and I'll do my best to further explain the justification.
It wasn't clear to me if the pointer casts here were supposed to be implicitly casting the lifetimes of the trait object to
'static. This is currently happening because writing*mut dyn Traitin the return type of a function signature desguars to*mut dyn Trait + 'static, with this change we now write*mut dyn Trait + '_which introduces a new lifetime parameter.