about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2023-11-14 18:53:17 +0100
committerLukas Wirth <lukastw97@gmail.com>2023-11-14 18:53:48 +0100
commitd5faad1dae0b5c43b19efbfba7a268f1800b56e4 (patch)
tree0c007f00d8c25198065fa2f63f1fc1290b7a59b7
parent6ddccc9a6e81ebd3350568575051ac795184fa81 (diff)
downloadrust-d5faad1dae0b5c43b19efbfba7a268f1800b56e4.tar.gz
rust-d5faad1dae0b5c43b19efbfba7a268f1800b56e4.zip
Fix inlay-hint tests being invalidated by minicore chanes
-rw-r--r--crates/hir/src/lib.rs4
-rw-r--r--crates/ide/src/inlay_hints.rs17
-rw-r--r--crates/ide/src/inlay_hints/chaining.rs20
3 files changed, 32 insertions, 9 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index dfb0779f102..8d82e88da9d 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -3403,6 +3403,10 @@ impl Impl {
         db.impl_data(self.id).is_negative
     }
 
+    pub fn is_unsafe(self, db: &dyn HirDatabase) -> bool {
+        db.impl_data(self.id).is_unique()
+    }
+
     pub fn module(self, db: &dyn HirDatabase) -> Module {
         self.id.lookup(db.upcast()).container.into()
     }
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs
index a5d070fe767..24f44ca06ff 100644
--- a/crates/ide/src/inlay_hints.rs
+++ b/crates/ide/src/inlay_hints.rs
@@ -563,6 +563,7 @@ mod tests {
     use hir::ClosureStyle;
     use itertools::Itertools;
     use test_utils::extract_annotations;
+    use text_edit::{TextRange, TextSize};
 
     use crate::inlay_hints::{AdjustmentHints, AdjustmentHintsMode};
     use crate::DiscriminantHints;
@@ -629,6 +630,22 @@ mod tests {
         expect.assert_debug_eq(&inlay_hints)
     }
 
+    #[track_caller]
+    pub(super) fn check_expect_clear_loc(
+        config: InlayHintsConfig,
+        ra_fixture: &str,
+        expect: Expect,
+    ) {
+        let (analysis, file_id) = fixture::file(ra_fixture);
+        let mut inlay_hints = analysis.inlay_hints(&config, file_id, None).unwrap();
+        inlay_hints.iter_mut().flat_map(|hint| &mut hint.label.parts).for_each(|hint| {
+            if let Some(loc) = &mut hint.linked_location {
+                loc.range = TextRange::empty(TextSize::from(0));
+            }
+        });
+        expect.assert_debug_eq(&inlay_hints)
+    }
+
     /// Computes inlay hints for the fixture, applies all the provided text edits and then runs
     /// expect test.
     #[track_caller]
diff --git a/crates/ide/src/inlay_hints/chaining.rs b/crates/ide/src/inlay_hints/chaining.rs
index 4152e606755..c9e9a223786 100644
--- a/crates/ide/src/inlay_hints/chaining.rs
+++ b/crates/ide/src/inlay_hints/chaining.rs
@@ -78,7 +78,9 @@ mod tests {
     use expect_test::expect;
 
     use crate::{
-        inlay_hints::tests::{check_expect, check_with_config, DISABLED_CONFIG, TEST_CONFIG},
+        inlay_hints::tests::{
+            check_expect, check_expect_clear_loc, check_with_config, DISABLED_CONFIG, TEST_CONFIG,
+        },
         InlayHintsConfig,
     };
 
@@ -444,7 +446,7 @@ fn main() {
 
     #[test]
     fn shorten_iterator_chaining_hints() {
-        check_expect(
+        check_expect_clear_loc(
             InlayHintsConfig { chaining_hints: true, ..DISABLED_CONFIG },
             r#"
 //- minicore: iterators
@@ -484,7 +486,7 @@ fn main() {
                                         file_id: FileId(
                                             1,
                                         ),
-                                        range: 10752..10760,
+                                        range: 0..0,
                                     },
                                 ),
                                 tooltip: "",
@@ -497,7 +499,7 @@ fn main() {
                                         file_id: FileId(
                                             1,
                                         ),
-                                        range: 10784..10788,
+                                        range: 0..0,
                                     },
                                 ),
                                 tooltip: "",
@@ -522,7 +524,7 @@ fn main() {
                                         file_id: FileId(
                                             1,
                                         ),
-                                        range: 10752..10760,
+                                        range: 0..0,
                                     },
                                 ),
                                 tooltip: "",
@@ -535,7 +537,7 @@ fn main() {
                                         file_id: FileId(
                                             1,
                                         ),
-                                        range: 10784..10788,
+                                        range: 0..0,
                                     },
                                 ),
                                 tooltip: "",
@@ -560,7 +562,7 @@ fn main() {
                                         file_id: FileId(
                                             1,
                                         ),
-                                        range: 10752..10760,
+                                        range: 0..0,
                                     },
                                 ),
                                 tooltip: "",
@@ -573,7 +575,7 @@ fn main() {
                                         file_id: FileId(
                                             1,
                                         ),
-                                        range: 10784..10788,
+                                        range: 0..0,
                                     },
                                 ),
                                 tooltip: "",
@@ -598,7 +600,7 @@ fn main() {
                                         file_id: FileId(
                                             0,
                                         ),
-                                        range: 24..30,
+                                        range: 0..0,
                                     },
                                 ),
                                 tooltip: "",