-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Mark std::mem::drop
as unstable until negative bounds are implemented
#536
Conversation
On IRC it has been mentioned that an alternative would be to have a lint specifically for this function, that would give a compilation error if the function is called with an implicitly copyable type. I'm fine with this solution, as long as the lint cannot be overridden. My only concern is that this function should not be callable with an implicitly copyable type, regardless of how that is achieved. |
This would be problematic when used with generic functions. Something like this: fn frob<T>(x: T) {
// …do something…
drop(x);
// …do some more things…
} is perfectly valid today, but will not compile under this change. A lint would probably be much better because it could ignore cases like this where the type might be Another alternative is to put a |
A |
@P1start I contend that that generic code is wrong. If you expect |
bstrie: the code might not be intending to "do" anything from its own perspective, but simply trying to be a good citizen and release the object as soon as it's not needed. However such generic code strikes me as a bit contrived (taking something by-value that you only need temporarily, but otherwise know nothing about). I would personally be interested in "upgrading" drop so that it effectively kills the variable of interest. In this way it could be used to "unborrow" a reference in the middle of a scope, without having to scope-juggle variables. |
@gankro would your scheme require |
It would probably have to be an intrinsic of some kind. Same as mem::forget. |
If |
Yes, if |
|
@P1start I'm not sure if "variable is not used after this point" is part of the scope of non-lexical lifetimes (I think that would imply eager drop?). In particular note that if you drop() an &T it only gets copied. You can only end a borrow based on an &T by having the variable of interest go out of scope. If drop/discard actual killed the variable itself (semantically), then this would be accomplished (might still need non-lexical for that fact to register. |
The SEME regions RFC mentions shortening borrows within the same scope as the first point in the Motivation section. |
@P1start Ah, you're correct (been a long while since I read that). Point retracted, then! |
See |
If we want this, it should probably go in a lint, not as a generic. |
This seems really pointless to me, unless we get types that implement both Any confusion that is currently caused by |
@bstrie Thanks for the RFC. After the discussion here and on IRC, it seems preferable to create a lint for this instead (which could likely be landed directly as a PR) -- it could probably give a clearer error message than negative bounds (which do not yet have a fully fleshed out design). I'm going to close this RFC in favor of a lint. |
Rendered