Skip to content

Commit 4fcad5a

Browse files
committed
Auto merge of rust-lang#18107 - Veykril:push-oopkquknxqxs, r=Veykril
fix: Don't emit empty inlay hint parts
2 parents 8cd0a27 + d1e4f73 commit 4fcad5a

File tree

4 files changed

+24
-38
lines changed

4 files changed

+24
-38
lines changed

src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,14 @@ impl HirWrite for InlayHintLabelBuilder<'_> {
577577

578578
impl InlayHintLabelBuilder<'_> {
579579
fn make_new_part(&mut self) {
580-
self.result.parts.push(InlayHintLabelPart {
581-
text: take(&mut self.last_part),
582-
linked_location: self.location.take(),
583-
tooltip: None,
584-
});
580+
let text = take(&mut self.last_part);
581+
if !text.is_empty() {
582+
self.result.parts.push(InlayHintLabelPart {
583+
text,
584+
linked_location: self.location.take(),
585+
tooltip: None,
586+
});
587+
}
585588
}
586589

587590
fn finish(mut self) -> InlayHintLabel {

src/tools/rust-analyzer/crates/ide/src/inlay_hints/chaining.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ fn main() {
140140
(
141141
147..172,
142142
[
143-
"",
144143
InlayHintLabelPart {
145144
text: "B",
146145
linked_location: Some(
@@ -153,13 +152,11 @@ fn main() {
153152
),
154153
tooltip: "",
155154
},
156-
"",
157155
],
158156
),
159157
(
160158
147..154,
161159
[
162-
"",
163160
InlayHintLabelPart {
164161
text: "A",
165162
linked_location: Some(
@@ -172,7 +169,6 @@ fn main() {
172169
),
173170
tooltip: "",
174171
},
175-
"",
176172
],
177173
),
178174
]
@@ -223,7 +219,6 @@ fn main() {
223219
(
224220
143..190,
225221
[
226-
"",
227222
InlayHintLabelPart {
228223
text: "C",
229224
linked_location: Some(
@@ -236,13 +231,11 @@ fn main() {
236231
),
237232
tooltip: "",
238233
},
239-
"",
240234
],
241235
),
242236
(
243237
143..179,
244238
[
245-
"",
246239
InlayHintLabelPart {
247240
text: "B",
248241
linked_location: Some(
@@ -255,7 +248,6 @@ fn main() {
255248
),
256249
tooltip: "",
257250
},
258-
"",
259251
],
260252
),
261253
]
@@ -290,7 +282,6 @@ fn main() {
290282
(
291283
143..190,
292284
[
293-
"",
294285
InlayHintLabelPart {
295286
text: "C",
296287
linked_location: Some(
@@ -303,13 +294,11 @@ fn main() {
303294
),
304295
tooltip: "",
305296
},
306-
"",
307297
],
308298
),
309299
(
310300
143..179,
311301
[
312-
"",
313302
InlayHintLabelPart {
314303
text: "B",
315304
linked_location: Some(
@@ -322,7 +311,6 @@ fn main() {
322311
),
323312
tooltip: "",
324313
},
325-
"",
326314
],
327315
),
328316
]
@@ -358,7 +346,6 @@ fn main() {
358346
(
359347
246..283,
360348
[
361-
"",
362349
InlayHintLabelPart {
363350
text: "B",
364351
linked_location: Some(
@@ -390,7 +377,6 @@ fn main() {
390377
(
391378
246..265,
392379
[
393-
"",
394380
InlayHintLabelPart {
395381
text: "A",
396382
linked_location: Some(
@@ -563,7 +549,6 @@ fn main() {
563549
),
564550
tooltip: "",
565551
},
566-
"",
567552
],
568553
),
569554
]
@@ -598,7 +583,6 @@ fn main() {
598583
(
599584
124..130,
600585
[
601-
"",
602586
InlayHintLabelPart {
603587
text: "Struct",
604588
linked_location: Some(
@@ -611,13 +595,11 @@ fn main() {
611595
),
612596
tooltip: "",
613597
},
614-
"",
615598
],
616599
),
617600
(
618601
145..185,
619602
[
620-
"",
621603
InlayHintLabelPart {
622604
text: "Struct",
623605
linked_location: Some(
@@ -630,13 +612,11 @@ fn main() {
630612
),
631613
tooltip: "",
632614
},
633-
"",
634615
],
635616
),
636617
(
637618
145..168,
638619
[
639-
"",
640620
InlayHintLabelPart {
641621
text: "Struct",
642622
linked_location: Some(
@@ -649,7 +629,6 @@ fn main() {
649629
),
650630
tooltip: "",
651631
},
652-
"",
653632
],
654633
),
655634
(

src/tools/rust-analyzer/crates/ide/src/inlay_hints/closing_brace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub(super) fn hints(
7878
}
7979
closing_token = block.r_curly_token()?;
8080

81-
let lifetime = label.lifetime().map_or_else(String::new, |it| it.to_string());
81+
let lifetime = label.lifetime()?.to_string();
8282

8383
(lifetime, Some(label.syntax().text_range()))
8484
} else if let Some(block) = ast::BlockExpr::cast(node.clone()) {

src/tools/rust-analyzer/crates/ide/src/inlay_hints/closure_captures.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! Tests live in [`bind_pat`][super::bind_pat] module.
44
use ide_db::famous_defs::FamousDefs;
55
use span::EditionedFileId;
6-
use stdx::TupleExt;
6+
use stdx::{never, TupleExt};
77
use syntax::ast::{self, AstNode};
88
use text_edit::{TextRange, TextSize};
99

@@ -63,17 +63,21 @@ pub(super) fn hints(
6363
// force cache the source file, otherwise sema lookup will potentially panic
6464
_ = sema.parse_or_expand(source.file());
6565

66+
let label = format!(
67+
"{}{}",
68+
match capture.kind() {
69+
hir::CaptureKind::SharedRef => "&",
70+
hir::CaptureKind::UniqueSharedRef => "&unique ",
71+
hir::CaptureKind::MutableRef => "&mut ",
72+
hir::CaptureKind::Move => "",
73+
},
74+
capture.display_place(sema.db)
75+
);
76+
if never!(label.is_empty()) {
77+
continue;
78+
}
6679
let label = InlayHintLabel::simple(
67-
format!(
68-
"{}{}",
69-
match capture.kind() {
70-
hir::CaptureKind::SharedRef => "&",
71-
hir::CaptureKind::UniqueSharedRef => "&unique ",
72-
hir::CaptureKind::MutableRef => "&mut ",
73-
hir::CaptureKind::Move => "",
74-
},
75-
capture.display_place(sema.db)
76-
),
80+
label,
7781
None,
7882
source.name().and_then(|name| {
7983
name.syntax().original_file_range_opt(sema.db).map(TupleExt::head).map(Into::into)

0 commit comments

Comments
 (0)