mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Auto merge of #14742 - Veykril:closure-capture-inlays, r=Veykril
feat: Closure capture inlay hints I opted for a fictional `move(foo, &bar, &mut qux)` syntax here, disabled by default as these are not correct rust syntax and hence could cause confusion. 
This commit is contained in:
commit
d3ce333ec8
11 changed files with 278 additions and 37 deletions
|
@ -3,7 +3,8 @@ use std::fmt::Display;
|
|||
|
||||
use either::Either;
|
||||
use hir::{
|
||||
Adt, AsAssocItem, AttributeTemplate, HasAttrs, HasSource, HirDisplay, Semantics, TypeInfo,
|
||||
Adt, AsAssocItem, AttributeTemplate, CaptureKind, HasAttrs, HasSource, HirDisplay, Semantics,
|
||||
TypeInfo,
|
||||
};
|
||||
use ide_db::{
|
||||
base_db::SourceDatabase,
|
||||
|
@ -58,8 +59,14 @@ pub(super) fn closure_expr(
|
|||
let mut captures = c
|
||||
.captured_items(sema.db)
|
||||
.into_iter()
|
||||
.map(|x| {
|
||||
format!("* `{}` by {}", x.display_place(c.clone().into(), sema.db), x.display_kind())
|
||||
.map(|it| {
|
||||
let borrow_kind= match it.kind() {
|
||||
CaptureKind::SharedRef => "immutable borrow",
|
||||
CaptureKind::UniqueSharedRef => "unique immutable borrow ([read more](https://doc.rust-lang.org/stable/reference/types/closure.html#unique-immutable-borrows-in-captures))",
|
||||
CaptureKind::MutableRef => "mutable borrow",
|
||||
CaptureKind::Move => "move",
|
||||
};
|
||||
format!("* `{}` by {}", it.display_place(sema.db), borrow_kind)
|
||||
})
|
||||
.join("\n");
|
||||
if captures.trim().is_empty() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue