Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 466b4ec

Browse files
committed
Auto merge of rust-lang#14714 - jhgg:hover/exclude-sized-trait-in-goto-actions, r=Veykril
fix: ide: exclude sized in go-to actions in hover fixes rust-lang#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.
2 parents 7d48bba + 3132a9e commit 466b4ec

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

crates/hir/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use hir_def::{
4444
generics::{LifetimeParamData, TypeOrConstParamData, TypeParamProvenance},
4545
hir::{BindingAnnotation, BindingId, ExprOrPatId, LabelId, Pat},
4646
item_tree::ItemTreeNode,
47-
lang_item::{LangItem, LangItemTarget},
47+
lang_item::LangItemTarget,
4848
layout::ReprOptions,
4949
macro_id_to_def_id,
5050
nameres::{self, diagnostics::DefDiagnostic, ModuleOrigin},
@@ -114,6 +114,7 @@ pub use {
114114
data::adt::StructKind,
115115
find_path::PrefixKind,
116116
import_map,
117+
lang_item::LangItem,
117118
nameres::ModuleSource,
118119
path::{ModPath, PathKind},
119120
type_ref::{Mutability, TypeRef},

crates/ide/src/hover.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod tests;
66
use std::iter;
77

88
use either::Either;
9-
use hir::{HasSource, Semantics};
9+
use hir::{db::DefDatabase, HasSource, LangItem, Semantics};
1010
use ide_db::{
1111
base_db::FileRange,
1212
defs::{Definition, IdentClass, OperatorClass},
@@ -353,7 +353,14 @@ fn goto_type_action_for_def(db: &RootDatabase, def: Definition) -> Option<HoverA
353353
};
354354

355355
if let Definition::GenericParam(hir::GenericParam::TypeParam(it)) = def {
356-
it.trait_bounds(db).into_iter().for_each(|it| push_new_def(it.into()));
356+
let krate = it.module(db).krate();
357+
let sized_trait =
358+
db.lang_item(krate.into(), LangItem::Sized).and_then(|lang_item| lang_item.as_trait());
359+
360+
it.trait_bounds(db)
361+
.into_iter()
362+
.filter(|&it| Some(it.into()) != sized_trait)
363+
.for_each(|it| push_new_def(it.into()));
357364
} else {
358365
let ty = match def {
359366
Definition::Local(it) => it.ty(db),

crates/ide/src/hover/tests.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,6 +2098,19 @@ fn main() { let s$0t = S{ f1:Arg(0) }; }
20982098
);
20992099
}
21002100

2101+
#[test]
2102+
fn test_hover_generic_excludes_sized_go_to_action() {
2103+
check_actions(
2104+
r#"
2105+
//- minicore: sized
2106+
struct S<T$0>(T);
2107+
"#,
2108+
expect![[r#"
2109+
[]
2110+
"#]],
2111+
);
2112+
}
2113+
21012114
#[test]
21022115
fn test_hover_generic_struct_has_flattened_goto_type_actions() {
21032116
check_actions(

0 commit comments

Comments
 (0)