-
Notifications
You must be signed in to change notification settings - Fork 286
clarify passage on problematic use of transmute #486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clarify passage on problematic use of transmute #486
Conversation
Thanks for the PR. I kind of see what this is trying to get at, but it would need to say a lot more to make this point correctly. And it may not be worth doing that since the elaboration is already there on the linked pages. So we're going to close this. |
@traviscross The problem is the verb produces, as it's not always true. Why not be correct in technical documentation? Don't let perfect be the enemy of good. |
Maybe it'd help if you wrote out a code example of the case you're trying to cover here. |
@traviscross I have a unsafe { transmute::<&mut [MaybeUninit<u8>], &mut [u8]>(buf.mut_slice()) } Now this value is passed into |
If you could write out a full example including the call to Please write it in a self-contained way that works in the playground. |
In your example, the lifetime of that slice is indeed unbounded. To see this, add, e.g.: fn is_unbounded<T>(_: T) where for<'a> T: 'a {}
is_unbounded(slice); That doesn't necessarily mean you're doing anything wrong, but the lifetime there is not bounded. |
I see what you mean. I tried to think of more involved examples to make my point, but I realized that all my valid examples would end up coercing the lifetime, either implicitly or explicitly, from unbounded to named. So I suppose the wording is correct: transmute will produce unbounded lifetimes if that's the types given to it. Are you still sure that no clarification is needed? Perhaps one more sentence can be added. Every other bullet point has at least two sentences. "The transmuted value should not be used in contexts where the original lifetime would be rejected." or so? |
No description provided.