File tree 4 files changed +39
-9
lines changed
4 files changed +39
-9
lines changed Original file line number Diff line number Diff line change @@ -70,10 +70,12 @@ impl<T> Rc<T> {
70
70
impl < T > Drop for Rc < T > {
71
71
fn finalize ( & self ) {
72
72
unsafe {
73
- ( * self . ptr ) . count -= 1 ;
74
- if ( * self . ptr ) . count == 0 {
75
- ptr:: replace_ptr ( self . ptr , intrinsics:: uninit ( ) ) ;
76
- free ( self . ptr as * c_void )
73
+ if self . ptr . is_not_null ( ) {
74
+ ( * self . ptr ) . count -= 1 ;
75
+ if ( * self . ptr ) . count == 0 {
76
+ ptr:: replace_ptr ( self . ptr , intrinsics:: uninit ( ) ) ;
77
+ free ( self . ptr as * c_void )
78
+ }
77
79
}
78
80
}
79
81
}
@@ -220,10 +222,12 @@ impl<T> RcMut<T> {
220
222
impl < T > Drop for RcMut < T > {
221
223
fn finalize ( & self ) {
222
224
unsafe {
223
- ( * self . ptr ) . count -= 1 ;
224
- if ( * self . ptr ) . count == 0 {
225
- ptr:: replace_ptr ( self . ptr , uninit ( ) ) ;
226
- free ( self . ptr as * c_void )
225
+ if self . ptr . is_not_null ( ) {
226
+ ( * self . ptr ) . count -= 1 ;
227
+ if ( * self . ptr ) . count == 0 {
228
+ ptr:: replace_ptr ( self . ptr , uninit ( ) ) ;
229
+ free ( self . ptr as * c_void )
230
+ }
227
231
}
228
232
}
229
233
}
Original file line number Diff line number Diff line change @@ -3883,7 +3883,7 @@ impl DtorKind {
3883
3883
pub fn ty_dtor ( cx : ctxt , struct_id : def_id ) -> DtorKind {
3884
3884
match cx. destructor_for_type . find ( & struct_id) {
3885
3885
Some ( & method_def_id) => {
3886
- let flag = has_attr ( cx, struct_id, "no_drop_flag" ) ;
3886
+ let flag = ! has_attr ( cx, struct_id, "no_drop_flag" ) ;
3887
3887
3888
3888
TraitDtor ( method_def_id, flag)
3889
3889
}
Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ pub struct AtomicPtr<T> {
62
62
/**
63
63
* An owned atomic pointer. Ensures that only a single reference to the data is held at any time.
64
64
*/
65
+ #[ no_drop_flag]
65
66
pub struct AtomicOption < T > {
66
67
priv p: * mut c_void
67
68
}
Original file line number Diff line number Diff line change
1
+ // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ use std:: sys:: size_of;
12
+
13
+ #[ no_drop_flag]
14
+ struct Test < T > {
15
+ a : T
16
+ }
17
+
18
+ #[ unsafe_destructor]
19
+ impl < T > Drop for Test < T > {
20
+ fn finalize ( & self ) { }
21
+ }
22
+
23
+ fn main ( ) {
24
+ assert_eq ! ( size_of:: <int>( ) , size_of:: <Test <int>>( ) ) ;
25
+ }
You can’t perform that action at this time.
0 commit comments