Feature request: `assert_expr_impl!`
scottjmaddox opened this issue · 3 comments
Over on the rust internals board, betamos
noted that it would be nice to be able to annotate a type or value as sendable, and get a compile-time error if it is not. I thought this should be achievable using a macro, and that it would be a good fit for this crate. Maybe someone here can take a crack at it?
Edit: updated request to assert_expr_impl!
Is this not already achievable with assert_impl!(Type, Send)
? However, reading the comment by @betamos, it seems they want to assert that an expression is sendable. In which case, I guess an assert_expr_impl!
macro would be needed.
I actually didn't know about assert_impl!
! So yeah, that covers the type assertion! But it would also be nice to have an expression assertion.
macro_rules! assert_expr_impl_all {
($expr:expr => $($trait:path),+ $(,)?) => {
const _: fn() = || {
// Only callable when `$type` implements all traits in `$($trait)+`.
fn assert_expr_impl_all<T: ?Sized $(+ $trait)+>(_arg: &T) {}
assert_expr_impl_all(&$expr);
};
};
}