Stream: t-compiler/rust-analyzer

Topic: Hir: Traversing "scope" items up to the crate root.


popzxc (Oct 31 2020 at 18:40, on Zulip):

I'm currently working on a way to look up item attributes applied to the code item, including ones derived from the parent items.
Short-term goal is to check for allow(..) attributes in items case diagnostic, but the long-term goal is to provide an interface to make this kind of information to any hir item that needs it.

So far I'm struggling with finding a way to find a next parent item which has attributes, e.g. `function -> function -> impl block -> mod -> mod -> crate root".

Code example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=259aadbe3bd5af7344c3c37302ae2d27

In this example, given the InnerData structure ID, I would want to sequentially get the IDs of the following items: inner_foo -> foo -> impl Data -> b -> a -> crate root.
And of course, this structure can be split over multiple files, if that's important.

Ideally, I would want to be able to do the least possible amount of work getting the parent, so that traversal could be efficiently finished once required item is found.

Do you have any hints how to achieve this (or at least direction to think in)?

Last update: Jul 26 2021 at 14:00UTC