-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Destructors and wild-card patterns (when do destructors run?) #3181
Comments
In general, I like the idea of always running destructors when the variable goes out of scope, although I don't think this will work so well for destructors in the heap. One of my common uses for destructors is to add some code that I want to be sure runs at function exit or failure. We get that now with |
I also would prefer that the pattern acted as a variable that you can't refer to and it's scoping behaves like other variables. |
Oh, but I guess then in patterns you would end up with a bunch of extra copies. |
@eholk I always use related #2735. it would be cool to be able to write |
In general, @pcwalton wants destructors to run when a value is "dead" rather than explicitly at the end of scope. The reason for this being primarily to deal with moves, which currently require a hokey extra field in structs to record whether the struct was moved or not---though I could imagine a hybrid version where destructors ran at the end of scope, unless you move the value, in which case they would be destroyed as soon as you enter a path where the value is dead but will not be moved. For example, if you had an My feeling however is that D probably does this better than C++. Destruction in D, as I understand it, occurs sometime between the variable being dead and it going out of scope. If you want to tie the destructor execution to the scope, you use a
in place of
the former of course creates a temporary and is probably not what you intended. |
I like the idea of destroying a value when it becomes dead also. It'd be great not to have to zero things out to know whether to run the destructors. |
This is reminiscent of the sequence-points and temporary-lifetimes issue we were discussing on IRC the other day. Needs a rigorous definition and rationale (including study of other languages), not things picked-at-random. It'll have far-reaching implications. |
Revisiting this for triage. I feel like this is something that needs a group meeting to decide. Either options seems feasible:
I think the pros/cons between those two are all aesthetic. |
@nikomatsakis can you weigh in on this matter? (deferring from this week's triage). |
as @alexcrichton summarized, work has already been done or is subsumed by #10488. Closing. |
fix the logic for retaining a comment before the arrow in a match
freebsd add *stat calls interception support
Context: #2735
I added a special-case to trans for
let _ = e;
wheree
has a destructor, so this gets treated the same way ase;
. However, @nikomatsakis points out that this isn't an entirely satisfactory solution, because for consistency, we'd also want to drop the RHS of the tuple inlet (x, _) = e;
early, or indeed, any sub-component of a data structure that's bound to a pattern with a deeply-nested_
in the corresponding position.Since we don't have a semantics for when destructors run, it's a little hard to say what the right thing is, but whatever we do should be consistent.
The text was updated successfully, but these errors were encountered: