about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/unnecessary_semicolon.edition2024.fixed
blob: d2609cea0002762faf00663b86137d7505953bb9 (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
74
//@revisions: edition2021 edition2024
//@[edition2021] edition:2021
//@[edition2024] edition:2024

#![warn(clippy::unnecessary_semicolon)]
#![feature(postfix_match)]
#![allow(clippy::single_match)]

fn no_lint(mut x: u32) -> Option<u32> {
    Some(())?;

    {
        let y = 3;
        dbg!(x + y)
    };

    {
        let (mut a, mut b) = (10, 20);
        (a, b) = (b + 1, a + 1);
    }

    Some(0)
}

fn main() {
    let mut a = 3;
    if a == 2 {
        println!("This is weird");
    }
    //~^ unnecessary_semicolon

    a.match {
        3 => println!("three"),
        _ => println!("not three"),
    }
    //~^ unnecessary_semicolon
}

// This is a problem in edition 2021 and below
fn borrow_issue() {
    let v = std::cell::RefCell::new(Some(vec![1]));
    match &*v.borrow() {
        Some(v) => {
            dbg!(v);
        },
        None => {},
    }
    //~[edition2024]^ unnecessary_semicolon
}

fn no_borrow_issue(a: u32, b: u32) {
    match Some(a + b) {
        Some(v) => {
            dbg!(v);
        },
        None => {},
    }
    //~^ unnecessary_semicolon
}

fn issue14100() -> bool {
    // Removing the `;` would make the block type be `()` instead of `!`, and this could no longer be
    // cast into the `bool` function return type.
    if return true {};
}

fn issue15426(x: u32) {
    // removing the `;` would turn the stmt into an expr, but attrs aren't allowed on exprs
    #[rustfmt::skip]
    match x {
        0b00 => {}  0b01 => {}
        0b11 => {}  _    => {}
    };
}