mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 11:20:54 +00:00
fix: Fix bind pat inlay hints rendering for constant patterns
This commit is contained in:
parent
7677f41f41
commit
5fdf640fb3
@ -67,28 +67,23 @@ fn should_not_display_type_hint(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(hir::Adt::Struct(s)) = pat_ty.as_adt() {
|
if sema.resolve_bind_pat_to_const(bind_pat).is_some() {
|
||||||
if s.fields(db).is_empty() && s.name(db).to_smol_str() == bind_pat.to_string() {
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.hide_closure_initialization_hints {
|
|
||||||
if let Some(parent) = bind_pat.syntax().parent() {
|
|
||||||
if let Some(it) = ast::LetStmt::cast(parent) {
|
|
||||||
if let Some(ast::Expr::ClosureExpr(closure)) = it.initializer() {
|
|
||||||
if closure_has_block_body(&closure) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for node in bind_pat.syntax().ancestors() {
|
for node in bind_pat.syntax().ancestors() {
|
||||||
match_ast! {
|
match_ast! {
|
||||||
match node {
|
match node {
|
||||||
ast::LetStmt(it) => return it.ty().is_some(),
|
ast::LetStmt(it) => {
|
||||||
|
if config.hide_closure_initialization_hints {
|
||||||
|
if let Some(ast::Expr::ClosureExpr(closure)) = it.initializer() {
|
||||||
|
if closure_has_block_body(&closure) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return it.ty().is_some()
|
||||||
|
},
|
||||||
// FIXME: We might wanna show type hints in parameters for non-top level patterns as well
|
// FIXME: We might wanna show type hints in parameters for non-top level patterns as well
|
||||||
ast::Param(it) => return it.ty().is_some(),
|
ast::Param(it) => return it.ty().is_some(),
|
||||||
ast::MatchArm(_) => return pat_is_enum_variant(db, bind_pat, pat_ty),
|
ast::MatchArm(_) => return pat_is_enum_variant(db, bind_pat, pat_ty),
|
||||||
@ -567,6 +562,21 @@ fn main() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn const_pats_have_no_type_hints() {
|
||||||
|
check_types(
|
||||||
|
r#"
|
||||||
|
const FOO: usize = 0;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
match 0 {
|
||||||
|
FOO => (),
|
||||||
|
_ => ()
|
||||||
|
}
|
||||||
|
}"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn let_statement() {
|
fn let_statement() {
|
||||||
check_types(
|
check_types(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user