aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/attr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/attr.rs')
-rw-r--r--crates/ra_hir/src/attr.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/crates/ra_hir/src/attr.rs b/crates/ra_hir/src/attr.rs
index 84c36b8da..a8a7e9006 100644
--- a/crates/ra_hir/src/attr.rs
+++ b/crates/ra_hir/src/attr.rs
@@ -45,10 +45,15 @@ impl Attr {
45 45
46 pub(crate) fn from_attrs_owner( 46 pub(crate) fn from_attrs_owner(
47 file_id: HirFileId, 47 file_id: HirFileId,
48 owner: &impl AttrsOwner, 48 owner: &dyn AttrsOwner,
49 db: &impl AstDatabase, 49 db: &impl AstDatabase,
50 ) -> Arc<[Attr]> { 50 ) -> Option<Arc<[Attr]>> {
51 owner.attrs().flat_map(|ast| Attr::from_src(Source { file_id, ast }, db)).collect() 51 let mut attrs = owner.attrs().peekable();
52 if attrs.peek().is_none() {
53 // Avoid heap allocation
54 return None;
55 }
56 Some(attrs.flat_map(|ast| Attr::from_src(Source { file_id, ast }, db)).collect())
52 } 57 }
53 58
54 pub(crate) fn is_simple_atom(&self, name: &str) -> bool { 59 pub(crate) fn is_simple_atom(&self, name: &str) -> bool {