aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock15
-rw-r--r--crates/ra_hir_ty/src/display.rs12
-rw-r--r--crates/ra_hir_ty/src/lib.rs31
-rw-r--r--crates/ra_ide/src/inlay_hints.rs37
4 files changed, 70 insertions, 25 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 792e30494..3314ef70f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -10,7 +10,7 @@ dependencies = [
10 10
11[[package]] 11[[package]]
12name = "anyhow" 12name = "anyhow"
13version = "1.0.25" 13version = "1.0.26"
14source = "registry+https://github.com/rust-lang/crates.io-index" 14source = "registry+https://github.com/rust-lang/crates.io-index"
15 15
16[[package]] 16[[package]]
@@ -237,7 +237,7 @@ dependencies = [
237 "crossbeam-channel 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 237 "crossbeam-channel 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
238 "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", 238 "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
239 "crossbeam-epoch 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 239 "crossbeam-epoch 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
240 "crossbeam-queue 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 240 "crossbeam-queue 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
241 "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 241 "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
242] 242]
243 243
@@ -273,9 +273,10 @@ dependencies = [
273 273
274[[package]] 274[[package]]
275name = "crossbeam-queue" 275name = "crossbeam-queue"
276version = "0.2.0" 276version = "0.2.1"
277source = "registry+https://github.com/rust-lang/crates.io-index" 277source = "registry+https://github.com/rust-lang/crates.io-index"
278dependencies = [ 278dependencies = [
279 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
279 "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 280 "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
280] 281]
281 282
@@ -1334,7 +1335,7 @@ version = "1.7.0"
1334source = "registry+https://github.com/rust-lang/crates.io-index" 1335source = "registry+https://github.com/rust-lang/crates.io-index"
1335dependencies = [ 1336dependencies = [
1336 "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", 1337 "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
1337 "crossbeam-queue 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 1338 "crossbeam-queue 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
1338 "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 1339 "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
1339 "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 1340 "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
1340 "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", 1341 "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1752,7 +1753,7 @@ dependencies = [
1752name = "xtask" 1753name = "xtask"
1753version = "0.1.0" 1754version = "0.1.0"
1754dependencies = [ 1755dependencies = [
1755 "anyhow 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", 1756 "anyhow 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)",
1756 "pico-args 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 1757 "pico-args 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
1757 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 1758 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
1758 "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 1759 "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1771,7 +1772,7 @@ dependencies = [
1771 1772
1772[metadata] 1773[metadata]
1773"checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d" 1774"checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d"
1774"checksum anyhow 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "9267dff192e68f3399525901e709a48c1d3982c9c072fa32f2127a0cb0babf14" 1775"checksum anyhow 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)" = "7825f6833612eb2414095684fcf6c635becf3ce97fe48cf6421321e93bfbd53c"
1775"checksum anymap 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "33954243bd79057c2de7338850b85983a44588021f8a5fee574a8888c6de4344" 1776"checksum anymap 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "33954243bd79057c2de7338850b85983a44588021f8a5fee574a8888c6de4344"
1776"checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" 1777"checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
1777"checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" 1778"checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90"
@@ -1802,7 +1803,7 @@ dependencies = [
1802"checksum crossbeam-channel 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "acec9a3b0b3559f15aee4f90746c4e5e293b701c0f7d3925d24e01645267b68c" 1803"checksum crossbeam-channel 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "acec9a3b0b3559f15aee4f90746c4e5e293b701c0f7d3925d24e01645267b68c"
1803"checksum crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3aa945d63861bfe624b55d153a39684da1e8c0bc8fba932f7ee3a3c16cea3ca" 1804"checksum crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3aa945d63861bfe624b55d153a39684da1e8c0bc8fba932f7ee3a3c16cea3ca"
1804"checksum crossbeam-epoch 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5064ebdbf05ce3cb95e45c8b086f72263f4166b29b97f6baff7ef7fe047b55ac" 1805"checksum crossbeam-epoch 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5064ebdbf05ce3cb95e45c8b086f72263f4166b29b97f6baff7ef7fe047b55ac"
1805"checksum crossbeam-queue 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dfd6515864a82d2f877b42813d4553292c6659498c9a2aa31bab5a15243c2700" 1806"checksum crossbeam-queue 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c695eeca1e7173472a32221542ae469b3e9aac3a4fc81f7696bcad82029493db"
1806"checksum crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4" 1807"checksum crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4"
1807"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" 1808"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
1808"checksum drop_bomb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "69b26e475fd29098530e709294e94e661974c851aed42512793f120fed4e199f" 1809"checksum drop_bomb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "69b26e475fd29098530e709294e94e661974c851aed42512793f120fed4e199f"
diff --git a/crates/ra_hir_ty/src/display.rs b/crates/ra_hir_ty/src/display.rs
index dcca1bace..37def7c03 100644
--- a/crates/ra_hir_ty/src/display.rs
+++ b/crates/ra_hir_ty/src/display.rs
@@ -10,7 +10,7 @@ pub struct HirFormatter<'a, 'b, DB> {
10 buf: String, 10 buf: String,
11 curr_size: usize, 11 curr_size: usize,
12 max_size: Option<usize>, 12 max_size: Option<usize>,
13 should_display_default_types: bool, 13 omit_verbose_types: bool,
14} 14}
15 15
16pub trait HirDisplay { 16pub trait HirDisplay {
@@ -20,7 +20,7 @@ pub trait HirDisplay {
20 where 20 where
21 Self: Sized, 21 Self: Sized,
22 { 22 {
23 HirDisplayWrapper(db, self, None, true) 23 HirDisplayWrapper(db, self, None, false)
24 } 24 }
25 25
26 fn display_truncated<'a, DB>( 26 fn display_truncated<'a, DB>(
@@ -31,7 +31,7 @@ pub trait HirDisplay {
31 where 31 where
32 Self: Sized, 32 Self: Sized,
33 { 33 {
34 HirDisplayWrapper(db, self, max_size, false) 34 HirDisplayWrapper(db, self, max_size, true)
35 } 35 }
36} 36}
37 37
@@ -74,8 +74,8 @@ where
74 } 74 }
75 } 75 }
76 76
77 pub fn should_display_default_types(&self) -> bool { 77 pub fn omit_verbose_types(&self) -> bool {
78 self.should_display_default_types 78 self.omit_verbose_types
79 } 79 }
80} 80}
81 81
@@ -93,7 +93,7 @@ where
93 buf: String::with_capacity(20), 93 buf: String::with_capacity(20),
94 curr_size: 0, 94 curr_size: 0,
95 max_size: self.2, 95 max_size: self.2,
96 should_display_default_types: self.3, 96 omit_verbose_types: self.3,
97 }) 97 })
98 } 98 }
99} 99}
diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs
index 48abf97c9..55b6dd836 100644
--- a/crates/ra_hir_ty/src/lib.rs
+++ b/crates/ra_hir_ty/src/lib.rs
@@ -821,6 +821,8 @@ impl TypeWalk for Ty {
821 } 821 }
822} 822}
823 823
824const TYPE_HINT_TRUNCATION: &str = "…";
825
824impl HirDisplay for &Ty { 826impl HirDisplay for &Ty {
825 fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { 827 fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result {
826 HirDisplay::hir_fmt(*self, f) 828 HirDisplay::hir_fmt(*self, f)
@@ -830,7 +832,7 @@ impl HirDisplay for &Ty {
830impl HirDisplay for ApplicationTy { 832impl HirDisplay for ApplicationTy {
831 fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { 833 fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result {
832 if f.should_truncate() { 834 if f.should_truncate() {
833 return write!(f, ""); 835 return write!(f, "{}", TYPE_HINT_TRUNCATION);
834 } 836 }
835 837
836 match self.ctor { 838 match self.ctor {
@@ -908,9 +910,7 @@ impl HirDisplay for ApplicationTy {
908 write!(f, "<")?; 910 write!(f, "<")?;
909 911
910 let mut non_default_parameters = Vec::with_capacity(self.parameters.len()); 912 let mut non_default_parameters = Vec::with_capacity(self.parameters.len());
911 let parameters_to_write = if f.should_display_default_types() { 913 let parameters_to_write = if f.omit_verbose_types() {
912 self.parameters.0.as_ref()
913 } else {
914 match self 914 match self
915 .ctor 915 .ctor
916 .as_generic_def() 916 .as_generic_def()
@@ -935,6 +935,8 @@ impl HirDisplay for ApplicationTy {
935 &non_default_parameters 935 &non_default_parameters
936 } 936 }
937 } 937 }
938 } else {
939 self.parameters.0.as_ref()
938 }; 940 };
939 941
940 f.write_joined(parameters_to_write, ", ")?; 942 f.write_joined(parameters_to_write, ", ")?;
@@ -959,9 +961,16 @@ impl HirDisplay for ApplicationTy {
959 let sig = self.parameters[0] 961 let sig = self.parameters[0]
960 .callable_sig(f.db) 962 .callable_sig(f.db)
961 .expect("first closure parameter should contain signature"); 963 .expect("first closure parameter should contain signature");
962 write!(f, "|")?; 964 let return_type_hint = sig.ret().display(f.db);
963 f.write_joined(sig.params(), ", ")?; 965 if sig.params().is_empty() {
964 write!(f, "| -> {}", sig.ret().display(f.db))?; 966 write!(f, "|| -> {}", return_type_hint)?;
967 } else if f.omit_verbose_types() {
968 write!(f, "|{}| -> {}", TYPE_HINT_TRUNCATION, return_type_hint)?;
969 } else {
970 write!(f, "|")?;
971 f.write_joined(sig.params(), ", ")?;
972 write!(f, "| -> {}", return_type_hint)?;
973 };
965 } 974 }
966 } 975 }
967 Ok(()) 976 Ok(())
@@ -971,7 +980,7 @@ impl HirDisplay for ApplicationTy {
971impl HirDisplay for ProjectionTy { 980impl HirDisplay for ProjectionTy {
972 fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { 981 fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result {
973 if f.should_truncate() { 982 if f.should_truncate() {
974 return write!(f, ""); 983 return write!(f, "{}", TYPE_HINT_TRUNCATION);
975 } 984 }
976 985
977 let trait_name = f.db.trait_data(self.trait_(f.db)).name.clone(); 986 let trait_name = f.db.trait_data(self.trait_(f.db)).name.clone();
@@ -989,7 +998,7 @@ impl HirDisplay for ProjectionTy {
989impl HirDisplay for Ty { 998impl HirDisplay for Ty {
990 fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { 999 fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result {
991 if f.should_truncate() { 1000 if f.should_truncate() {
992 return write!(f, ""); 1001 return write!(f, "{}", TYPE_HINT_TRUNCATION);
993 } 1002 }
994 1003
995 match self { 1004 match self {
@@ -1074,7 +1083,7 @@ impl HirDisplay for Ty {
1074impl TraitRef { 1083impl TraitRef {
1075 fn hir_fmt_ext(&self, f: &mut HirFormatter<impl HirDatabase>, use_as: bool) -> fmt::Result { 1084 fn hir_fmt_ext(&self, f: &mut HirFormatter<impl HirDatabase>, use_as: bool) -> fmt::Result {
1076 if f.should_truncate() { 1085 if f.should_truncate() {
1077 return write!(f, ""); 1086 return write!(f, "{}", TYPE_HINT_TRUNCATION);
1078 } 1087 }
1079 1088
1080 self.substs[0].hir_fmt(f)?; 1089 self.substs[0].hir_fmt(f)?;
@@ -1108,7 +1117,7 @@ impl HirDisplay for &GenericPredicate {
1108impl HirDisplay for GenericPredicate { 1117impl HirDisplay for GenericPredicate {
1109 fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { 1118 fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result {
1110 if f.should_truncate() { 1119 if f.should_truncate() {
1111 return write!(f, ""); 1120 return write!(f, "{}", TYPE_HINT_TRUNCATION);
1112 } 1121 }
1113 1122
1114 match self { 1123 match self {
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs
index c5e406977..977aafc51 100644
--- a/crates/ra_ide/src/inlay_hints.rs
+++ b/crates/ra_ide/src/inlay_hints.rs
@@ -293,7 +293,7 @@ fn main() {
293 } 293 }
294 294
295 #[test] 295 #[test]
296 fn closure_parameter() { 296 fn closure_parameters() {
297 let (analysis, file_id) = single_file( 297 let (analysis, file_id) = single_file(
298 r#" 298 r#"
299fn main() { 299fn main() {
@@ -301,6 +301,11 @@ fn main() {
301 (0..2).for_each(|increment| { 301 (0..2).for_each(|increment| {
302 start += increment; 302 start += increment;
303 }) 303 })
304
305 let multiply = |a, b, c, d| a * b * c * d;
306 let _: i32 = multiply(1, 2, 3, 4);
307
308 let return_42 = || 42;
304}"#, 309}"#,
305 ); 310 );
306 311
@@ -316,6 +321,36 @@ fn main() {
316 kind: TypeHint, 321 kind: TypeHint,
317 label: "i32", 322 label: "i32",
318 }, 323 },
324 InlayHint {
325 range: [114; 122),
326 kind: TypeHint,
327 label: "|…| -> i32",
328 },
329 InlayHint {
330 range: [126; 127),
331 kind: TypeHint,
332 label: "i32",
333 },
334 InlayHint {
335 range: [129; 130),
336 kind: TypeHint,
337 label: "i32",
338 },
339 InlayHint {
340 range: [132; 133),
341 kind: TypeHint,
342 label: "i32",
343 },
344 InlayHint {
345 range: [135; 136),
346 kind: TypeHint,
347 label: "i32",
348 },
349 InlayHint {
350 range: [201; 210),
351 kind: TypeHint,
352 label: "|| -> i32",
353 },
319 ] 354 ]
320 "### 355 "###
321 ); 356 );