mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-03 16:58:46 +00:00
Auto merge of #12199 - jonas-schievink:no-invalid-assoc-ty-completions, r=jonas-schievink
fix: Don't show assoc. type binding completions when invalid Fixes https://github.com/rust-lang/rust-analyzer/issues/12165
This commit is contained in:
commit
ad6df5b12e
2 changed files with 43 additions and 9 deletions
|
@ -165,15 +165,17 @@ pub(crate) fn complete_type_path(acc: &mut Completions, ctx: &CompletionContext)
|
||||||
if let Some(ImmediateLocation::GenericArgList(arg_list)) = &ctx.completion_location {
|
if let Some(ImmediateLocation::GenericArgList(arg_list)) = &ctx.completion_location {
|
||||||
if let Some(path_seg) = arg_list.syntax().parent().and_then(ast::PathSegment::cast)
|
if let Some(path_seg) = arg_list.syntax().parent().and_then(ast::PathSegment::cast)
|
||||||
{
|
{
|
||||||
if let Some(hir::PathResolution::Def(hir::ModuleDef::Trait(trait_))) =
|
if path_seg.syntax().ancestors().find_map(ast::TypeBound::cast).is_some() {
|
||||||
ctx.sema.resolve_path(&path_seg.parent_path())
|
if let Some(hir::PathResolution::Def(hir::ModuleDef::Trait(trait_))) =
|
||||||
{
|
ctx.sema.resolve_path(&path_seg.parent_path())
|
||||||
trait_.items_with_supertraits(ctx.sema.db).into_iter().for_each(|it| {
|
{
|
||||||
if let hir::AssocItem::TypeAlias(alias) = it {
|
trait_.items_with_supertraits(ctx.sema.db).into_iter().for_each(|it| {
|
||||||
cov_mark::hit!(complete_assoc_type_in_generics_list);
|
if let hir::AssocItem::TypeAlias(alias) = it {
|
||||||
acc.add_type_alias_with_eq(ctx, alias)
|
cov_mark::hit!(complete_assoc_type_in_generics_list);
|
||||||
}
|
acc.add_type_alias_with_eq(ctx, alias)
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -393,6 +393,38 @@ fn foo<'lt, T: Trait2<self::$0>, const CONST_PARAM: usize>(_: T) {}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_assoc_completion_outside_type_bounds() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
struct S;
|
||||||
|
trait Tr<T> {
|
||||||
|
type Ty;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Tr<$0
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
ct CONST
|
||||||
|
en Enum
|
||||||
|
ma makro!(…) macro_rules! makro
|
||||||
|
md module
|
||||||
|
sp Self
|
||||||
|
st Record
|
||||||
|
st S
|
||||||
|
st Tuple
|
||||||
|
st Unit
|
||||||
|
tt Tr
|
||||||
|
tt Trait
|
||||||
|
un Union
|
||||||
|
bt u32
|
||||||
|
kw crate::
|
||||||
|
kw self::
|
||||||
|
kw super::
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn enum_qualified() {
|
fn enum_qualified() {
|
||||||
check(
|
check(
|
||||||
|
|
Loading…
Reference in a new issue