Skip to content

Commit fb225d1

Browse files
committed
Test expect attribute for tool lints, clippy edition (RFC 2383)
1 parent cd51c7c commit fb225d1

File tree

2 files changed

+182
-0
lines changed

2 files changed

+182
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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::logic_bug)]
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::logic_bug)]
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
error: this lint expectation is unfulfilled
2+
--> $DIR/expect_tool_lint_rfc_2383.rs:35:14
3+
|
4+
LL | #[expect(dead_code)]
5+
| ^^^^^^^^^
6+
|
7+
= note: `-D unfulfilled-lint-expectations` implied by `-D warnings`
8+
9+
error: this lint expectation is unfulfilled
10+
--> $DIR/expect_tool_lint_rfc_2383.rs:39:18
11+
|
12+
LL | #[expect(illegal_floating_point_literal_pattern)]
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
15+
error: this lint expectation is unfulfilled
16+
--> $DIR/expect_tool_lint_rfc_2383.rs:113:14
17+
|
18+
LL | #[expect(clippy::almost_swapped)]
19+
| ^^^^^^^^^^^^^^^^^^^^^^
20+
21+
error: this lint expectation is unfulfilled
22+
--> $DIR/expect_tool_lint_rfc_2383.rs:120:14
23+
|
24+
LL | #[expect(clippy::bytes_nth)]
25+
| ^^^^^^^^^^^^^^^^^
26+
27+
error: this lint expectation is unfulfilled
28+
--> $DIR/expect_tool_lint_rfc_2383.rs:125:14
29+
|
30+
LL | #[expect(clippy::if_same_then_else)]
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
32+
33+
error: this lint expectation is unfulfilled
34+
--> $DIR/expect_tool_lint_rfc_2383.rs:130:14
35+
|
36+
LL | #[expect(clippy::logic_bug)]
37+
| ^^^^^^^^^^^^^^^^^
38+
39+
error: aborting due to 6 previous errors
40+

0 commit comments

Comments
 (0)