Skip to content

Commit 671ba41

Browse files
Merge pull request #21927 from A4-Tacks/no-expect-name-nested
fix: Not suggest name in nested type in variant
2 parents 9767050 + 4136f7b commit 671ba41

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

crates/ide-completion/src/context/analysis.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,10 +828,15 @@ fn expected_type_and_name<'db>(
828828
.unwrap_or((None, None))
829829
},
830830
ast::Variant(it) => {
831+
let is_simple_field = |field: ast::TupleField| {
832+
let Some(ty) = field.ty() else { return true };
833+
matches!(ty, ast::Type::PathType(_)) && ty.generic_arg_list().is_none()
834+
};
831835
let is_simple_variant = matches!(
832836
it.field_list(),
833837
Some(ast::FieldList::TupleFieldList(list))
834838
if list.syntax().children_with_tokens().all(|it| it.kind() != T![,])
839+
&& list.fields().next().is_none_or(is_simple_field)
835840
);
836841
(None, it.name().filter(|_| is_simple_variant).map(NameOrNameRef::Name))
837842
},

crates/ide-completion/src/render.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3077,6 +3077,22 @@ enum Foo {
30773077
st String String []
30783078
"#]],
30793079
);
3080+
3081+
check_relevance(
3082+
r#"
3083+
struct Other;
3084+
struct Vec<T>(T);
3085+
enum Foo {
3086+
Vec(Vec<$0>)
3087+
}
3088+
"#,
3089+
expect![[r#"
3090+
en Foo Foo []
3091+
st Other Other []
3092+
sp Self Foo []
3093+
st Vec<…> Vec<{unknown}> []
3094+
"#]],
3095+
);
30803096
}
30813097

30823098
#[test]

0 commit comments

Comments
 (0)