Skip to content

Commit 2bb80a4

Browse files
Also replace the associated types with iter
1 parent 9a72b7b commit 2bb80a4

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

crates/hir/src/code_model.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ impl Type {
13721372
r#trait: Trait,
13731373
args: &[Type],
13741374
alias: TypeAlias,
1375-
) -> Option<Ty> {
1375+
) -> Option<Type> {
13761376
let subst = Substs::build_for_def(db, r#trait.id)
13771377
.push(self.ty.value.clone())
13781378
.fill(args.iter().map(|t| t.ty.value.clone()))
@@ -1393,6 +1393,10 @@ impl Type {
13931393
Solution::Unique(SolutionVariables(subst)) => subst.value.first().cloned(),
13941394
Solution::Ambig(_) => None,
13951395
}
1396+
.map(|ty| Type {
1397+
krate: self.krate,
1398+
ty: InEnvironment { value: ty, environment: Arc::clone(&self.ty.environment) },
1399+
})
13961400
}
13971401

13981402
pub fn is_copy(&self, db: &dyn HirDatabase) -> bool {

crates/ide/src/inlay_hints.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,17 +228,20 @@ 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());
233231
const LABEL_START: &str = "impl Iterator<Item = ";
234232
const LABEL_END: &str = ">";
235233

236-
let ty_display = ty.display_truncated(
237-
db,
238-
config
239-
.max_length
240-
.map(|len| len.saturating_sub(LABEL_START.len() + LABEL_END.len())),
241-
);
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+
});
242245
return Some(format!("{}{}{}", LABEL_START, ty_display, LABEL_END).into());
243246
}
244247
}
@@ -1169,7 +1172,7 @@ fn main() {
11691172
InlayHintsConfig {
11701173
parameter_hints: false,
11711174
type_hints: true,
1172-
chaining_hints: true,
1175+
chaining_hints: false,
11731176
max_length: None,
11741177
},
11751178
r#"
@@ -1193,8 +1196,8 @@ fn main() {
11931196
let mut some_iter = SomeIter::new();
11941197
//^^^^^^^^^^^^^ SomeIter<Take<Repeat<i32>>>
11951198
some_iter.push(iter::repeat(2).take(2));
1196-
let zz = some_iter.take(2);
1197-
//^^ impl Iterator<Item = Take<Repeat<i32>>>
1199+
let iter_of_iters = some_iter.take(2);
1200+
//^^^^^^^^^^^^^ impl Iterator<Item = impl Iterator<Item = i32>>
11981201
}
11991202
"#,
12001203
);

0 commit comments

Comments
 (0)