diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir/src/code_model.rs | 6 | ||||
-rw-r--r-- | crates/ide/src/inlay_hints.rs | 77 |
2 files changed, 53 insertions, 30 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 650b4fa40..a101d724e 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs | |||
@@ -1389,7 +1389,7 @@ impl Type { | |||
1389 | r#trait: Trait, | 1389 | r#trait: Trait, |
1390 | args: &[Type], | 1390 | args: &[Type], |
1391 | alias: TypeAlias, | 1391 | alias: TypeAlias, |
1392 | ) -> Option<Ty> { | 1392 | ) -> Option<Type> { |
1393 | let subst = Substs::build_for_def(db, r#trait.id) | 1393 | let subst = Substs::build_for_def(db, r#trait.id) |
1394 | .push(self.ty.value.clone()) | 1394 | .push(self.ty.value.clone()) |
1395 | .fill(args.iter().map(|t| t.ty.value.clone())) | 1395 | .fill(args.iter().map(|t| t.ty.value.clone())) |
@@ -1410,6 +1410,10 @@ impl Type { | |||
1410 | Solution::Unique(SolutionVariables(subst)) => subst.value.first().cloned(), | 1410 | Solution::Unique(SolutionVariables(subst)) => subst.value.first().cloned(), |
1411 | Solution::Ambig(_) => None, | 1411 | Solution::Ambig(_) => None, |
1412 | } | 1412 | } |
1413 | .map(|ty| Type { | ||
1414 | krate: self.krate, | ||
1415 | ty: InEnvironment { value: ty, environment: Arc::clone(&self.ty.environment) }, | ||
1416 | }) | ||
1413 | } | 1417 | } |
1414 | 1418 | ||
1415 | pub fn is_copy(&self, db: &dyn HirDatabase) -> bool { | 1419 | pub fn is_copy(&self, db: &dyn HirDatabase) -> bool { |
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index 7d716577e..2ed84095d 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs | |||
@@ -231,12 +231,17 @@ fn hint_iterator( | |||
231 | const LABEL_START: &str = "impl Iterator<Item = "; | 231 | const LABEL_START: &str = "impl Iterator<Item = "; |
232 | const LABEL_END: &str = ">"; | 232 | const LABEL_END: &str = ">"; |
233 | 233 | ||
234 | let ty_display = ty.display_truncated( | 234 | let ty_display = hint_iterator(sema, config, &ty) |
235 | db, | 235 | .map(|assoc_type_impl| assoc_type_impl.to_string()) |
236 | config | 236 | .unwrap_or_else(|| { |
237 | .max_length | 237 | ty.display_truncated( |
238 | .map(|len| len.saturating_sub(LABEL_START.len() + LABEL_END.len())), | 238 | db, |
239 | ); | 239 | config |
240 | .max_length | ||
241 | .map(|len| len.saturating_sub(LABEL_START.len() + LABEL_END.len())), | ||
242 | ) | ||
243 | .to_string() | ||
244 | }); | ||
240 | return Some(format!("{}{}{}", LABEL_START, ty_display, LABEL_END).into()); | 245 | return Some(format!("{}{}{}", LABEL_START, ty_display, LABEL_END).into()); |
241 | } | 246 | } |
242 | } | 247 | } |
@@ -1002,18 +1007,6 @@ fn main() { | |||
1002 | 1007 | ||
1003 | println!("Unit expr"); | 1008 | println!("Unit expr"); |
1004 | } | 1009 | } |
1005 | |||
1006 | //- /alloc.rs crate:alloc deps:core | ||
1007 | mod 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 | "#, | 1010 | "#, |
1018 | ); | 1011 | ); |
1019 | } | 1012 | } |
@@ -1043,17 +1036,6 @@ fn main() { | |||
1043 | //^ &str | 1036 | //^ &str |
1044 | } | 1037 | } |
1045 | } | 1038 | } |
1046 | //- /alloc.rs crate:alloc deps:core | ||
1047 | mod 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 | "#, | 1039 | "#, |
1058 | ); | 1040 | ); |
1059 | } | 1041 | } |
@@ -1183,4 +1165,41 @@ fn main() { | |||
1183 | "#]], | 1165 | "#]], |
1184 | ); | 1166 | ); |
1185 | } | 1167 | } |
1168 | |||
1169 | #[test] | ||
1170 | fn shorten_iterators_in_associated_params() { | ||
1171 | check_with_config( | ||
1172 | InlayHintsConfig { | ||
1173 | parameter_hints: false, | ||
1174 | type_hints: true, | ||
1175 | chaining_hints: false, | ||
1176 | max_length: None, | ||
1177 | }, | ||
1178 | r#" | ||
1179 | use core::iter; | ||
1180 | |||
1181 | pub struct SomeIter<T> {} | ||
1182 | |||
1183 | impl<T> SomeIter<T> { | ||
1184 | pub fn new() -> Self { SomeIter {} } | ||
1185 | pub fn push(&mut self, t: T) {} | ||
1186 | } | ||
1187 | |||
1188 | impl<T> Iterator for SomeIter<T> { | ||
1189 | type Item = T; | ||
1190 | fn next(&mut self) -> Option<Self::Item> { | ||
1191 | None | ||
1192 | } | ||
1193 | } | ||
1194 | |||
1195 | fn main() { | ||
1196 | let mut some_iter = SomeIter::new(); | ||
1197 | //^^^^^^^^^^^^^ SomeIter<Take<Repeat<i32>>> | ||
1198 | some_iter.push(iter::repeat(2).take(2)); | ||
1199 | let iter_of_iters = some_iter.take(2); | ||
1200 | //^^^^^^^^^^^^^ impl Iterator<Item = impl Iterator<Item = i32>> | ||
1201 | } | ||
1202 | "#, | ||
1203 | ); | ||
1204 | } | ||
1186 | } | 1205 | } |