Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #14714 - jhgg:hover/exclude-sized-trait-in-goto-actions, r=Veykril
fix: ide: exclude sized in go-to actions in hover fixes #13163 i opted to just simply omit `Sized` entirely from go-to actions, as opposed to including it if even someone writes an explicit `T: Sized`, as i think a go-to on Sized is of dubious value practically.
bors 2023-05-02
parent 7d48bba · parent 3132a9e · commit 466b4ec
-rw-r--r--crates/hir/src/lib.rs3
-rw-r--r--crates/ide/src/hover.rs11
-rw-r--r--crates/ide/src/hover/tests.rs13
3 files changed, 24 insertions, 3 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index f955b74d0e..c38dbfd0e7 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -44,7 +44,7 @@ use hir_def::{
generics::{LifetimeParamData, TypeOrConstParamData, TypeParamProvenance},
hir::{BindingAnnotation, BindingId, ExprOrPatId, LabelId, Pat},
item_tree::ItemTreeNode,
- lang_item::{LangItem, LangItemTarget},
+ lang_item::LangItemTarget,
layout::ReprOptions,
macro_id_to_def_id,
nameres::{self, diagnostics::DefDiagnostic, ModuleOrigin},
@@ -114,6 +114,7 @@ pub use {
data::adt::StructKind,
find_path::PrefixKind,
import_map,
+ lang_item::LangItem,
nameres::ModuleSource,
path::{ModPath, PathKind},
type_ref::{Mutability, TypeRef},
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs
index 8e0aa9df14..c47f85b7bf 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -6,7 +6,7 @@ mod tests;
use std::iter;
use either::Either;
-use hir::{HasSource, Semantics};
+use hir::{db::DefDatabase, HasSource, LangItem, Semantics};
use ide_db::{
base_db::FileRange,
defs::{Definition, IdentClass, OperatorClass},
@@ -353,7 +353,14 @@ fn goto_type_action_for_def(db: &RootDatabase, def: Definition) -> Option<HoverA
};
if let Definition::GenericParam(hir::GenericParam::TypeParam(it)) = def {
- it.trait_bounds(db).into_iter().for_each(|it| push_new_def(it.into()));
+ let krate = it.module(db).krate();
+ let sized_trait =
+ db.lang_item(krate.into(), LangItem::Sized).and_then(|lang_item| lang_item.as_trait());
+
+ it.trait_bounds(db)
+ .into_iter()
+ .filter(|&it| Some(it.into()) != sized_trait)
+ .for_each(|it| push_new_def(it.into()));
} else {
let ty = match def {
Definition::Local(it) => it.ty(db),
diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs
index 082e5372d4..64df511e46 100644
--- a/crates/ide/src/hover/tests.rs
+++ b/crates/ide/src/hover/tests.rs
@@ -2099,6 +2099,19 @@ fn main() { let s$0t = S{ f1:Arg(0) }; }
}
#[test]
+fn test_hover_generic_excludes_sized_go_to_action() {
+ check_actions(
+ r#"
+//- minicore: sized
+struct S<T$0>(T);
+ "#,
+ expect![[r#"
+ []
+ "#]],
+ );
+}
+
+#[test]
fn test_hover_generic_struct_has_flattened_goto_type_actions() {
check_actions(
r#"