about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-09-12 06:49:21 +0000
committerbors <bors@rust-lang.org>2024-09-12 06:49:21 +0000
commit4fcad5a1ffecd6f1fd9bd92946ca8a08b8c41311 (patch)
tree8dcd372f284fd2b5be000569ae43b92cee754392
parent8cd0a277b69778157d56a6238d8c34799c2cd64b (diff)
parentd1e4f734d12bc2da674e7317e54227c18fdb7f72 (diff)
downloadrust-4fcad5a1ffecd6f1fd9bd92946ca8a08b8c41311.tar.gz
rust-4fcad5a1ffecd6f1fd9bd92946ca8a08b8c41311.zip
Auto merge of #18107 - Veykril:push-oopkquknxqxs, r=Veykril
fix: Don't emit empty inlay hint parts
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs13
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/inlay_hints/chaining.rs21
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/inlay_hints/closing_brace.rs2
-rw-r--r--src/tools/rust-analyzer/crates/ide/src/inlay_hints/closure_captures.rs26
4 files changed, 24 insertions, 38 deletions
diff --git a/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs b/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs
index 2e49af49145..97e712356b5 100644
--- a/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/inlay_hints.rs
@@ -577,11 +577,14 @@ impl HirWrite for InlayHintLabelBuilder<'_> {
 
 impl InlayHintLabelBuilder<'_> {
     fn make_new_part(&mut self) {
-        self.result.parts.push(InlayHintLabelPart {
-            text: take(&mut self.last_part),
-            linked_location: self.location.take(),
-            tooltip: None,
-        });
+        let text = take(&mut self.last_part);
+        if !text.is_empty() {
+            self.result.parts.push(InlayHintLabelPart {
+                text,
+                linked_location: self.location.take(),
+                tooltip: None,
+            });
+        }
     }
 
     fn finish(mut self) -> InlayHintLabel {
diff --git a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/chaining.rs b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/chaining.rs
index df34e4aa245..58d8f97a8ce 100644
--- a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/chaining.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/chaining.rs
@@ -140,7 +140,6 @@ fn main() {
                     (
                         147..172,
                         [
-                            "",
                             InlayHintLabelPart {
                                 text: "B",
                                 linked_location: Some(
@@ -153,13 +152,11 @@ fn main() {
                                 ),
                                 tooltip: "",
                             },
-                            "",
                         ],
                     ),
                     (
                         147..154,
                         [
-                            "",
                             InlayHintLabelPart {
                                 text: "A",
                                 linked_location: Some(
@@ -172,7 +169,6 @@ fn main() {
                                 ),
                                 tooltip: "",
                             },
-                            "",
                         ],
                     ),
                 ]
@@ -223,7 +219,6 @@ fn main() {
                     (
                         143..190,
                         [
-                            "",
                             InlayHintLabelPart {
                                 text: "C",
                                 linked_location: Some(
@@ -236,13 +231,11 @@ fn main() {
                                 ),
                                 tooltip: "",
                             },
-                            "",
                         ],
                     ),
                     (
                         143..179,
                         [
-                            "",
                             InlayHintLabelPart {
                                 text: "B",
                                 linked_location: Some(
@@ -255,7 +248,6 @@ fn main() {
                                 ),
                                 tooltip: "",
                             },
-                            "",
                         ],
                     ),
                 ]
@@ -290,7 +282,6 @@ fn main() {
                     (
                         143..190,
                         [
-                            "",
                             InlayHintLabelPart {
                                 text: "C",
                                 linked_location: Some(
@@ -303,13 +294,11 @@ fn main() {
                                 ),
                                 tooltip: "",
                             },
-                            "",
                         ],
                     ),
                     (
                         143..179,
                         [
-                            "",
                             InlayHintLabelPart {
                                 text: "B",
                                 linked_location: Some(
@@ -322,7 +311,6 @@ fn main() {
                                 ),
                                 tooltip: "",
                             },
-                            "",
                         ],
                     ),
                 ]
@@ -358,7 +346,6 @@ fn main() {
                     (
                         246..283,
                         [
-                            "",
                             InlayHintLabelPart {
                                 text: "B",
                                 linked_location: Some(
@@ -390,7 +377,6 @@ fn main() {
                     (
                         246..265,
                         [
-                            "",
                             InlayHintLabelPart {
                                 text: "A",
                                 linked_location: Some(
@@ -563,7 +549,6 @@ fn main() {
                                 ),
                                 tooltip: "",
                             },
-                            "",
                         ],
                     ),
                 ]
@@ -598,7 +583,6 @@ fn main() {
                     (
                         124..130,
                         [
-                            "",
                             InlayHintLabelPart {
                                 text: "Struct",
                                 linked_location: Some(
@@ -611,13 +595,11 @@ fn main() {
                                 ),
                                 tooltip: "",
                             },
-                            "",
                         ],
                     ),
                     (
                         145..185,
                         [
-                            "",
                             InlayHintLabelPart {
                                 text: "Struct",
                                 linked_location: Some(
@@ -630,13 +612,11 @@ fn main() {
                                 ),
                                 tooltip: "",
                             },
-                            "",
                         ],
                     ),
                     (
                         145..168,
                         [
-                            "",
                             InlayHintLabelPart {
                                 text: "Struct",
                                 linked_location: Some(
@@ -649,7 +629,6 @@ fn main() {
                                 ),
                                 tooltip: "",
                             },
-                            "",
                         ],
                     ),
                     (
diff --git a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/closing_brace.rs b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/closing_brace.rs
index 8af5bd5661a..90b8be64a46 100644
--- a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/closing_brace.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/closing_brace.rs
@@ -78,7 +78,7 @@ pub(super) fn hints(
         }
         closing_token = block.r_curly_token()?;
 
-        let lifetime = label.lifetime().map_or_else(String::new, |it| it.to_string());
+        let lifetime = label.lifetime()?.to_string();
 
         (lifetime, Some(label.syntax().text_range()))
     } else if let Some(block) = ast::BlockExpr::cast(node.clone()) {
diff --git a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/closure_captures.rs b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/closure_captures.rs
index adf7cbc3656..f399bd01d07 100644
--- a/src/tools/rust-analyzer/crates/ide/src/inlay_hints/closure_captures.rs
+++ b/src/tools/rust-analyzer/crates/ide/src/inlay_hints/closure_captures.rs
@@ -3,7 +3,7 @@
 //! Tests live in [`bind_pat`][super::bind_pat] module.
 use ide_db::famous_defs::FamousDefs;
 use span::EditionedFileId;
-use stdx::TupleExt;
+use stdx::{never, TupleExt};
 use syntax::ast::{self, AstNode};
 use text_edit::{TextRange, TextSize};
 
@@ -63,17 +63,21 @@ pub(super) fn hints(
         // force cache the source file, otherwise sema lookup will potentially panic
         _ = sema.parse_or_expand(source.file());
 
+        let label = format!(
+            "{}{}",
+            match capture.kind() {
+                hir::CaptureKind::SharedRef => "&",
+                hir::CaptureKind::UniqueSharedRef => "&unique ",
+                hir::CaptureKind::MutableRef => "&mut ",
+                hir::CaptureKind::Move => "",
+            },
+            capture.display_place(sema.db)
+        );
+        if never!(label.is_empty()) {
+            continue;
+        }
         let label = InlayHintLabel::simple(
-            format!(
-                "{}{}",
-                match capture.kind() {
-                    hir::CaptureKind::SharedRef => "&",
-                    hir::CaptureKind::UniqueSharedRef => "&unique ",
-                    hir::CaptureKind::MutableRef => "&mut ",
-                    hir::CaptureKind::Move => "",
-                },
-                capture.display_place(sema.db)
-            ),
+            label,
             None,
             source.name().and_then(|name| {
                 name.syntax().original_file_range_opt(sema.db).map(TupleExt::head).map(Into::into)