mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 06:23:25 +00:00
return Iterator instead of Vec for combined lifetime and argument parameters
This commit is contained in:
parent
9942cc425b
commit
8bc75c4c28
2 changed files with 23 additions and 32 deletions
|
@ -42,7 +42,7 @@ use hir_def::{
|
||||||
adt::VariantData,
|
adt::VariantData,
|
||||||
body::{BodyDiagnostic, SyntheticSyntax},
|
body::{BodyDiagnostic, SyntheticSyntax},
|
||||||
expr::{BindingAnnotation, ExprOrPatId, LabelId, Pat, PatId},
|
expr::{BindingAnnotation, ExprOrPatId, LabelId, Pat, PatId},
|
||||||
generics::{TypeOrConstParamData, TypeParamProvenance, LifetimeParamData},
|
generics::{LifetimeParamData, TypeOrConstParamData, TypeParamProvenance},
|
||||||
item_tree::ItemTreeNode,
|
item_tree::ItemTreeNode,
|
||||||
lang_item::{LangItem, LangItemTarget},
|
lang_item::{LangItem, LangItemTarget},
|
||||||
layout::{Layout, LayoutError, ReprOptions},
|
layout::{Layout, LayoutError, ReprOptions},
|
||||||
|
@ -1177,13 +1177,16 @@ impl Adt {
|
||||||
Adt::Union(u) => u.id.resolver(db.upcast()),
|
Adt::Union(u) => u.id.resolver(db.upcast()),
|
||||||
Adt::Enum(e) => e.id.resolver(db.upcast()),
|
Adt::Enum(e) => e.id.resolver(db.upcast()),
|
||||||
};
|
};
|
||||||
resolver.generic_params().and_then(|gp| {
|
resolver
|
||||||
|
.generic_params()
|
||||||
|
.and_then(|gp| {
|
||||||
(&gp.lifetimes)
|
(&gp.lifetimes)
|
||||||
.iter()
|
.iter()
|
||||||
// there should only be a single lifetime
|
// there should only be a single lifetime
|
||||||
// but `Arena` requires to use an iterator
|
// but `Arena` requires to use an iterator
|
||||||
.nth(0)
|
.nth(0)
|
||||||
}).map(|arena| arena.1.clone())
|
})
|
||||||
|
.map(|arena| arena.1.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_enum(&self) -> Option<Enum> {
|
pub fn as_enum(&self) -> Option<Enum> {
|
||||||
|
@ -3355,23 +3358,15 @@ impl Type {
|
||||||
.map(move |ty| self.derived(ty))
|
.map(move |ty| self.derived(ty))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Combines lifetime indicators and type arguments into a single `Vec<SmolStr>`
|
/// Combines lifetime indicators and type arguments into a single `Iterator`
|
||||||
pub fn lifetime_and_type_arguments<'a>(&'a self, db: &'a dyn HirDatabase) -> Vec<SmolStr> {
|
pub fn lifetime_and_type_arguments<'a>(
|
||||||
let mut names = if let Some(lt) = self
|
&'a self,
|
||||||
.as_adt()
|
db: &'a dyn HirDatabase,
|
||||||
.and_then(|a| {
|
) -> impl Iterator<Item = SmolStr> + 'a {
|
||||||
a.lifetime(db)
|
self.as_adt()
|
||||||
.and_then(|lt| Some((<.name).to_smol_str().clone()))
|
.and_then(|a| a.lifetime(db).and_then(|lt| Some((<.name).to_smol_str())))
|
||||||
}) {
|
.into_iter()
|
||||||
vec![lt]
|
.chain(self.type_arguments().map(|ty| SmolStr::new(ty.display(db).to_string())))
|
||||||
} else {
|
|
||||||
vec![]
|
|
||||||
};
|
|
||||||
|
|
||||||
for ty in self.type_arguments() {
|
|
||||||
names.push(SmolStr::new(ty.display(db).to_string()))
|
|
||||||
}
|
|
||||||
names
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iterate_method_candidates_with_traits<T>(
|
pub fn iterate_method_candidates_with_traits<T>(
|
||||||
|
|
|
@ -370,7 +370,7 @@ pub(crate) fn runnable_impl(
|
||||||
let nav = def.try_to_nav(sema.db)?;
|
let nav = def.try_to_nav(sema.db)?;
|
||||||
let ty = def.self_ty(sema.db);
|
let ty = def.self_ty(sema.db);
|
||||||
let adt_name = ty.as_adt()?.name(sema.db);
|
let adt_name = ty.as_adt()?.name(sema.db);
|
||||||
let mut ty_args = ty.lifetime_and_type_arguments(sema.db).into_iter().peekable();
|
let mut ty_args = ty.lifetime_and_type_arguments(sema.db).peekable();
|
||||||
let params = if ty_args.peek().is_some() {
|
let params = if ty_args.peek().is_some() {
|
||||||
format!("<{}>", ty_args.format_with(",", |ty, cb| cb(&ty)))
|
format!("<{}>", ty_args.format_with(",", |ty, cb| cb(&ty)))
|
||||||
} else {
|
} else {
|
||||||
|
@ -436,14 +436,10 @@ fn module_def_doctest(db: &RootDatabase, def: Definition) -> Option<Runnable> {
|
||||||
let ty = imp.self_ty(db);
|
let ty = imp.self_ty(db);
|
||||||
if let Some(adt) = ty.as_adt() {
|
if let Some(adt) = ty.as_adt() {
|
||||||
let name = adt.name(db);
|
let name = adt.name(db);
|
||||||
let mut ty_args = ty.lifetime_and_type_arguments(db).into_iter().peekable();
|
let mut ty_args = ty.lifetime_and_type_arguments(db).peekable();
|
||||||
format_to!(path, "{}", name);
|
format_to!(path, "{}", name);
|
||||||
if ty_args.peek().is_some() {
|
if ty_args.peek().is_some() {
|
||||||
format_to!(
|
format_to!(path, "<{}>", ty_args.format_with(",", |ty, cb| cb(&ty)));
|
||||||
path,
|
|
||||||
"<{}>",
|
|
||||||
ty_args.format_with(",", |ty, cb| cb(&ty))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
format_to!(path, "::{}", def_name);
|
format_to!(path, "::{}", def_name);
|
||||||
path.retain(|c| c != ' ');
|
path.retain(|c| c != ' ');
|
||||||
|
|
Loading…
Reference in a new issue