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#97325 - tmiasko:capture-enum-field, r=arora…
…-aman Fix precise field capture of univariant enums When constructing a MIR from a THIR field expression, introduce an additional downcast projection before accessing a field of an enum. When rebasing a place builder on top of a captured place, account for the fact that a single HIR enum field projection corresponds to two MIR projection elements: a downcast element and a field element. Fixes rust-lang#95271. Fixes rust-lang#96299. Fixes rust-lang#96512. Fixes rust-lang#97378. r? `@nikomatsakis` `@arora-aman`
- Loading branch information
Showing
5 changed files
with
85 additions
and
21 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
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
27 changes: 27 additions & 0 deletions
27
src/test/ui/closures/2229_closure_analysis/capture-enum-field.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,27 @@ | ||
// edition:2021 | ||
// run-pass | ||
|
||
#[derive(Debug, PartialEq, Eq)] | ||
pub enum Color { | ||
RGB(u8, u8, u8), | ||
} | ||
|
||
fn main() { | ||
let mut color = Color::RGB(0, 0, 0); | ||
let mut red = |v| { | ||
let Color::RGB(ref mut r, _, _) = color; | ||
*r = v; | ||
}; | ||
let mut green = |v| { | ||
let Color::RGB(_, ref mut g, _) = color; | ||
*g = v; | ||
}; | ||
let mut blue = |v| { | ||
let Color::RGB(_, _, ref mut b) = color; | ||
*b = v; | ||
}; | ||
red(1); | ||
green(2); | ||
blue(3); | ||
assert_eq!(Color::RGB(1, 2, 3), color); | ||
} |