safe transmute: use Assume
struct to provide analysis options by jswrenn · Pull Request #100726 · rust-lang/rust (original) (raw)
I also attempted to implement Add
and Sub
for Assume
(another part of MCP411):
#[unstable(feature = "transmutability", issue = "99571")] #[rustc_const_unstable(feature = "transmutability", issue = "99571")] impl const core::ops::Add for Assume { type Output = Assume;
fn add(self, rhs: Assume) -> Assume {
Assume {
alignment: self.alignment || rhs.alignment,
lifetimes: self.lifetimes || rhs.lifetimes,
safety: self.safety || rhs.safety,
validity: self.validity || rhs.validity,
}
}
}
#[unstable(feature = "transmutability", issue = "99571")] #[rustc_const_unstable(feature = "transmutability", issue = "99571")] impl const core::ops::Sub for Assume { type Output = Assume;
fn sub(self, rhs: Assume) -> Assume {
Assume {
alignment: self.alignment && !rhs.alignment,
lifetimes: self.lifetimes && !rhs.lifetimes,
safety: self.safety && !rhs.safety,
validity: self.validity && !rhs.validity,
}
}
}
...but attempting to use these impls in the UI tests results in errors; e.g.:
error[E0015]: cannot call non-const operator in constants
--> /home/ubuntu/projects/rust/src/test/ui/transmutability/arrays/should_have_correct_length.rs:14:52
|
LL | Dst: BikeshedIntrinsicFrom<Src, Context, { Assume::SAFETY + Assume::VALIDITY }>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: impl defined here, but it is not `const`
--> /home/ubuntu/projects/rust/library/core/src/mem/transmutability.rs:65:1
|
LL | impl const core::ops::Add for Assume {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
Anyone know what's going on here? The error message seems non-sensical.