Skip to content

Commit d78a0be

Browse files
committed
Auto merge of rust-lang#14125 - Veykril:inlay-fix, r=Veykril
fix: Fix bind pat inlay hints rendering for constant patterns Fixes rust-lang/rust-analyzer#14124
2 parents 8011029 + 5fdf640 commit d78a0be

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

crates/ide/src/inlay_hints/bind_pat.rs

+27-17
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,23 @@ fn should_not_display_type_hint(
6767
return true;
6868
}
6969

70-
if let Some(hir::Adt::Struct(s)) = pat_ty.as_adt() {
71-
if s.fields(db).is_empty() && s.name(db).to_smol_str() == bind_pat.to_string() {
72-
return true;
73-
}
74-
}
75-
76-
if config.hide_closure_initialization_hints {
77-
if let Some(parent) = bind_pat.syntax().parent() {
78-
if let Some(it) = ast::LetStmt::cast(parent) {
79-
if let Some(ast::Expr::ClosureExpr(closure)) = it.initializer() {
80-
if closure_has_block_body(&closure) {
81-
return true;
82-
}
83-
}
84-
}
85-
}
70+
if sema.resolve_bind_pat_to_const(bind_pat).is_some() {
71+
return true;
8672
}
8773

8874
for node in bind_pat.syntax().ancestors() {
8975
match_ast! {
9076
match node {
91-
ast::LetStmt(it) => return it.ty().is_some(),
77+
ast::LetStmt(it) => {
78+
if config.hide_closure_initialization_hints {
79+
if let Some(ast::Expr::ClosureExpr(closure)) = it.initializer() {
80+
if closure_has_block_body(&closure) {
81+
return true;
82+
}
83+
}
84+
}
85+
return it.ty().is_some()
86+
},
9287
// FIXME: We might wanna show type hints in parameters for non-top level patterns as well
9388
ast::Param(it) => return it.ty().is_some(),
9489
ast::MatchArm(_) => return pat_is_enum_variant(db, bind_pat, pat_ty),
@@ -567,6 +562,21 @@ fn main() {
567562
);
568563
}
569564

565+
#[test]
566+
fn const_pats_have_no_type_hints() {
567+
check_types(
568+
r#"
569+
const FOO: usize = 0;
570+
571+
fn main() {
572+
match 0 {
573+
FOO => (),
574+
_ => ()
575+
}
576+
}"#,
577+
);
578+
}
579+
570580
#[test]
571581
fn let_statement() {
572582
check_types(

0 commit comments

Comments
 (0)