From: Matt Corallo Date: Thu, 27 Jul 2023 20:00:25 +0000 (+0000) Subject: Fix strict-aliasing violation on traits holding inner fields X-Git-Tag: v0.0.115.3^2~2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=cd94859a3ef20447674f393d3f169bd9e29023a1;hp=cd94859a3ef20447674f393d3f169bd9e29023a1;p=ldk-c-bindings Fix strict-aliasing violation on traits holding inner fields When we map a trait method which returns a reference to a struct, we map it by storing said struct in the trait implementation struct. Then, we create a setter method which ensures the new field is set. Sadly, because the original Rust trait method may take a non-mutable reference to self, we have to update the field without a mutable reference to the trait implementation struct. Previously we did this by simply unsafe-casting a pointer to mutable, which violates the aliasing rules in Rust. In a recent rustc (at least on macOS), this broke. Here, we convert the stored struct to wrap it in an `UnsafeCell`, which fixes the issue. ---