rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.32k stars 1.61k forks source link

internal: Add public `direct_supertraits(…)` & `all_supertraits(…)` accessor methods to `hir::Trait` #18482

Closed regexident closed 1 week ago

regexident commented 2 weeks ago

Hi @Veykril,

I need to access a trait's supertraits (as external user of ra_ap's APIs) and while hir_ty::all_super_traits() already provides such capabilities to a limited degree I'd like to propose the following accessors on hir::Trait itself, it only does provide access to the entire trait hierarchy (while I only want the direct supertraits) and requires a descent into hir_ty land. I'd thus like to propose adding the following methods: hir::Trait::direct_supertraits(db) & hir::Trait::all_supertraits(db).


There seems to be some naming inconsistency with regard to supertrait (43 occurrences) vs. super_trait (53 occurrences) in the codebase. (I'd be happy to open a follow-up PR unifying the project-wide naming, if so desired.) I went with supertraits in this PR since that's what the already existing hir::Trait::items_with_supertraits(…) uses in close proximity to the newly added methods.