diff options
| author | bors <bors@rust-lang.org> | 2023-02-11 15:30:46 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-02-11 15:30:46 +0000 |
| commit | d78a0be9b0a9b46559a65fb59634b6428ccf29ac (patch) | |
| tree | 226bd21fb128f8751e562bb3de419c72504fe4b0 | |
| parent | 8011029d3a0f4014217e1ade75688c0f3c5305db (diff) | |
| parent | 5fdf640fb3cf207531629bff7372fb4caf296e94 (diff) | |
| download | rust-d78a0be9b0a9b46559a65fb59634b6428ccf29ac.tar.gz rust-d78a0be9b0a9b46559a65fb59634b6428ccf29ac.zip | |
Auto merge of #14125 - Veykril:inlay-fix, r=Veykril
fix: Fix bind pat inlay hints rendering for constant patterns Fixes https://github.com/rust-lang/rust-analyzer/issues/14124
| -rw-r--r-- | crates/ide/src/inlay_hints/bind_pat.rs | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/crates/ide/src/inlay_hints/bind_pat.rs b/crates/ide/src/inlay_hints/bind_pat.rs index f5b5c447374..4af7f9bdb73 100644 --- a/crates/ide/src/inlay_hints/bind_pat.rs +++ b/crates/ide/src/inlay_hints/bind_pat.rs @@ -67,28 +67,23 @@ fn should_not_display_type_hint( return true; } - if let Some(hir::Adt::Struct(s)) = pat_ty.as_adt() { - if s.fields(db).is_empty() && s.name(db).to_smol_str() == bind_pat.to_string() { - 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; - } - } - } - } + if sema.resolve_bind_pat_to_const(bind_pat).is_some() { + return true; } for node in bind_pat.syntax().ancestors() { match_ast! { 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 ast::Param(it) => return it.ty().is_some(), ast::MatchArm(_) => return pat_is_enum_variant(db, bind_pat, pat_ty), @@ -568,6 +563,21 @@ fn main() { } #[test] + fn const_pats_have_no_type_hints() { + check_types( + r#" +const FOO: usize = 0; + +fn main() { + match 0 { + FOO => (), + _ => () + } +}"#, + ); + } + + #[test] fn let_statement() { check_types( r#" |
