Tracking Issue for breaking lifetime changing raw pointer casts of trait objects #141402
Labels
A-dyn-trait
Area: trait objects, vtable layout
A-raw-pointers
Area: raw pointers, MaybeUninit, NonNull
C-tracking-issue
Category: An issue tracking the progress of sth. like the implementation of an RFC
F-arbitrary_self_types
`#![feature(arbitrary_self_types)]`
F-derive_coerce_pointee
Feature: RFC 3621's oft-renamed implementation
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
This is the tracking issue for the breaking change made in #136776 The goal of this page is describe why this change was made and how you can fix code that is affected by it. It also provides a place to ask questions or register a complaint if you feel the change should not be made.
What is the warning for?
As part of stabilizing the
arbitrary_self_types
andderive_coerce_pointee
we needed to change what raw pointer casts are legal. Specifically, casting*const dyn Trait + 'a
to*const dyn Trait + 'b
where it is not able to be proven that'a
outlives'b
has become an error.Why was this change made?
Casting the lifetime bound on trait objects can invalidate the VTable for the trait object allowing for dispatching to methods that should not be callable. When a trait method has a
where Self: 'a
bound, casting the lifetime bound on a trait object may cause the method to go from uncallable to callable.Example
Migration
Existing code can be trivially migrated by converting the offending raw pointer cast to a lifetime affecting transmute. See metrics-rs/metrics#564 as an example of how such a migration can be accomplished. It's advised to only do so if actually sure that extending the lifetime of the trait object is sound.
Related Links
The text was updated successfully, but these errors were encountered: