Rollup merge of #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 #95271. Fixes #96299. Fixes #96512. Fixes #97378. r? ``@nikomatsakis`` ``@arora-aman``
This commit is contained in:
commit
fd76e0eee0
5 changed files with 85 additions and 21 deletions
|
|
@ -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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue