-
Notifications
You must be signed in to change notification settings - Fork 27
Port types returning &'static references is unsound #95
Copy link
Copy link
Open
Labels
💥 Unsound APIA bug that allows to trigger Undefined Behavior in safe RustA bug that allows to trigger Undefined Behavior in safe Rust💔 Breaking changeChanges to the code that will lead to break one or more APIsChanges to the code that will lead to break one or more APIs🦀 Blocked on Rust featureImplementing this requires Rust features that aren't stabilized yetImplementing this requires Rust features that aren't stabilized yet🐞 BugSomething isn't workingSomething isn't working
Metadata
Metadata
Assignees
Labels
💥 Unsound APIA bug that allows to trigger Undefined Behavior in safe RustA bug that allows to trigger Undefined Behavior in safe Rust💔 Breaking changeChanges to the code that will lead to break one or more APIsChanges to the code that will lead to break one or more APIs🦀 Blocked on Rust featureImplementing this requires Rust features that aren't stabilized yetImplementing this requires Rust features that aren't stabilized yet🐞 BugSomething isn't workingSomething isn't working
As of now, all port types return
&'staticreferences to their contents, which allows them to be stored outside of therun()function, at which point the host could invalidate them (the following code compiles fine today):While this example is rather obvious in that it's doing something very odd, issues can be viciously subtle with more complex port types such as
Atom: one could want to store a deserialized value.I haven't made any in-depth testing, but I see two solutions to this:
The first would be to make
PortTypegeneric over a'alifetime:However, this has a cascading effect, which would force all downstream users of port types to specify their lifetimes:
The second option would be to make the associated types themselves generic:
However, this would require Generic Associated Types being stabilized, but while it seems to be making steady progress, there doesn't seem to be any deadline coming soon.
Both options are breaking changes however.
I think we could potentially use the first solution now, and move to GATs when they are stabilized, making two breaking changes.