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