|
| 1 | +//! When a closure syntactically captures a place, but doesn't actually capture |
| 2 | +//! it, make sure MIR building doesn't ICE when handling that place. |
| 3 | +//! |
| 4 | +//! Under the Rust 2021 disjoint capture rules, this sort of non-capture can |
| 5 | +//! occur when a place is only inspected by infallible non-binding patterns. |
| 6 | +
|
| 7 | +// FIXME(#135985): On its own, this test should probably just be check-pass. |
| 8 | +// But there are few/no other tests that use non-binding array patterns and |
| 9 | +// invoke the later parts of the compiler, so building/running has some value. |
| 10 | + |
| 11 | +//@ run-pass |
| 12 | +//@ edition:2021 |
| 13 | + |
| 14 | +#[expect(dead_code)] |
| 15 | +struct Props { |
| 16 | + field_1: u32, |
| 17 | + field_2: u32, |
| 18 | +} |
| 19 | + |
| 20 | +fn main() { |
| 21 | + // Test 1 |
| 22 | + let props_2 = Props { field_1: 1, field_2: 1 }; |
| 23 | + |
| 24 | + let _ = || { |
| 25 | + let _: Props = props_2; |
| 26 | + }; |
| 27 | + |
| 28 | + // Test 2 |
| 29 | + let mut arr = [1, 3, 4, 5]; |
| 30 | + |
| 31 | + let mref = &mut arr; |
| 32 | + |
| 33 | + // These array patterns don't need to inspect the array, so the array |
| 34 | + // isn't captured. |
| 35 | + let _c = || match arr { |
| 36 | + [_, _, _, _] => println!("C"), |
| 37 | + }; |
| 38 | + let _d = || match arr { |
| 39 | + [_, .., _] => println!("D"), |
| 40 | + }; |
| 41 | + let _e = || match arr { |
| 42 | + [_, ..] => println!("E"), |
| 43 | + }; |
| 44 | + |
| 45 | + println!("{:#?}", mref); |
| 46 | +} |
0 commit comments