From 9a72b7bccde54d901f3d89300777e0685790aefd Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sat, 10 Oct 2020 19:51:02 +0300 Subject: Add a test --- crates/ide/src/inlay_hints.rs | 62 +++++++++++++++++++++++++++---------------- 1 file 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( _ => None, })?; if let Some(ty) = ty.normalize_trait_assoc_type(db, iter_trait, &[], assoc_type_item) { + // TODO kb also check for the iterator impls for this ty + dbg!(ty.display(db).to_string()); const LABEL_START: &str = "impl Iterator {} - impl Vec { - fn new() -> Self { Vec {} } - fn push(&mut self, t: T) { } - } - impl IntoIterator for Vec { - type Item=T; - } -} "#, ); } @@ -1043,17 +1033,6 @@ fn main() { //^ &str } } -//- /alloc.rs crate:alloc deps:core -mod collections { - struct Vec {} - impl Vec { - fn new() -> Self { Vec {} } - fn push(&mut self, t: T) { } - } - impl IntoIterator for Vec { - type Item=T; - } -} "#, ); } @@ -1183,4 +1162,41 @@ fn main() { "#]], ); } + + #[test] + fn shorten_iterators_in_associated_params() { + check_with_config( + InlayHintsConfig { + parameter_hints: false, + type_hints: true, + chaining_hints: true, + max_length: None, + }, + r#" +use core::iter; + +pub struct SomeIter {} + +impl SomeIter { + pub fn new() -> Self { SomeIter {} } + pub fn push(&mut self, t: T) {} +} + +impl Iterator for SomeIter { + type Item = T; + fn next(&mut self) -> Option { + None + } +} + +fn main() { + let mut some_iter = SomeIter::new(); + //^^^^^^^^^^^^^ SomeIter>> + some_iter.push(iter::repeat(2).take(2)); + let zz = some_iter.take(2); + //^^ impl Iterator>> +} +"#, + ); + } } -- cgit v1.2.3