mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Also replace the associated types with iter
This commit is contained in:
parent
9a72b7bccd
commit
2bb80a4f03
2 changed files with 19 additions and 12 deletions
|
@ -1372,7 +1372,7 @@ impl Type {
|
||||||
r#trait: Trait,
|
r#trait: Trait,
|
||||||
args: &[Type],
|
args: &[Type],
|
||||||
alias: TypeAlias,
|
alias: TypeAlias,
|
||||||
) -> Option<Ty> {
|
) -> Option<Type> {
|
||||||
let subst = Substs::build_for_def(db, r#trait.id)
|
let subst = Substs::build_for_def(db, r#trait.id)
|
||||||
.push(self.ty.value.clone())
|
.push(self.ty.value.clone())
|
||||||
.fill(args.iter().map(|t| t.ty.value.clone()))
|
.fill(args.iter().map(|t| t.ty.value.clone()))
|
||||||
|
@ -1393,6 +1393,10 @@ impl Type {
|
||||||
Solution::Unique(SolutionVariables(subst)) => subst.value.first().cloned(),
|
Solution::Unique(SolutionVariables(subst)) => subst.value.first().cloned(),
|
||||||
Solution::Ambig(_) => None,
|
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 {
|
pub fn is_copy(&self, db: &dyn HirDatabase) -> bool {
|
||||||
|
|
|
@ -228,17 +228,20 @@ fn hint_iterator(
|
||||||
_ => None,
|
_ => None,
|
||||||
})?;
|
})?;
|
||||||
if let Some(ty) = ty.normalize_trait_assoc_type(db, iter_trait, &[], assoc_type_item) {
|
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_START: &str = "impl Iterator<Item = ";
|
||||||
const LABEL_END: &str = ">";
|
const LABEL_END: &str = ">";
|
||||||
|
|
||||||
let ty_display = ty.display_truncated(
|
let ty_display = hint_iterator(sema, config, &ty)
|
||||||
db,
|
.map(|assoc_type_impl| assoc_type_impl.to_string())
|
||||||
config
|
.unwrap_or_else(|| {
|
||||||
.max_length
|
ty.display_truncated(
|
||||||
.map(|len| len.saturating_sub(LABEL_START.len() + LABEL_END.len())),
|
db,
|
||||||
);
|
config
|
||||||
|
.max_length
|
||||||
|
.map(|len| len.saturating_sub(LABEL_START.len() + LABEL_END.len())),
|
||||||
|
)
|
||||||
|
.to_string()
|
||||||
|
});
|
||||||
return Some(format!("{}{}{}", LABEL_START, ty_display, LABEL_END).into());
|
return Some(format!("{}{}{}", LABEL_START, ty_display, LABEL_END).into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1169,7 +1172,7 @@ fn main() {
|
||||||
InlayHintsConfig {
|
InlayHintsConfig {
|
||||||
parameter_hints: false,
|
parameter_hints: false,
|
||||||
type_hints: true,
|
type_hints: true,
|
||||||
chaining_hints: true,
|
chaining_hints: false,
|
||||||
max_length: None,
|
max_length: None,
|
||||||
},
|
},
|
||||||
r#"
|
r#"
|
||||||
|
@ -1193,8 +1196,8 @@ fn main() {
|
||||||
let mut some_iter = SomeIter::new();
|
let mut some_iter = SomeIter::new();
|
||||||
//^^^^^^^^^^^^^ SomeIter<Take<Repeat<i32>>>
|
//^^^^^^^^^^^^^ SomeIter<Take<Repeat<i32>>>
|
||||||
some_iter.push(iter::repeat(2).take(2));
|
some_iter.push(iter::repeat(2).take(2));
|
||||||
let zz = some_iter.take(2);
|
let iter_of_iters = some_iter.take(2);
|
||||||
//^^ impl Iterator<Item = Take<Repeat<i32>>>
|
//^^^^^^^^^^^^^ impl Iterator<Item = impl Iterator<Item = i32>>
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue