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.
This commit is contained in:
bors 2023-05-02 08:30:17 +00:00
commit 466b4ec547
3 changed files with 24 additions and 3 deletions

View File

@ -44,7 +44,7 @@
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 @@
data::adt::StructKind,
find_path::PrefixKind,
import_map,
lang_item::LangItem,
nameres::ModuleSource,
path::{ModPath, PathKind},
type_ref::{Mutability, TypeRef},

View File

@ -6,7 +6,7 @@
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),

View File

@ -2098,6 +2098,19 @@ struct S<T>{ f1: T }
);
}
#[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(