Skip to content

Commit 950e146

Browse files
committed
Add implicitely initialized Inner
1 parent 0f9ed7a commit 950e146

3 files changed

Lines changed: 18 additions & 15 deletions

File tree

‎tests/unit/in_class_field_initializer.cpp‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ struct S {
1010
int a = 1;
1111
char b = 2;
1212
Inner c = {};
13+
Inner d;
1314
};
1415

1516
int main() {
16-
S s{};
17+
S s;
1718
assert(s.a == 1);
1819
assert(s.b == 2);
1920
assert(s.c.x == 3);
2021
assert(s.c.y == 4);
22+
assert(s.d.x == 3);
23+
assert(s.d.y == 4);
2124
return 0;
2225
};

‎tests/unit/out/refcount/in_class_field_initializer.rs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ pub struct S {
4848
pub a: Value<i32>,
4949
pub b: Value<u8>,
5050
pub c: Value<Inner>,
51+
pub d: Value<Inner>,
5152
}
5253
impl Clone for S {
5354
fn clone(&self) -> Self {
5455
let mut this = Self {
5556
a: Rc::new(RefCell::new((*self.a.borrow()))),
5657
b: Rc::new(RefCell::new((*self.b.borrow()))),
5758
c: Rc::new(RefCell::new((*self.c.borrow()).clone())),
59+
d: Rc::new(RefCell::new((*self.d.borrow()).clone())),
5860
};
5961
this
6062
}
@@ -68,41 +70,39 @@ impl Default for S {
6870
x: Rc::new(RefCell::new(3)),
6971
y: Rc::new(RefCell::new(4)),
7072
})),
73+
d: <Value<Inner>>::default(),
7174
}
7275
}
7376
}
7477
impl ByteRepr for S {
7578
fn byte_size() -> usize {
76-
16
79+
24
7780
}
7881
fn to_bytes(&self, buf: &mut [u8]) {
7982
(*self.a.borrow()).to_bytes(&mut buf[0..4]);
8083
(*self.b.borrow()).to_bytes(&mut buf[4..5]);
8184
(*self.c.borrow()).to_bytes(&mut buf[8..16]);
85+
(*self.d.borrow()).to_bytes(&mut buf[16..24]);
8286
}
8387
fn from_bytes(buf: &[u8]) -> Self {
8488
Self {
8589
a: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
8690
b: Rc::new(RefCell::new(<u8>::from_bytes(&buf[4..5]))),
8791
c: Rc::new(RefCell::new(<Inner>::from_bytes(&buf[8..16]))),
92+
d: Rc::new(RefCell::new(<Inner>::from_bytes(&buf[16..24]))),
8893
}
8994
}
9095
}
9196
pub fn main() {
9297
std::process::exit(main_0());
9398
}
9499
fn main_0() -> i32 {
95-
let s: Value<S> = Rc::new(RefCell::new(S {
96-
a: Rc::new(RefCell::new(1)),
97-
b: Rc::new(RefCell::new(2_u8)),
98-
c: Rc::new(RefCell::new(Inner {
99-
x: Rc::new(RefCell::new(3)),
100-
y: Rc::new(RefCell::new(4)),
101-
})),
102-
}));
100+
let s: Value<S> = Rc::new(RefCell::new(<S>::default()));
103101
assert!(((*(*s.borrow()).a.borrow()) == 1));
104102
assert!((((*(*s.borrow()).b.borrow()) as i32) == 2));
105103
assert!(((*(*(*s.borrow()).c.borrow()).x.borrow()) == 3));
106104
assert!(((*(*(*s.borrow()).c.borrow()).y.borrow()) == 4));
105+
assert!(((*(*(*s.borrow()).d.borrow()).x.borrow()) == 3));
106+
assert!(((*(*(*s.borrow()).d.borrow()).y.borrow()) == 4));
107107
return 0;
108108
}

‎tests/unit/out/unsafe/in_class_field_initializer.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ pub struct S {
2323
pub a: i32,
2424
pub b: libc::c_char,
2525
pub c: Inner,
26+
pub d: Inner,
2627
}
2728
impl Default for S {
2829
fn default() -> Self {
2930
S {
3031
a: 1,
3132
b: (2 as libc::c_char),
3233
c: Inner { x: 3, y: 4 },
34+
d: <Inner>::default(),
3335
}
3436
}
3537
}
@@ -39,14 +41,12 @@ pub fn main() {
3941
}
4042
}
4143
unsafe fn main_0() -> i32 {
42-
let mut s: S = S {
43-
a: 1,
44-
b: (2 as libc::c_char),
45-
c: Inner { x: 3, y: 4 },
46-
};
44+
let mut s: S = <S>::default();
4745
assert!(((s.a) == (1)));
4846
assert!(((s.b as i32) == (2)));
4947
assert!(((s.c.x) == (3)));
5048
assert!(((s.c.y) == (4)));
49+
assert!(((s.d.x) == (3)));
50+
assert!(((s.d.y) == (4)));
5151
return 0;
5252
}

0 commit comments

Comments
 (0)