Skip to content

Commit 9a72b7b

Browse files
Add a test
1 parent b7596d2 commit 9a72b7b

File tree

1 file changed

+39
-23
lines changed

1 file changed

+39
-23
lines changed

crates/ide/src/inlay_hints.rs

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ fn hint_iterator(
228228
_ => None,
229229
})?;
230230
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());
231233
const LABEL_START: &str = "impl Iterator<Item = ";
232234
const LABEL_END: &str = ">";
233235

@@ -1002,18 +1004,6 @@ fn main() {
10021004
10031005
println!("Unit expr");
10041006
}
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-
}
10171007
"#,
10181008
);
10191009
}
@@ -1043,17 +1033,6 @@ fn main() {
10431033
//^ &str
10441034
}
10451035
}
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-
}
10571036
"#,
10581037
);
10591038
}
@@ -1183,4 +1162,41 @@ fn main() {
11831162
"#]],
11841163
);
11851164
}
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#"
1176+
use core::iter;
1177+
1178+
pub struct SomeIter<T> {}
1179+
1180+
impl<T> SomeIter<T> {
1181+
pub fn new() -> Self { SomeIter {} }
1182+
pub fn push(&mut self, t: T) {}
1183+
}
1184+
1185+
impl<T> Iterator for SomeIter<T> {
1186+
type Item = T;
1187+
fn next(&mut self) -> Option<Self::Item> {
1188+
None
1189+
}
1190+
}
1191+
1192+
fn 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+
}
11861202
}

0 commit comments

Comments
 (0)