I’m not really sure that this is a particularly good idea, but for sake of discussion I’ll propose a strawman subset of expressions we can consider “trivial”, which is not closed under composition. These are things I would expect you’d want to inline.
-
as casts
- Primitive arithmetic, where both operands are identifiers or literals.
- Single function calls, where all arguments are identifiers or literals.
- Copying out of a variable or a pointer.
- Constructing a trivially-destructible type.
- Branching, maybe?
- Unsafe intrinsics like
ptr::read and mem::transmute (hahaha please no).
I could probably spend the rest of my morning listing these, but I think that’s a pointless exercise. I think what you really want is something like this:
pub unsafe trait Cast<T>: Into<T> {}
Implementing this trait is the assertion that your Into implementation is a cast (or a similar O(1) operation), in a similar way to how implementing Copy asserts that your type’s Clone is just a memcpy. I’m not really sure how this is useful, though…