]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/expect_tool_lint_rfc_2383.rs
Rollup merge of #102110 - CleanCut:migrate_rustc_passes_diagnostics, r=davidtwco
[rust.git] / src / tools / clippy / tests / ui / expect_tool_lint_rfc_2383.rs
1 // check-pass
2 #![feature(lint_reasons)]
3 //! This file tests the `#[expect]` attribute implementation for tool lints. The same
4 //! file is used to test clippy and rustdoc. Any changes to this file should be synced
5 //! to the other test files as well.
6 //!
7 //! Expectations:
8 //! * rustc: only rustc lint expectations are emitted
9 //! * clippy: rustc and Clippy's expectations are emitted
10 //! * rustdoc: only rustdoc lint expectations are emitted
11 //!
12 //! This test can't cover every lint from Clippy, rustdoc and potentially other
13 //! tools that will be developed. This therefore only tests a small subset of lints
14 #![expect(rustdoc::missing_crate_level_docs)]
15
16 mod rustc_ok {
17     //! See <https://doc.rust-lang.org/rustc/lints/index.html>
18
19     #[expect(dead_code)]
20     pub fn rustc_lints() {
21         let x = 42.0;
22
23         #[expect(illegal_floating_point_literal_pattern)]
24         match x {
25             5.0 => {}
26             6.0 => {}
27             _ => {}
28         }
29     }
30 }
31
32 mod rustc_warn {
33     //! See <https://doc.rust-lang.org/rustc/lints/index.html>
34
35     #[expect(dead_code)]
36     pub fn rustc_lints() {
37         let x = 42;
38
39         #[expect(illegal_floating_point_literal_pattern)]
40         match x {
41             5 => {}
42             6 => {}
43             _ => {}
44         }
45     }
46 }
47
48 pub mod rustdoc_ok {
49     //! See <https://doc.rust-lang.org/rustdoc/lints.html>
50
51     #[expect(rustdoc::broken_intra_doc_links)]
52     /// I want to link to [`Nonexistent`] but it doesn't exist!
53     pub fn foo() {}
54
55     #[expect(rustdoc::invalid_html_tags)]
56     /// <h1>
57     pub fn bar() {}
58
59     #[expect(rustdoc::bare_urls)]
60     /// http://example.org
61     pub fn baz() {}
62 }
63
64 pub mod rustdoc_warn {
65     //! See <https://doc.rust-lang.org/rustdoc/lints.html>
66
67     #[expect(rustdoc::broken_intra_doc_links)]
68     /// I want to link to [`bar`] but it doesn't exist!
69     pub fn foo() {}
70
71     #[expect(rustdoc::invalid_html_tags)]
72     /// <h1></h1>
73     pub fn bar() {}
74
75     #[expect(rustdoc::bare_urls)]
76     /// <http://example.org>
77     pub fn baz() {}
78 }
79
80 mod clippy_ok {
81     //! See <https://rust-lang.github.io/rust-clippy/master/index.html>
82
83     #[expect(clippy::almost_swapped)]
84     fn foo() {
85         let mut a = 0;
86         let mut b = 9;
87         a = b;
88         b = a;
89     }
90
91     #[expect(clippy::bytes_nth)]
92     fn bar() {
93         let _ = "Hello".bytes().nth(3);
94     }
95
96     #[expect(clippy::if_same_then_else)]
97     fn baz() {
98         let _ = if true { 42 } else { 42 };
99     }
100
101     #[expect(clippy::overly_complex_bool_expr)]
102     fn burger() {
103         let a = false;
104         let b = true;
105
106         if a && b || a {}
107     }
108 }
109
110 mod clippy_warn {
111     //! See <https://rust-lang.github.io/rust-clippy/master/index.html>
112
113     #[expect(clippy::almost_swapped)]
114     fn foo() {
115         let mut a = 0;
116         let mut b = 9;
117         a = b;
118     }
119
120     #[expect(clippy::bytes_nth)]
121     fn bar() {
122         let _ = "Hello".as_bytes().get(3);
123     }
124
125     #[expect(clippy::if_same_then_else)]
126     fn baz() {
127         let _ = if true { 33 } else { 42 };
128     }
129
130     #[expect(clippy::overly_complex_bool_expr)]
131     fn burger() {
132         let a = false;
133         let b = true;
134         let c = false;
135
136         if a && b || c {}
137     }
138 }
139
140 fn main() {
141     rustc_warn::rustc_lints();
142 }