Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upNew destructor semantics #8861
Comments
nikomatsakis
referenced this issue
Aug 29, 2013
Closed
#[unsafe_destructor] is excessively unsafe (monomorphizes wrong) #6971
This comment has been minimized.
This comment has been minimized.
|
Accepted for well-defined |
ghost
assigned
nikomatsakis
Oct 29, 2013
glaebhoerl
referenced this issue
Jan 8, 2014
Closed
Forbid destructors on objects that aren't 'static bounded #11406
nikomatsakis
referenced this issue
Feb 18, 2014
Closed
Reorganise std::unstable::mutex to add an RAII unlocker to the mutex & replace LittleLock #12235
nikomatsakis
referenced this issue
Apr 1, 2014
Closed
rvalue destructors inside of a bare block run at the wrong time #13246
alexcrichton
referenced this issue
Apr 26, 2014
Closed
Allow destructors on a structure that does not satisfy Send, but can't have cycles #13778
This comment has been minimized.
This comment has been minimized.
|
Here is a specific example, from #13246, of unsound code we currently accept due to inadequate rules: This program: struct Foo { a: int }
impl Drop for Foo {
fn drop(&mut self) {
println!("{}", self.a);
}
}
fn main() {
{
let _1 = Foo { a: 1 };
let _2 = Foo { a: 2 };
match Foo { a: 3 } {
_ => {}
}
}
let _4 = Foo { a: 4 };
}should output
but instead outputs
It appears that if the bare block around the first part of This was originally reported to me in sfackler/rust-postgres#31 as a segfault, but it looks like that's probably just due to heap corruption from a use-after-free caused by this bug. UpdateIR: join: ; preds = %case_body
call void @_ZN3Foo14glue_drop.146917h02f639dd107d06daE(%struct.Foo* %_2)
call void @_ZN3Foo14glue_drop.146917h02f639dd107d06daE(%struct.Foo* %_1)
call void @_ZN3Foo14glue_drop.146917h02f639dd107d06daE(%struct.Foo* %0) ; <-- 3
%7 = getelementptr inbounds %struct.Foo* %_4, i32 0, i32 1
store i8 1, i8* %7
%8 = getelementptr inbounds %struct.Foo* %_4, i32 0, i32 0
store i64 4, i64* %8
call void @_ZN3Foo14glue_drop.146917h02f639dd107d06daE(%struct.Foo* %_4)
ret void |
This comment has been minimized.
This comment has been minimized.
|
Another problem: use std::cell::RefCell;
fn main() {
let b = {
let a = box RefCell::new(4);
*a.borrow() + 1
};
println!("{}", b);
}
As much as I'd love to punt on things for 1.0, this seems like a serious issue we need to fix. |
nikomatsakis
referenced this issue
Jun 17, 2014
Closed
Lifetimes can escape in traits / objects #5723
pnkfelix
added
the
A-destructors
label
Jul 8, 2014
pcwalton
added a commit
to pcwalton/rust
that referenced
this issue
Aug 1, 2014
pcwalton
referenced this issue
Aug 1, 2014
Closed
librustc: lifetimes in values-with-dtors must outlive such values themselves #16154
pcwalton
added a commit
to pcwalton/rust
that referenced
this issue
Sep 16, 2014
sfackler
referenced this issue
Oct 18, 2014
Closed
Allow (unsafe) access to the UnsafeCell inside RefCell #18131
glaebhoerl
referenced this issue
Oct 26, 2014
Open
Support for intrusive data structures and unmoveable types #417
pnkfelix
referenced this issue
Nov 17, 2014
Merged
Refactored new ScopeData for improved abstraction. #19033
bors
added a commit
that referenced
this issue
Nov 20, 2014
pnkfelix
referenced this issue
Dec 23, 2014
Closed
ICE: lifetime substitution in struct fields when struct implements Drop #14889
This comment has been minimized.
This comment has been minimized.
|
Does this rule mean code like this would be invalid? extern crate arena;
fn main() {
struct Foo<'a> { foo: ::std::cell::Cell<Option<&'a Foo<'a>>> }
let foo = arena::TypedArena::new();
let bar = foo.alloc(Foo { foo: ::std::cell::Cell::new(None) });
bar.foo.set(Some(&*bar));
}If so, I'm not really on board with it, as this is a very useful pattern (and is perfectly safe in this case), as this change seems to force the use of |
This comment has been minimized.
This comment has been minimized.
|
As an addendum: this only seems to be a memory safety issue when two things occur together:
If the struct does not have an explicit destructor, then for each field, either the field is a reference (in which case there is no drop glue, so it can't cause memory unsafety), the field is a non-reference and has a lifetime equal to itself (in which case we can recursively perform the same check), or the field is a non-reference with a lifetime strictly greater than itself (in which case it's fine and we can move on to the next field). This may not apply to |
pythonesque
referenced this issue
Jan 5, 2015
Closed
New scoping rules for safe destruction; not ready to land #20539
This comment has been minimized.
This comment has been minimized.
|
Nominating for -beta milestone. |
aturon
added
the
I-nominated
label
Jan 8, 2015
This comment has been minimized.
This comment has been minimized.
|
Moving ahead to the 1.0-beta milestone. |
pnkfelix
added this to the 1.0 beta milestone
Jan 8, 2015
pnkfelix
removed this from the 1.0 milestone
Jan 8, 2015
pnkfelix
removed
the
I-nominated
label
Jan 8, 2015
pcwalton
referenced
this issue
in servo/rust-cssparser
Jan 8, 2015
pnkfelix
added a commit
to pnkfelix/rust
that referenced
this issue
Jan 26, 2015
This was referenced Jan 26, 2015
pnkfelix
added a commit
to pnkfelix/rust
that referenced
this issue
Jan 27, 2015
bors
added a commit
that referenced
this issue
Jan 27, 2015
pnkfelix
referenced this issue
Feb 5, 2015
Merged
dropck and new scoping rules for safe destruction #21972
Byron
referenced this issue
Feb 9, 2015
Closed
Misleading error with Drop and lifetime parameters #17858
This comment has been minimized.
This comment has been minimized.
|
for people who come to this issue url due to its many references on github, the code base, and IRC: I suspect the most relevant thing for you to look at right now is the Sound Generic Drop RFC PR: rust-lang/rfcs#769 |
bors
added a commit
that referenced
this issue
Feb 11, 2015
bors
added a commit
that referenced
this issue
Feb 11, 2015
bors
added a commit
that referenced
this issue
Feb 11, 2015
bors
closed this
in
#21972
Feb 11, 2015
pnkfelix
referenced this issue
Feb 11, 2015
Closed
Once confident in dropck: remove `#[unsafe_destructor]` attribute #22196
pnkfelix
reopened this
Feb 12, 2015
This comment has been minimized.
This comment has been minimized.
|
The description for #21972 accidentally closed this ticket, but there is still work to be done; reopening. Also, assigning to myself since I pretty much own this topic at this point. |
pnkfelix
assigned
pnkfelix
and unassigned
nikomatsakis
Feb 12, 2015
This comment has been minimized.
This comment has been minimized.
|
reclassifying P-high, not 1.0 since everything for 1.0 is pretty much done (hopefully `unsafe_destructor will indeed be gone). |
pnkfelix
removed this from the 1.0 beta milestone
Mar 26, 2015
pnkfelix
added
P-medium
and removed
P-backcompat-lang
labels
Mar 26, 2015
This comment has been minimized.
This comment has been minimized.
|
closing; the remaining (hypothetical or far-future) work items are tracked on #22321 |
nikomatsakis commentedAug 29, 2013
Tracking issue for RFC #769, Sound Generic Drop.
Original description follows:
We agreed in a meeting to replace the unsafe destructor code with the rule that a value with a destructor must only contain values of lifetime strictly greater than the value to be destructed. The idea is to prevent values from referencing one another. Permitting borrowed values in destructors enables a number of RAII causes and helps to eliminate the need for once fns. This also relies on the change to prevent
&pointers from being placed within managed boxes (which I think has already been made).I have to figure out precisely how to formalize this rule still. =)
Nominating for backwards compat.
Update from @pnkfelix : Much of this is implemented, and so pnkfelix is listing out specific subtasks, issues, and/or PRs, to try to track what is done and what is left to do:
Dropfrom adding new bounds on a type param; Issue #8142<iterator-expr>only live for the for-loop itself. (i.e. turn for-loops into a terminating scope). Addresses the bulk Issue #21114. Resolved by #21984#[unsafe_destructor]attribute entirely; Issue #22196Far future / No longer deemed necessary
Vec<T>,Box<T>,Rc<T>, etc, covariant with respect toT. Discussed on issue #21198 (may not be a strict requirement for landing new destructor semantics).(See also #22321)