diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2025-03-24 07:00:54 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-24 07:00:54 +0000 |
| commit | 06fdb96a8b6b8a3a0287d314b61c91ec63ebd9da (patch) | |
| tree | 8ad90dcb5e23e6aa3abea4016f4b8b60c3080de7 /src | |
| parent | 19ac6ce67a5dbca3dc39ef5367d56a9edd4751d9 (diff) | |
| parent | a41c4dcddd2dfb0b3feae037487af9f8dba10059 (diff) | |
| download | rust-06fdb96a8b6b8a3a0287d314b61c91ec63ebd9da.tar.gz rust-06fdb96a8b6b8a3a0287d314b61c91ec63ebd9da.zip | |
Merge pull request #19435 from Veykril/push-owstqqlrtsko
fix: Fix closure return inlayhints using macro ranges
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide/src/inlay_hints/closure_ret.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/closure_ret.rs b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/closure_ret.rs index 0014c8127de..f9b21c672dc 100644 --- a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/closure_ret.rs +++ b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/closure_ret.rs @@ -35,8 +35,9 @@ pub(super) fn hints( let param_list = closure.param_list()?; - let closure = sema.descend_node_into_attributes(closure).pop()?; - let ty = sema.type_of_expr(&ast::Expr::ClosureExpr(closure.clone()))?.adjusted(); + let resolve_parent = Some(closure.syntax().text_range()); + let descended_closure = sema.descend_node_into_attributes(closure.clone()).pop()?; + let ty = sema.type_of_expr(&ast::Expr::ClosureExpr(descended_closure.clone()))?.adjusted(); let callable = ty.as_callable(sema.db)?; let ty = callable.return_type(); if arrow.is_none() && ty.is_unit() { @@ -52,7 +53,7 @@ pub(super) fn hints( ty_to_text_edit( sema, config, - closure.syntax(), + descended_closure.syntax(), &ty, arrow .as_ref() @@ -70,7 +71,7 @@ pub(super) fn hints( let mut builder = TextEdit::builder(); let insert_pos = param_list.syntax().text_range().end(); - let rendered = match sema.scope(closure.syntax()).and_then(|scope| { + let rendered = match sema.scope(descended_closure.syntax()).and_then(|scope| { ty.display_source_code(scope.db, scope.module().into(), false).ok() }) { Some(rendered) => rendered, @@ -95,7 +96,7 @@ pub(super) fn hints( position: InlayHintPosition::After, pad_left: false, pad_right: false, - resolve_parent: Some(closure.syntax().text_range()), + resolve_parent, }); Some(()) } |
