aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/inlay_hints.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/inlay_hints.rs')
-rw-r--r--crates/ide/src/inlay_hints.rs62
1 files changed, 39 insertions, 23 deletions
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs
index 7d716577e..08ef49a27 100644
--- a/crates/ide/src/inlay_hints.rs
+++ b/crates/ide/src/inlay_hints.rs
@@ -228,6 +228,8 @@ fn hint_iterator(
228 _ => None, 228 _ => None,
229 })?; 229 })?;
230 if let Some(ty) = ty.normalize_trait_assoc_type(db, iter_trait, &[], assoc_type_item) { 230 if let Some(ty) = ty.normalize_trait_assoc_type(db, iter_trait, &[], assoc_type_item) {
231 // TODO kb also check for the iterator impls for this ty
232 dbg!(ty.display(db).to_string());
231 const LABEL_START: &str = "impl Iterator<Item = "; 233 const LABEL_START: &str = "impl Iterator<Item = ";
232 const LABEL_END: &str = ">"; 234 const LABEL_END: &str = ">";
233 235
@@ -1002,18 +1004,6 @@ fn main() {
1002 1004
1003 println!("Unit expr"); 1005 println!("Unit expr");
1004} 1006}
1005
1006//- /alloc.rs crate:alloc deps:core
1007mod collections {
1008 struct Vec<T> {}
1009 impl<T> Vec<T> {
1010 fn new() -> Self { Vec {} }
1011 fn push(&mut self, t: T) { }
1012 }
1013 impl<T> IntoIterator for Vec<T> {
1014 type Item=T;
1015 }
1016}
1017"#, 1007"#,
1018 ); 1008 );
1019 } 1009 }
@@ -1043,17 +1033,6 @@ fn main() {
1043 //^ &str 1033 //^ &str
1044 } 1034 }
1045} 1035}
1046//- /alloc.rs crate:alloc deps:core
1047mod collections {
1048 struct Vec<T> {}
1049 impl<T> Vec<T> {
1050 fn new() -> Self { Vec {} }
1051 fn push(&mut self, t: T) { }
1052 }
1053 impl<T> IntoIterator for Vec<T> {
1054 type Item=T;
1055 }
1056}
1057"#, 1036"#,
1058 ); 1037 );
1059 } 1038 }
@@ -1183,4 +1162,41 @@ fn main() {
1183 "#]], 1162 "#]],
1184 ); 1163 );
1185 } 1164 }
1165
1166 #[test]
1167 fn shorten_iterators_in_associated_params() {
1168 check_with_config(
1169 InlayHintsConfig {
1170 parameter_hints: false,
1171 type_hints: true,
1172 chaining_hints: true,
1173 max_length: None,
1174 },
1175 r#"
1176use core::iter;
1177
1178pub struct SomeIter<T> {}
1179
1180impl<T> SomeIter<T> {
1181 pub fn new() -> Self { SomeIter {} }
1182 pub fn push(&mut self, t: T) {}
1183}
1184
1185impl<T> Iterator for SomeIter<T> {
1186 type Item = T;
1187 fn next(&mut self) -> Option<Self::Item> {
1188 None
1189 }
1190}
1191
1192fn main() {
1193 let mut some_iter = SomeIter::new();
1194 //^^^^^^^^^^^^^ SomeIter<Take<Repeat<i32>>>
1195 some_iter.push(iter::repeat(2).take(2));
1196 let zz = some_iter.take(2);
1197 //^^ impl Iterator<Item = Take<Repeat<i32>>>
1198}
1199"#,
1200 );
1201 }
1186} 1202}