aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-10-10 19:37:20 +0100
committerKirill Bulatov <[email protected]>2020-10-10 19:39:57 +0100
commit2bb80a4f0350045503258518d354a4e63e4c68fd (patch)
treeb9b9e8283753f469177797dac60c76fc89a8bcd3 /crates
parent9a72b7bccde54d901f3d89300777e0685790aefd (diff)
Also replace the associated types with iter
Diffstat (limited to 'crates')
-rw-r--r--crates/hir/src/code_model.rs6
-rw-r--r--crates/ide/src/inlay_hints.rs25
2 files changed, 19 insertions, 12 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs
index 031c91ccf..9aaa280c8 100644
--- a/crates/hir/src/code_model.rs
+++ b/crates/hir/src/code_model.rs
@@ -1372,7 +1372,7 @@ impl Type {
1372 r#trait: Trait, 1372 r#trait: Trait,
1373 args: &[Type], 1373 args: &[Type],
1374 alias: TypeAlias, 1374 alias: TypeAlias,
1375 ) -> Option<Ty> { 1375 ) -> Option<Type> {
1376 let subst = Substs::build_for_def(db, r#trait.id) 1376 let subst = Substs::build_for_def(db, r#trait.id)
1377 .push(self.ty.value.clone()) 1377 .push(self.ty.value.clone())
1378 .fill(args.iter().map(|t| t.ty.value.clone())) 1378 .fill(args.iter().map(|t| t.ty.value.clone()))
@@ -1393,6 +1393,10 @@ impl Type {
1393 Solution::Unique(SolutionVariables(subst)) => subst.value.first().cloned(), 1393 Solution::Unique(SolutionVariables(subst)) => subst.value.first().cloned(),
1394 Solution::Ambig(_) => None, 1394 Solution::Ambig(_) => None,
1395 } 1395 }
1396 .map(|ty| Type {
1397 krate: self.krate,
1398 ty: InEnvironment { value: ty, environment: Arc::clone(&self.ty.environment) },
1399 })
1396 } 1400 }
1397 1401
1398 pub fn is_copy(&self, db: &dyn HirDatabase) -> bool { 1402 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 08ef49a27..2ed84095d 100644
--- a/crates/ide/src/inlay_hints.rs
+++ b/crates/ide/src/inlay_hints.rs
@@ -228,17 +228,20 @@ fn hint_iterator(
228 _ => None, 228 _ => None,
229 })?; 229 })?;
230 if let Some(ty) = ty.normalize_trait_assoc_type(db, iter_trait, &[], assoc_type_item) { 230 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());
233 const LABEL_START: &str = "impl Iterator<Item = "; 231 const LABEL_START: &str = "impl Iterator<Item = ";
234 const LABEL_END: &str = ">"; 232 const LABEL_END: &str = ">";
235 233
236 let ty_display = ty.display_truncated( 234 let ty_display = hint_iterator(sema, config, &ty)
237 db, 235 .map(|assoc_type_impl| assoc_type_impl.to_string())
238 config 236 .unwrap_or_else(|| {
239 .max_length 237 ty.display_truncated(
240 .map(|len| len.saturating_sub(LABEL_START.len() + LABEL_END.len())), 238 db,
241 ); 239 config
240 .max_length
241 .map(|len| len.saturating_sub(LABEL_START.len() + LABEL_END.len())),
242 )
243 .to_string()
244 });
242 return Some(format!("{}{}{}", LABEL_START, ty_display, LABEL_END).into()); 245 return Some(format!("{}{}{}", LABEL_START, ty_display, LABEL_END).into());
243 } 246 }
244 } 247 }
@@ -1169,7 +1172,7 @@ fn main() {
1169 InlayHintsConfig { 1172 InlayHintsConfig {
1170 parameter_hints: false, 1173 parameter_hints: false,
1171 type_hints: true, 1174 type_hints: true,
1172 chaining_hints: true, 1175 chaining_hints: false,
1173 max_length: None, 1176 max_length: None,
1174 }, 1177 },
1175 r#" 1178 r#"
@@ -1193,8 +1196,8 @@ fn main() {
1193 let mut some_iter = SomeIter::new(); 1196 let mut some_iter = SomeIter::new();
1194 //^^^^^^^^^^^^^ SomeIter<Take<Repeat<i32>>> 1197 //^^^^^^^^^^^^^ SomeIter<Take<Repeat<i32>>>
1195 some_iter.push(iter::repeat(2).take(2)); 1198 some_iter.push(iter::repeat(2).take(2));
1196 let zz = some_iter.take(2); 1199 let iter_of_iters = some_iter.take(2);
1197 //^^ impl Iterator<Item = Take<Repeat<i32>>> 1200 //^^^^^^^^^^^^^ impl Iterator<Item = impl Iterator<Item = i32>>
1198} 1201}
1199"#, 1202"#,
1200 ); 1203 );