aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src')
-rw-r--r--crates/hir_def/src/attr.rs28
1 files changed, 14 insertions, 14 deletions
diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs
index aeeb2c5cf..b7353d868 100644
--- a/crates/hir_def/src/attr.rs
+++ b/crates/hir_def/src/attr.rs
@@ -76,7 +76,7 @@ impl ops::Deref for Attrs {
76impl RawAttrs { 76impl RawAttrs {
77 pub(crate) const EMPTY: Self = Self { entries: None }; 77 pub(crate) const EMPTY: Self = Self { entries: None };
78 78
79 pub(crate) fn new(owner: &dyn AttrsOwner, hygiene: &Hygiene) -> Self { 79 pub(crate) fn new(owner: &dyn ast::AttrsOwner, hygiene: &Hygiene) -> Self {
80 let entries = collect_attrs(owner) 80 let entries = collect_attrs(owner)
81 .enumerate() 81 .enumerate()
82 .flat_map(|(i, attr)| match attr { 82 .flat_map(|(i, attr)| match attr {
@@ -92,7 +92,7 @@ impl RawAttrs {
92 Self { entries: if entries.is_empty() { None } else { Some(entries) } } 92 Self { entries: if entries.is_empty() { None } else { Some(entries) } }
93 } 93 }
94 94
95 fn from_attrs_owner(db: &dyn DefDatabase, owner: InFile<&dyn AttrsOwner>) -> Self { 95 fn from_attrs_owner(db: &dyn DefDatabase, owner: InFile<&dyn ast::AttrsOwner>) -> Self {
96 let hygiene = Hygiene::new(db.upcast(), owner.file_id); 96 let hygiene = Hygiene::new(db.upcast(), owner.file_id);
97 Self::new(owner.value, &hygiene) 97 Self::new(owner.value, &hygiene)
98 } 98 }
@@ -178,7 +178,7 @@ impl Attrs {
178 Some(it) => { 178 Some(it) => {
179 let raw_attrs = RawAttrs::from_attrs_owner( 179 let raw_attrs = RawAttrs::from_attrs_owner(
180 db, 180 db,
181 it.as_ref().map(|it| it as &dyn AttrsOwner), 181 it.as_ref().map(|it| it as &dyn ast::AttrsOwner),
182 ); 182 );
183 match mod_data.definition_source(db) { 183 match mod_data.definition_source(db) {
184 InFile { file_id, value: ModuleSource::SourceFile(file) } => raw_attrs 184 InFile { file_id, value: ModuleSource::SourceFile(file) } => raw_attrs
@@ -189,9 +189,9 @@ impl Attrs {
189 None => RawAttrs::from_attrs_owner( 189 None => RawAttrs::from_attrs_owner(
190 db, 190 db,
191 mod_data.definition_source(db).as_ref().map(|src| match src { 191 mod_data.definition_source(db).as_ref().map(|src| match src {
192 ModuleSource::SourceFile(file) => file as &dyn AttrsOwner, 192 ModuleSource::SourceFile(file) => file as &dyn ast::AttrsOwner,
193 ModuleSource::Module(module) => module as &dyn AttrsOwner, 193 ModuleSource::Module(module) => module as &dyn ast::AttrsOwner,
194 ModuleSource::BlockExpr(block) => block as &dyn AttrsOwner, 194 ModuleSource::BlockExpr(block) => block as &dyn ast::AttrsOwner,
195 }), 195 }),
196 ), 196 ),
197 } 197 }
@@ -249,7 +249,7 @@ impl Attrs {
249 let mut res = ArenaMap::default(); 249 let mut res = ArenaMap::default();
250 250
251 for (id, var) in src.value.iter() { 251 for (id, var) in src.value.iter() {
252 let attrs = RawAttrs::from_attrs_owner(db, src.with_value(var as &dyn AttrsOwner)) 252 let attrs = RawAttrs::from_attrs_owner(db, src.with_value(var as &dyn ast::AttrsOwner))
253 .filter(db, krate); 253 .filter(db, krate);
254 254
255 res.insert(id, attrs) 255 res.insert(id, attrs)
@@ -283,7 +283,7 @@ impl Attrs {
283 /// Constructs a map that maps the lowered `Attr`s in this `Attrs` back to its original syntax nodes. 283 /// Constructs a map that maps the lowered `Attr`s in this `Attrs` back to its original syntax nodes.
284 /// 284 ///
285 /// `owner` must be the original owner of the attributes. 285 /// `owner` must be the original owner of the attributes.
286 pub fn source_map(&self, owner: &dyn AttrsOwner) -> AttrSourceMap { 286 pub fn source_map(&self, owner: &dyn ast::AttrsOwner) -> AttrSourceMap {
287 AttrSourceMap { attrs: collect_attrs(owner).collect() } 287 AttrSourceMap { attrs: collect_attrs(owner).collect() }
288 } 288 }
289 289
@@ -321,9 +321,7 @@ impl Attrs {
321 let mut buf = String::new(); 321 let mut buf = String::new();
322 for doc in docs { 322 for doc in docs {
323 // str::lines doesn't yield anything for the empty string 323 // str::lines doesn't yield anything for the empty string
324 if doc.is_empty() { 324 if !doc.is_empty() {
325 buf.push('\n');
326 } else {
327 buf.extend(Itertools::intersperse( 325 buf.extend(Itertools::intersperse(
328 doc.lines().map(|line| { 326 doc.lines().map(|line| {
329 line.char_indices() 327 line.char_indices()
@@ -436,7 +434,7 @@ impl Attr {
436 /// 434 ///
437 /// Note that the returned syntax node might be a `#[cfg_attr]`, or a doc comment, instead of 435 /// Note that the returned syntax node might be a `#[cfg_attr]`, or a doc comment, instead of
438 /// the attribute represented by `Attr`. 436 /// the attribute represented by `Attr`.
439 pub fn to_src(&self, owner: &dyn AttrsOwner) -> Either<ast::Attr, ast::Comment> { 437 pub fn to_src(&self, owner: &dyn ast::AttrsOwner) -> Either<ast::Attr, ast::Comment> {
440 collect_attrs(owner).nth(self.index as usize).unwrap_or_else(|| { 438 collect_attrs(owner).nth(self.index as usize).unwrap_or_else(|| {
441 panic!("cannot find `Attr` at index {} in {}", self.index, owner.syntax()) 439 panic!("cannot find `Attr` at index {} in {}", self.index, owner.syntax())
442 }) 440 })
@@ -528,7 +526,7 @@ where
528 N: ast::AttrsOwner, 526 N: ast::AttrsOwner,
529{ 527{
530 let src = InFile::new(src.file_id, src.to_node(db.upcast())); 528 let src = InFile::new(src.file_id, src.to_node(db.upcast()));
531 RawAttrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner)) 529 RawAttrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn ast::AttrsOwner))
532} 530}
533 531
534fn attrs_from_item_tree<N: ItemTreeNode>(id: ItemTreeId<N>, db: &dyn DefDatabase) -> RawAttrs { 532fn attrs_from_item_tree<N: ItemTreeNode>(id: ItemTreeId<N>, db: &dyn DefDatabase) -> RawAttrs {
@@ -537,7 +535,9 @@ fn attrs_from_item_tree<N: ItemTreeNode>(id: ItemTreeId<N>, db: &dyn DefDatabase
537 tree.raw_attrs(mod_item.into()).clone() 535 tree.raw_attrs(mod_item.into()).clone()
538} 536}
539 537
540fn collect_attrs(owner: &dyn AttrsOwner) -> impl Iterator<Item = Either<ast::Attr, ast::Comment>> { 538fn collect_attrs(
539 owner: &dyn ast::AttrsOwner,
540) -> impl Iterator<Item = Either<ast::Attr, ast::Comment>> {
541 let (inner_attrs, inner_docs) = inner_attributes(owner.syntax()) 541 let (inner_attrs, inner_docs) = inner_attributes(owner.syntax())
542 .map_or((None, None), |(attrs, docs)| ((Some(attrs), Some(docs)))); 542 .map_or((None, None), |(attrs, docs)| ((Some(attrs), Some(docs))));
543 543