Non-borrowable values,


#1

tangent from another thread about enum packing options

Be wary of optimizations that are incompatible with pointers to the payload.
For example
let mut x: Option<Option> = Some(None);
let y: &mut Option = x.as_mut().unwrap();
y is a reference to just an Option, so we can’t fudge its discriminant from the outer layer.

so basically if I was to pack aligned pointers to different types selected by their lower bits … you wouldn’t be able to borrow the pointer-to-pointer, but you could still extract it through the match operation

Could this be fixed with a notion of types who’s content can never be borrowed - and may that have any other uses; (‘copy/move-only’). ( perhaps we could end up with every permutation of move/copy/borrow selectable as default or prohibited behaviour… I certainly want an ‘autoborrow’ option aswell…)

I know Rust can implement the situations I’m after already reasonably well through wrapped unsafe code; but it would be amazing if we could keep the elegance of enum/match (definitely one of rusts best features IMO) whilst accessing all the low level tricks (as an opt-in if anyone is worried about pushing unexpected/unsuitable defaults). Complexity in the compiler saves complexity in countless user programs, and if layered appropriately it should be ok.