-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Description
Because mem::transmute checks its constraints before monomorphization, it fails for types containing fields whose type is determined by a generic parameter:
cannot transmute to or from a type that contains unsubstituted type parameters
It's great that it attempts to catch errors as early as possible, but if it's unable to prove that the 'to' and 'from' types have the same or different representations before monomorphization, it should fall back to checking them after, when it can get a definitive answer.
There's a slightly convoluted work-around which involves using ptr::read followed by mem::forget on the original to prevent it being dropped twice, but there's no guarantee that will compile into the same zero-cost operation as transmute, and it won't perform any checks that the two types have the same representation.
An alternative would be to leave the restrictions on mem::transmute unchanged and add a new intrinsic instead.