File: unresolvable-upvar-issue-87987.rs

package info (click to toggle)
rustc 1.87.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 925,564 kB
  • sloc: xml: 158,127; python: 36,039; javascript: 19,761; sh: 19,737; cpp: 18,981; ansic: 13,133; asm: 4,376; makefile: 710; perl: 29; lisp: 28; ruby: 19; sql: 11
file content (46 lines) | stat: -rw-r--r-- 1,200 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! When a closure syntactically captures a place, but doesn't actually capture
//! it, make sure MIR building doesn't ICE when handling that place.
//!
//! Under the Rust 2021 disjoint capture rules, this sort of non-capture can
//! occur when a place is only inspected by infallible non-binding patterns.

// FIXME(#135985): On its own, this test should probably just be check-pass.
// But there are few/no other tests that use non-binding array patterns and
// invoke the later parts of the compiler, so building/running has some value.

//@ run-pass
//@ edition:2021

#[expect(dead_code)]
struct Props {
    field_1: u32,
    field_2: u32,
}

fn main() {
    // Test 1
    let props_2 = Props { field_1: 1, field_2: 1 };

    let _ = || {
        let _: Props = props_2;
    };

    // Test 2
    let mut arr = [1, 3, 4, 5];

    let mref = &mut arr;

    // These array patterns don't need to inspect the array, so the array
    // isn't captured.
    let _c = || match arr {
        [_, _, _, _] => println!("C"),
    };
    let _d = || match arr {
        [_, .., _] => println!("D"),
    };
    let _e = || match arr {
        [_, ..] => println!("E"),
    };

    println!("{:#?}", mref);
}