Skip to content

Commit da1888a

Browse files
authored
Merge pull request #20031 from jnyfah/some-branch
Fix: Resolve HIR display length issues and improve adjustment tooltips
2 parents 37a7734 + a7619a3 commit da1888a

File tree

2 files changed

+75
-35
lines changed

2 files changed

+75
-35
lines changed

crates/ide/src/inlay_hints/adjustment.rs

Lines changed: 75 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -109,50 +109,90 @@ pub(super) fn hints(
109109
}
110110
has_adjustments = true;
111111

112-
// FIXME: Add some nicer tooltips to each of these
113-
let (text, coercion) = match kind {
112+
let (text, coercion, detailed_tooltip) = match kind {
114113
Adjust::NeverToAny if config.adjustment_hints == AdjustmentHints::Always => {
115114
allow_edit = false;
116-
("<never-to-any>", "never to any")
117-
}
118-
Adjust::Deref(None) => ("*", "dereference"),
119-
Adjust::Deref(Some(OverloadedDeref(Mutability::Shared))) => {
120-
("*", "`Deref` dereference")
121-
}
122-
Adjust::Deref(Some(OverloadedDeref(Mutability::Mut))) => {
123-
("*", "`DerefMut` dereference")
124-
}
125-
Adjust::Borrow(AutoBorrow::Ref(Mutability::Shared)) => ("&", "borrow"),
126-
Adjust::Borrow(AutoBorrow::Ref(Mutability::Mut)) => ("&mut ", "unique borrow"),
127-
Adjust::Borrow(AutoBorrow::RawPtr(Mutability::Shared)) => {
128-
("&raw const ", "const pointer borrow")
129-
}
130-
Adjust::Borrow(AutoBorrow::RawPtr(Mutability::Mut)) => {
131-
("&raw mut ", "mut pointer borrow")
115+
(
116+
"<never-to-any>",
117+
"never to any",
118+
"Coerces the never type `!` into any other type. This happens in code paths that never return, like after `panic!()` or `return`.",
119+
)
132120
}
121+
Adjust::Deref(None) => (
122+
"*",
123+
"dereference",
124+
"Built-in dereference of a reference to access the underlying value. The compiler inserts `*` to get the value from `&T`.",
125+
),
126+
Adjust::Deref(Some(OverloadedDeref(Mutability::Shared))) => (
127+
"*",
128+
"`Deref` dereference",
129+
"Dereference via the `Deref` trait. Used for types like `Box<T>` or `Rc<T>` so they act like plain `T`.",
130+
),
131+
Adjust::Deref(Some(OverloadedDeref(Mutability::Mut))) => (
132+
"*",
133+
"`DerefMut` dereference",
134+
"Mutable dereference using the `DerefMut` trait. Enables smart pointers to give mutable access to their inner values.",
135+
),
136+
Adjust::Borrow(AutoBorrow::Ref(Mutability::Shared)) => (
137+
"&",
138+
"shared borrow",
139+
"Inserts `&` to create a shared reference. Lets you use a value without moving or cloning it.",
140+
),
141+
Adjust::Borrow(AutoBorrow::Ref(Mutability::Mut)) => (
142+
"&mut ",
143+
"mutable borrow",
144+
"Inserts `&mut` to create a unique, mutable reference. Lets you modify a value without taking ownership.",
145+
),
146+
Adjust::Borrow(AutoBorrow::RawPtr(Mutability::Shared)) => (
147+
"&raw const ",
148+
"const raw pointer",
149+
"Converts a reference to a raw const pointer `*const T`. Often used when working with FFI or unsafe code.",
150+
),
151+
Adjust::Borrow(AutoBorrow::RawPtr(Mutability::Mut)) => (
152+
"&raw mut ",
153+
"mut raw pointer",
154+
"Converts a mutable reference to a raw mutable pointer `*mut T`. Allows mutation in unsafe contexts.",
155+
),
133156
// some of these could be represented via `as` casts, but that's not too nice and
134157
// handling everything as a prefix expr makes the `(` and `)` insertion easier
135158
Adjust::Pointer(cast) if config.adjustment_hints == AdjustmentHints::Always => {
136159
allow_edit = false;
137160
match cast {
138-
PointerCast::ReifyFnPointer => {
139-
("<fn-item-to-fn-pointer>", "fn item to fn pointer")
140-
}
161+
PointerCast::ReifyFnPointer => (
162+
"<fn-item-to-fn-pointer>",
163+
"fn item to fn pointer",
164+
"Converts a named function to a function pointer `fn()`. Useful when passing functions as values.",
165+
),
141166
PointerCast::UnsafeFnPointer => (
142167
"<safe-fn-pointer-to-unsafe-fn-pointer>",
143168
"safe fn pointer to unsafe fn pointer",
169+
"Coerces a safe function pointer to an unsafe one. Allows calling it in an unsafe context.",
170+
),
171+
PointerCast::ClosureFnPointer(Safety::Unsafe) => (
172+
"<closure-to-unsafe-fn-pointer>",
173+
"closure to unsafe fn pointer",
174+
"Converts a non-capturing closure to an unsafe function pointer. Required for use in `extern` or unsafe APIs.",
175+
),
176+
PointerCast::ClosureFnPointer(Safety::Safe) => (
177+
"<closure-to-fn-pointer>",
178+
"closure to fn pointer",
179+
"Converts a non-capturing closure to a function pointer. Lets closures behave like plain functions.",
180+
),
181+
PointerCast::MutToConstPointer => (
182+
"<mut-ptr-to-const-ptr>",
183+
"mut ptr to const ptr",
184+
"Coerces `*mut T` to `*const T`. Safe because const pointers restrict what you can do.",
185+
),
186+
PointerCast::ArrayToPointer => (
187+
"<array-ptr-to-element-ptr>",
188+
"array to pointer",
189+
"Converts an array to a pointer to its first element. Similar to how arrays decay to pointers in C.",
190+
),
191+
PointerCast::Unsize => (
192+
"<unsize>",
193+
"unsize coercion",
194+
"Converts a sized type to an unsized one. Used for things like turning arrays into slices or concrete types into trait objects.",
144195
),
145-
PointerCast::ClosureFnPointer(Safety::Unsafe) => {
146-
("<closure-to-unsafe-fn-pointer>", "closure to unsafe fn pointer")
147-
}
148-
PointerCast::ClosureFnPointer(Safety::Safe) => {
149-
("<closure-to-fn-pointer>", "closure to fn pointer")
150-
}
151-
PointerCast::MutToConstPointer => {
152-
("<mut-ptr-to-const-ptr>", "mut ptr to const ptr")
153-
}
154-
PointerCast::ArrayToPointer => ("<array-ptr-to-element-ptr>", ""),
155-
PointerCast::Unsize => ("<unsize>", "unsize"),
156196
}
157197
}
158198
_ => continue,
@@ -162,9 +202,11 @@ pub(super) fn hints(
162202
linked_location: None,
163203
tooltip: Some(config.lazy_tooltip(|| {
164204
InlayTooltip::Markdown(format!(
165-
"`{}` → `{}` ({coercion} coercion)",
205+
"`{}` → `{}`\n\n**{}**\n\n{}",
166206
source.display(sema.db, display_target),
167207
target.display(sema.db, display_target),
208+
coercion,
209+
detailed_tooltip
168210
))
169211
})),
170212
};

crates/ide/src/inlay_hints/closing_brace.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ pub(super) fn hints(
9191
match_ast! {
9292
match parent {
9393
ast::Fn(it) => {
94-
// FIXME: this could include parameters, but `HirDisplay` prints too much info
95-
// and doesn't respect the max length either, so the hints end up way too long
9694
(format!("fn {}", it.name()?), it.name().map(name))
9795
},
9896
ast::Static(it) => (format!("static {}", it.name()?), it.name().map(name)),

0 commit comments

Comments
 (0)