diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 650b4fa40ce..a101d724e46 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs @@ -1389,7 +1389,7 @@ pub fn normalize_trait_assoc_type( r#trait: Trait, args: &[Type], alias: TypeAlias, - ) -> Option { + ) -> Option { let subst = Substs::build_for_def(db, r#trait.id) .push(self.ty.value.clone()) .fill(args.iter().map(|t| t.ty.value.clone())) @@ -1410,6 +1410,10 @@ pub fn normalize_trait_assoc_type( Solution::Unique(SolutionVariables(subst)) => subst.value.first().cloned(), Solution::Ambig(_) => None, } + .map(|ty| Type { + krate: self.krate, + ty: InEnvironment { value: ty, environment: Arc::clone(&self.ty.environment) }, + }) } 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 7d716577e2b..2ed84095da1 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs @@ -231,12 +231,17 @@ fn hint_iterator( 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 +1036,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 +1165,41 @@ fn main() { "#]], ); } + + #[test] + fn shorten_iterators_in_associated_params() { + check_with_config( + InlayHintsConfig { + parameter_hints: false, + type_hints: true, + chaining_hints: false, + 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 iter_of_iters = some_iter.take(2); + //^^^^^^^^^^^^^ impl Iterator> +} +"#, + ); + } }