Address review comments part 1

This commit is contained in:
hecatia-elegua 2023-03-30 17:35:57 +02:00
parent ba2b48d1b8
commit c469936aac
5 changed files with 19 additions and 17 deletions

View file

@ -1,5 +1,8 @@
//! A higher level attributes based on TokenTree, with also some shortcuts.
#[cfg(test)]
mod tests;
use std::{hash::Hash, ops, sync::Arc};
use base_db::CrateId;
@ -238,12 +241,12 @@ impl Attrs {
})
}
pub fn doc_exprs(&self) -> Vec<DocExpr> {
self.by_key("doc").tt_values().map(DocExpr::parse).collect()
pub fn doc_exprs(&self) -> impl Iterator<Item = DocExpr> + '_ {
self.by_key("doc").tt_values().map(DocExpr::parse)
}
pub fn doc_aliases(&self) -> Vec<SmolStr> {
self.doc_exprs().into_iter().flat_map(|doc_expr| doc_expr.aliases()).collect()
pub fn doc_aliases(&self) -> impl Iterator<Item = SmolStr> + '_ {
self.doc_exprs().flat_map(|doc_expr| doc_expr.aliases().to_vec())
}
pub fn is_proc_macro(&self) -> bool {
@ -288,17 +291,17 @@ impl From<DocAtom> for DocExpr {
}
impl DocExpr {
pub fn parse<S>(tt: &tt::Subtree<S>) -> DocExpr {
fn parse<S>(tt: &tt::Subtree<S>) -> DocExpr {
next_doc_expr(&mut tt.token_trees.iter()).unwrap_or(DocExpr::Invalid)
}
pub fn aliases(self) -> Vec<SmolStr> {
pub fn aliases(&self) -> &[SmolStr] {
match self {
DocExpr::Atom(DocAtom::KeyValue { key, value }) if key == "alias" => {
vec![value]
std::slice::from_ref(value)
}
DocExpr::Alias(aliases) => aliases,
_ => vec![],
_ => &[],
}
}
}

View file

@ -53,8 +53,6 @@ pub mod import_map;
mod test_db;
#[cfg(test)]
mod macro_expansion_tests;
#[cfg(test)]
mod attr_tests;
mod pretty;
use std::{