about summary refs log tree commit diff
path: root/src/tools/rustfmt/tests/target/let_else_v2.rs
blob: 6e886299cb097185aa23b3cc0c08c20220a82efc (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// rustfmt-style_edition: 2024
// rustfmt-single_line_let_else_max_width: 100

fn issue5901() {
    #[cfg(target_os = "linux")]
    let Some(x) = foo else { todo!() };

    #[cfg(target_os = "linux")]
    // Some comments between attributes and let-else statement
    let Some(x) = foo else { todo!() };

    #[cfg(target_os = "linux")]
    #[cfg(target_arch = "x86_64")]
    let Some(x) = foo else { todo!() };

    // The else block is multi-lined
    #[cfg(target_os = "linux")]
    let Some(x) = foo else {
        return;
    };

    // The else block will be single-lined because attributes and comments before `let`
    // are no longer included when calculating max width
    #[cfg(target_os = "linux")]
    #[cfg(target_arch = "x86_64")]
    // Some comments between attributes and let-else statement
    let Some(x) = foo else { todo!() };

    // Some more test cases for v2 formatting with attributes

    #[cfg(target_os = "linux")]
    #[cfg(target_arch = "x86_64")]
    let Some(x) = opt
    // pre else keyword line-comment
    else {
        return;
    };

    #[cfg(target_os = "linux")]
    #[cfg(target_arch = "x86_64")]
    let Some(x) = opt else
    // post else keyword line-comment
    {
        return;
    };

    #[cfg(target_os = "linux")]
    #[cfg(target_arch = "x86_64")]
    let Foo {
        x: Bar(..),
        y: FooBar(..),
        z: Baz(..),
    } = opt
    else {
        return;
    };

    #[cfg(target_os = "linux")]
    #[cfg(target_arch = "x86_64")]
    let Some(Ok((Message::ChangeColor(super::color::Color::Rgb(r, g, b)), Point { x, y, z }))) =
        opt
    else {
        return;
    };

    #[cfg(target_os = "linux")]
    #[cfg(target_arch = "x86_64")]
    let Some(x) =
        very_very_very_very_very_very_very_very_very_very_very_very_long_expression_in_assign_rhs()
    else {
        return;
    };
}