Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Nov 11, 2024

Conversation

regexident
Copy link
Contributor

@regexident regexident commented Nov 6, 2024

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.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 6, 2024
@@ -43,6 +43,17 @@ pub(crate) fn fn_traits(
.flat_map(|it| it.as_trait())
}

/// Returns an iterator over the direct super traits (including the trait itself).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Iterator" 😆

(I know, all_super_traits says the same thing)

@lnicola lnicola changed the title Add public direct_supertraits(…) & all_supertraits(…) accessor methods to hir::Trait internal: Add public direct_supertraits(…) & all_supertraits(…) accessor methods to hir::Trait Nov 11, 2024
@lnicola lnicola added this pull request to the merge queue Nov 11, 2024
Merged via the queue into rust-lang:master with commit aabab29 Nov 11, 2024
9 checks passed
@regexident regexident deleted the hir_trait_supertraits_accessors branch November 11, 2024 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants