@@ -231,12 +231,17 @@ fn hint_iterator(
231
231
const LABEL_START : & str = "impl Iterator<Item = " ;
232
232
const LABEL_END : & str = ">" ;
233
233
234
- let ty_display = ty. display_truncated (
235
- db,
236
- config
237
- . max_length
238
- . map ( |len| len. saturating_sub ( LABEL_START . len ( ) + LABEL_END . len ( ) ) ) ,
239
- ) ;
234
+ let ty_display = hint_iterator ( sema, config, & ty)
235
+ . map ( |assoc_type_impl| assoc_type_impl. to_string ( ) )
236
+ . unwrap_or_else ( || {
237
+ ty. display_truncated (
238
+ db,
239
+ config
240
+ . max_length
241
+ . map ( |len| len. saturating_sub ( LABEL_START . len ( ) + LABEL_END . len ( ) ) ) ,
242
+ )
243
+ . to_string ( )
244
+ } ) ;
240
245
return Some ( format ! ( "{}{}{}" , LABEL_START , ty_display, LABEL_END ) . into ( ) ) ;
241
246
}
242
247
}
@@ -1002,18 +1007,6 @@ fn main() {
1002
1007
1003
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
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
}
0 commit comments