Skip to content

Commit 42cf990

Browse files
committed
Make functional record update/struct update syntax works inside closures when feature capture_disjoint_fields is enabled
1 parent 180fdff commit 42cf990

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

compiler/rustc_mir_build/src/build/expr/as_place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl<'tcx> PlaceBuilder<'tcx> {
303303
self.base
304304
}
305305

306-
fn field(self, f: Field, ty: Ty<'tcx>) -> Self {
306+
crate fn field(self, f: Field, ty: Ty<'tcx>) -> Self {
307307
self.project(PlaceElem::Field(f, ty))
308308
}
309309

compiler/rustc_mir_build/src/build/expr/into.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
302302
let field_names = this.hir.all_fields(adt_def, variant_index);
303303

304304
let fields: Vec<_> = if let Some(FruInfo { base, field_types }) = base {
305-
let base = unpack!(block = this.as_place(block, base));
305+
let place_builder = unpack!(block = this.as_place_builder(block, base));
306306

307307
// MIR does not natively support FRU, so for each
308308
// base-supplied field, generate an operand that
@@ -312,9 +312,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
312312
.zip(field_types.into_iter())
313313
.map(|(n, ty)| match fields_map.get(&n) {
314314
Some(v) => v.clone(),
315-
None => this.consume_by_copy_or_move(
316-
this.hir.tcx().mk_place_field(base, n, ty),
317-
),
315+
None => {
316+
let place_builder = place_builder.clone();
317+
this.consume_by_copy_or_move(
318+
place_builder
319+
.field(n, ty)
320+
.into_place(this.hir.tcx(), this.hir.typeck_results()),
321+
)
322+
},
318323
})
319324
.collect()
320325
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// run-pass
2+
3+
// Test that functional record update/struct update syntax works inside
4+
// a closure when the feature `capture_disjoint_fields` is enabled.
5+
6+
#![feature(capture_disjoint_fields)]
7+
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
8+
//~| NOTE: `#[warn(incomplete_features)]` on by default
9+
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
10+
11+
struct S {
12+
a: String,
13+
b: String,
14+
}
15+
16+
fn main() {
17+
let a = String::new();
18+
let b = String::new();
19+
let s = S {a, b};
20+
21+
let c = || {
22+
let s2 = S {
23+
a: format!("New a"),
24+
..s
25+
};
26+
println!("{} {}", s2.a, s2.b);
27+
};
28+
29+
c();
30+
}

0 commit comments

Comments
 (0)