forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#81291 - sexxi-goose:fix-struct-update-funct…
…ional-record-update-syntax-error, r=nikomatsakis Support FRU pattern with `[feature(capture_disjoint_fields)]` In case of a functional record update syntax for creating a structure, `ExprUseVisitor` to only detect the precise use of some of the field in the `..x` part of the syntax. However, when we start building MIR, we 1. First, build the place for `x` 2. and then, add precise field projections so that only some parts of `x` end up getting read. When `capture_disjoint_fields` is enabled, and FRU is used within a closure `x` won't be completely captured, and therefore the first step will fail. This PR updates `mir_build` to create a place builder in the first step and then create place from the builder only after applying the field projection. Closes rust-lang/project-rfc-2229#32 r? `@nikomatsakis`
- Loading branch information
Showing
4 changed files
with
67 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/test/ui/closures/2229_closure_analysis/run_pass/fru_syntax.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// run-pass | ||
|
||
// Test that functional record update/struct update syntax works inside | ||
// a closure when the feature `capture_disjoint_fields` is enabled. | ||
|
||
#![feature(capture_disjoint_fields)] | ||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete | ||
//~| NOTE: `#[warn(incomplete_features)]` on by default | ||
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> | ||
|
||
#[derive(Clone)] | ||
struct S { | ||
a: String, | ||
b: String, | ||
} | ||
|
||
struct T { | ||
a: String, | ||
s: S, | ||
} | ||
|
||
fn main() { | ||
let a = String::new(); | ||
let b = String::new(); | ||
let c = String::new(); | ||
let s = S {a, b}; | ||
let t = T { | ||
a: c, | ||
s: s.clone() | ||
}; | ||
|
||
let c = || { | ||
let s2 = S { | ||
a: format!("New s2"), | ||
..s | ||
}; | ||
let s3 = S { | ||
a: format!("New s3"), | ||
..t.s | ||
}; | ||
println!("{} {}", s2.a, s2.b); | ||
println!("{} {} {}", s3.a, s3.b, t.a); | ||
}; | ||
|
||
c(); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/test/ui/closures/2229_closure_analysis/run_pass/fru_syntax.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/fru_syntax.rs:6:12 | ||
| | ||
LL | #![feature(capture_disjoint_fields)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(incomplete_features)]` on by default | ||
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information | ||
|
||
warning: 1 warning emitted | ||
|