-
Notifications
You must be signed in to change notification settings - Fork 1
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
Dedup & de-lint #4
Conversation
So I have kind of meandering train of thought on this PR. First of all, there are some things that I think are strictly code clean up, where I was unnecessarily verbose because I didn't know how smart our compiler was. Specifically I mean:
A separate PR which just removed those two unnecessary unsafes and all the unnecessary turbofishes I would accept immediately. However, the other changes I'm less certain about. First, I notice overall that the In particular, I think creating a wrap function which just calls The other two wraps are a little more complicated, but I don't find the code they're unifying particularly hard to audit and so I don't really see the advantage of not repeating it. However, what I noticed is that they're not actualizing the real win that is possible here: both of these wrap functions are 100% safe, and could be marked safe. Creating a But I'd also point out that given that these are safe, these conversions should really be available in the standard library. I was surprised at how limited our APIs for safely converting smart pointers to NonNulls are, and I think its just an oversight. All we have is the ability to convert a Box using the incredibly verbose and unstable In other words, I think I'd be inclined to accept the wrap functions if they were marked safe, only for Rc and Arc, but I'd also like to start moving toward providing this functionality through the standard library instead of writing the abstraction ourselves. |
Makes sense to me, I'll resubmit. Thanks for sharing your thoughts, boats! |
Btw, I'm surprised Clippy doesn't have a check for an unnecessary |
@dwijnand its pretty difficult to tell that the unsafe is unnecessary, because a function could provide a totally safe operation that is only unsafe in the context of other methods on the same object. For example, |
Ah, I see. Makes sense. |
Hey @withoutboats, So I tried making this addition but I couldn't figure out where to put them, with NonNull in libcore and Rc/Arc in liballoc. I tried both. Any ideas? I also asked on Zulip. |
@dwijnand It needs to be in liballoc because libcore doesn't have access to
(I also think the division of libstd into these different crates instead of using cfg flags is sort of a bad design choice specifically because of these orphan rules problems, but that would be very hard to change at this point.) |
Thanks boats! I'll try Into, and if not fall back to the inherent. |
Add Into<NonNull<T>> impls for Arc<T>/Rc<T> /cc @withoutboats who mentioned to me this might be worth adding to the standard library, in withoutboats/smart#4 /cc @kennytm who last year didn't love the idea of having an Into<NonNull<T>> for Box<T>, in #46952
Just some cleanup I noticed in reading the code.
The last commit is extra - if you prefer the before state I can drop the commit.