about summary refs log tree commit diff
diff options
context:
space:
mode:
authorShoyu Vanilla (Flint) <modulo641@gmail.com>2025-09-15 05:39:17 +0000
committerGitHub <noreply@github.com>2025-09-15 05:39:17 +0000
commit03e383098bb1b8a73e183e83e052df1adff0f736 (patch)
treefeaae1002755ae73b71a7d3836874d81e2dc46b4
parent4515e789ede7c7002ccf40f7a716d3d1cdaf8be2 (diff)
parent55b8d4e6ffc220db78b928aacc274423631134f7 (diff)
downloadrust-03e383098bb1b8a73e183e83e052df1adff0f736.tar.gz
rust-03e383098bb1b8a73e183e83e052df1adff0f736.zip
Merge pull request #20665 from ChayimFriedman2/error-notable
fix: Don't mark unknown type as implementing every notable trait
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/hover.rs6
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/hover/tests.rs23
2 files changed, 29 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/crates/ide/src/hover.rs b/src/tools/rust-analyzer/crates/ide/src/hover.rs
index 3f52303d74e..03b9b367751 100644
--- a/src/tools/rust-analyzer/crates/ide/src/hover.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/hover.rs
@@ -483,6 +483,12 @@ fn notable_traits<'db>(
     db: &'db RootDatabase,
     ty: &hir::Type<'db>,
 ) -> Vec<(hir::Trait, Vec<(Option<hir::Type<'db>>, hir::Name)>)> {
+    if ty.is_unknown() {
+        // The trait solver returns "yes" to the question whether the error type
+        // impls any trait, and we don't want to show it as having any notable trait.
+        return Vec::new();
+    }
+
     db.notable_traits_in_deps(ty.krate(db).into())
         .iter()
         .flat_map(|it| &**it)
diff --git a/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs b/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs
index 58d8a7edbe0..a88c0c9866e 100644
--- a/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs
@@ -11097,3 +11097,26 @@ impl Enum<'_, Borrowed> {
         "#]],
     );
 }
+
+#[test]
+fn unknown_should_not_implement_notable_traits() {
+    check(
+        r#"
+//- minicore: future, iterator
+fn foo() {
+    let x$0;
+}
+    "#,
+        expect![[r#"
+            *x*
+
+            ```rust
+            let x: {unknown}
+            ```
+
+            ---
+
+            no Drop
+        "#]],
+    );
+}