I'm not sure how to address this comment: https://github.com/rust-analyzer/rust-analyzer/pull/7062/files#r550238723. Could someone please point me in the right direction. I can use self.infer.method_resolution to get hold of a FunctionId for the method being called (e.g. filter_map) and Resolver::resolve_known_trait to get hold of a TraitId for std::iter::Iterator, but I'm not sure what I can do to relate the two (i.e. how to conclude that this FunctionId is for a method on the iterator trait identified by TraitId).
FunctionId, you can do
id.lookup(db.upcast()).container to get the container, which you can then check whether it's equal to
AssocContainerId::TraitId(iterator_trait_id) to see whether it's a method from Iterator
I wish there was a more straightforward way to do that in the HIR crates (in code_model, it's easier)
Thanks! I'll give this a go.
alternatively, you could do
db.trait_data(trait_id).items.get(name![filter_map]) to get the method by name
This turned out to be surprisingly easy! https://github.com/rust-analyzer/rust-analyzer/pull/7062/commits/b667328e74859dd1b5c1dd9a48c97f5f58277d3c