about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-05-09 00:02:55 +0000
committerbors <bors@rust-lang.org>2022-05-09 00:02:55 +0000
commit670bc53c0350b461b0d9bdb9451261c0d805ecef (patch)
treebe6f177126b88da770b1748c3ca371f6fb330bd4
parent1d018ce47ce8ee6047ca6f92b89fb5b97b2ee5eb (diff)
parent21e4765e58b0f92bc266c5370ecec270c0b2206c (diff)
downloadrust-670bc53c0350b461b0d9bdb9451261c0d805ecef.tar.gz
rust-670bc53c0350b461b0d9bdb9451261c0d805ecef.zip
Auto merge of #95542 - xFrednet:rfc-2383-expect-query, r=wesleywiser
Support tool lints with the `#[expect]` attribute (RFC 2383)

This PR fixes the ICE https://github.com/rust-lang/rust/issues/94953 by making the assert for converted expectation IDs conditional.

Additionally, it moves the lint expectation check into a separate query to support rustdoc and other tools. On the way, I've also added some tests to ensure that the attribute works for Clippy and rustdoc lints.

The number of changes comes from the long test file. This may look like a monster PR, this may smell like a monster PR and this may be a monster PR, but it's a harmless monster. :sauropod:

---

Closes: https://github.com/rust-lang/rust/issues/94953

cc: https://github.com/rust-lang/rust/issues/85549

r? `@wesleywiser`

cc: `@rust-lang/rustdoc`
-rw-r--r--tests/ui/expect_tool_lint_rfc_2383.rs142
-rw-r--r--tests/ui/expect_tool_lint_rfc_2383.stderr40
2 files changed, 182 insertions, 0 deletions
diff --git a/tests/ui/expect_tool_lint_rfc_2383.rs b/tests/ui/expect_tool_lint_rfc_2383.rs
new file mode 100644
index 00000000000..28b37f96e91
--- /dev/null
+++ b/tests/ui/expect_tool_lint_rfc_2383.rs
@@ -0,0 +1,142 @@
+// check-pass
+#![feature(lint_reasons)]
+//! This file tests the `#[expect]` attribute implementation for tool lints. The same
+//! file is used to test clippy and rustdoc. Any changes to this file should be synced
+//! to the other test files as well.
+//!
+//! Expectations:
+//! * rustc: only rustc lint expectations are emitted
+//! * clippy: rustc and Clippy's expectations are emitted
+//! * rustdoc: only rustdoc lint expectations are emitted
+//!
+//! This test can't cover every lint from Clippy, rustdoc and potentially other
+//! tools that will be developed. This therefore only tests a small subset of lints
+#![expect(rustdoc::missing_crate_level_docs)]
+
+mod rustc_ok {
+    //! See <https://doc.rust-lang.org/rustc/lints/index.html>
+
+    #[expect(dead_code)]
+    pub fn rustc_lints() {
+        let x = 42.0;
+
+        #[expect(illegal_floating_point_literal_pattern)]
+        match x {
+            5.0 => {}
+            6.0 => {}
+            _ => {}
+        }
+    }
+}
+
+mod rustc_warn {
+    //! See <https://doc.rust-lang.org/rustc/lints/index.html>
+
+    #[expect(dead_code)]
+    pub fn rustc_lints() {
+        let x = 42;
+
+        #[expect(illegal_floating_point_literal_pattern)]
+        match x {
+            5 => {}
+            6 => {}
+            _ => {}
+        }
+    }
+}
+
+pub mod rustdoc_ok {
+    //! See <https://doc.rust-lang.org/rustdoc/lints.html>
+
+    #[expect(rustdoc::broken_intra_doc_links)]
+    /// I want to link to [`Nonexistent`] but it doesn't exist!
+    pub fn foo() {}
+
+    #[expect(rustdoc::invalid_html_tags)]
+    /// <h1>
+    pub fn bar() {}
+
+    #[expect(rustdoc::bare_urls)]
+    /// http://example.org
+    pub fn baz() {}
+}
+
+pub mod rustdoc_warn {
+    //! See <https://doc.rust-lang.org/rustdoc/lints.html>
+
+    #[expect(rustdoc::broken_intra_doc_links)]
+    /// I want to link to [`bar`] but it doesn't exist!
+    pub fn foo() {}
+
+    #[expect(rustdoc::invalid_html_tags)]
+    /// <h1></h1>
+    pub fn bar() {}
+
+    #[expect(rustdoc::bare_urls)]
+    /// <http://example.org>
+    pub fn baz() {}
+}
+
+mod clippy_ok {
+    //! See <https://rust-lang.github.io/rust-clippy/master/index.html>
+
+    #[expect(clippy::almost_swapped)]
+    fn foo() {
+        let mut a = 0;
+        let mut b = 9;
+        a = b;
+        b = a;
+    }
+
+    #[expect(clippy::bytes_nth)]
+    fn bar() {
+        let _ = "Hello".bytes().nth(3);
+    }
+
+    #[expect(clippy::if_same_then_else)]
+    fn baz() {
+        let _ = if true { 42 } else { 42 };
+    }
+
+    #[expect(clippy::logic_bug)]
+    fn burger() {
+        let a = false;
+        let b = true;
+
+        if a && b || a {}
+    }
+}
+
+mod clippy_warn {
+    //! See <https://rust-lang.github.io/rust-clippy/master/index.html>
+
+    #[expect(clippy::almost_swapped)]
+    fn foo() {
+        let mut a = 0;
+        let mut b = 9;
+        a = b;
+    }
+
+    #[expect(clippy::bytes_nth)]
+    fn bar() {
+        let _ = "Hello".as_bytes().get(3);
+    }
+
+    #[expect(clippy::if_same_then_else)]
+    fn baz() {
+        let _ = if true { 33 } else { 42 };
+    }
+
+    #[expect(clippy::logic_bug)]
+    fn burger() {
+        let a = false;
+        let b = true;
+        let c = false;
+
+        if a && b || c {}
+    }
+}
+
+fn main() {
+    rustc_warn::rustc_lints();
+}
diff --git a/tests/ui/expect_tool_lint_rfc_2383.stderr b/tests/ui/expect_tool_lint_rfc_2383.stderr
new file mode 100644
index 00000000000..db29e85a821
--- /dev/null
+++ b/tests/ui/expect_tool_lint_rfc_2383.stderr
@@ -0,0 +1,40 @@
+error: this lint expectation is unfulfilled
+  --> $DIR/expect_tool_lint_rfc_2383.rs:35:14
+   |
+LL |     #[expect(dead_code)]
+   |              ^^^^^^^^^
+   |
+   = note: `-D unfulfilled-lint-expectations` implied by `-D warnings`
+
+error: this lint expectation is unfulfilled
+  --> $DIR/expect_tool_lint_rfc_2383.rs:39:18
+   |
+LL |         #[expect(illegal_floating_point_literal_pattern)]
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: this lint expectation is unfulfilled
+  --> $DIR/expect_tool_lint_rfc_2383.rs:113:14
+   |
+LL |     #[expect(clippy::almost_swapped)]
+   |              ^^^^^^^^^^^^^^^^^^^^^^
+
+error: this lint expectation is unfulfilled
+  --> $DIR/expect_tool_lint_rfc_2383.rs:120:14
+   |
+LL |     #[expect(clippy::bytes_nth)]
+   |              ^^^^^^^^^^^^^^^^^
+
+error: this lint expectation is unfulfilled
+  --> $DIR/expect_tool_lint_rfc_2383.rs:125:14
+   |
+LL |     #[expect(clippy::if_same_then_else)]
+   |              ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: this lint expectation is unfulfilled
+  --> $DIR/expect_tool_lint_rfc_2383.rs:130:14
+   |
+LL |     #[expect(clippy::logic_bug)]
+   |              ^^^^^^^^^^^^^^^^^
+
+error: aborting due to 6 previous errors
+