Add a test

This commit is contained in:
Kirill Bulatov 2020-10-10 19:51:02 +03:00
parent b7596d2483
commit 9a72b7bccd

View file

@ -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<Item = ";
const LABEL_END: &str = ">";
@ -1002,18 +1004,6 @@ fn main() {
println!("Unit expr");
}
//- /alloc.rs crate:alloc deps:core
mod collections {
struct Vec<T> {}
impl<T> Vec<T> {
fn new() -> Self { Vec {} }
fn push(&mut self, t: T) { }
}
impl<T> IntoIterator for Vec<T> {
type Item=T;
}
}
"#,
);
}
@ -1043,17 +1033,6 @@ fn main() {
//^ &str
}
}
//- /alloc.rs crate:alloc deps:core
mod collections {
struct Vec<T> {}
impl<T> Vec<T> {
fn new() -> Self { Vec {} }
fn push(&mut self, t: T) { }
}
impl<T> IntoIterator for Vec<T> {
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<T> {}
impl<T> SomeIter<T> {
pub fn new() -> Self { SomeIter {} }
pub fn push(&mut self, t: T) {}
}
impl<T> Iterator for SomeIter<T> {
type Item = T;
fn next(&mut self) -> Option<Self::Item> {
None
}
}
fn main() {
let mut some_iter = SomeIter::new();
//^^^^^^^^^^^^^ SomeIter<Take<Repeat<i32>>>
some_iter.push(iter::repeat(2).take(2));
let zz = some_iter.take(2);
//^^ impl Iterator<Item = Take<Repeat<i32>>>
}
"#,
);
}
}