Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
proposal: spec: disallow T<->uintptr conversion for type T unsafe.Pointer #20171
Currently, implementations permit conversions to/from
Consequently, unsafe conversions can be hidden because package unsafe doesn't even have to be imported.
This was arguably an "implementation mistake" which we should fix. See also #19306.
Per #18130 (comment), I believe that it would be difficult to eliminate the possibility that packages that do not explicitly import
It may be more viable to disallow all conversions from
package unsafe type Pointer func Convert(Pointer) *T
@bcmills I don't think we make this bullet-proof - but at least I want it to be water-proof.
But I agree that if we reconsider the unsafe package interface entirely, we may find better solutions. Even with your suggestion, it's possible to encapsulate the desired conversions in functions exported by a package that's not the unsafe package. A client would only need to import that package.