Skip to content

Commit 6d6bf81

Browse files
committed
Auto merge of #28123 - Aatch:fix-silly-tuple-constructor, r=eddyb
This was preventing any side-effects from the expressions from happening. Fixes #28114 cc @rust-lang/compiler
2 parents ce40c48 + 4637d42 commit 6d6bf81

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/librustc_trans/trans/base.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,17 @@ pub fn trans_named_tuple_constructor<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
17581758
}
17591759
_ => ccx.sess().bug("expected expr as arguments for variant/struct tuple constructor")
17601760
}
1761+
} else {
1762+
// Just eval all the expressions (if any). Since expressions in Rust can have arbitrary
1763+
// contents, there could be side-effects we need from them.
1764+
match args {
1765+
callee::ArgExprs(exprs) => {
1766+
for expr in exprs {
1767+
bcx = expr::trans_into(bcx, expr, expr::Ignore);
1768+
}
1769+
}
1770+
_ => ()
1771+
}
17611772
}
17621773

17631774
// If the caller doesn't care about the result
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
#![allow(unused_assignments)]
12+
13+
// Make sure that the constructor args are translated for zero-sized tuple structs
14+
15+
struct Foo(());
16+
17+
fn main() {
18+
let mut a = 1;
19+
Foo({ a = 2 });
20+
assert_eq!(a, 2);
21+
}

0 commit comments

Comments
 (0)