Skip to content

[Draft] Supertrait item resolution in subtrait impls #143527

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dingxiangfei2009
Copy link
Contributor

r? @ghost

cc @cramertj @petrochenkov

This is pertaining to implementable trait aliases, Deref/Receiver trait migration and supertrait items in subtrait impls.

This is a draft for the resolver and crate metadata changes. Through this patch, the resolver will pick up supertrait items, collected from the trait super-bounds and trait alias in a future extension. This information will be encoded so that the resolver can resolve names in the downstream crates.

I would like to post this draft earlier because there are already significant design changes, which may warrant collecting opinions ahead of time.

Next steps would be

  • teach hir-analysis to collect associated items in subtrait items into implied supertrait impls;
  • adapt the syntax so that associated items can be paths instead of just identifies today, because associate items on paths is essential for the disambiguation of the design.

@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Jul 6, 2025
@rust-log-analyzer
Copy link
Collaborator

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
-    fn get_module_supertraits(self, id: DefIndex, sess: &'a Session) -> impl Iterator<Item = DefId> {
+    fn get_module_supertraits(
+        self,
+        id: DefIndex,
+        sess: &'a Session,
+    ) -> impl Iterator<Item = DefId> {
         let supertraits = self.root.tables.module_supertraits.get(self, id);
         supertraits.decode((self, sess)).into_iter()
     }
fmt: checked 6147 files
Build completed unsuccessfully in 0:00:44
  local time: Sun Jul  6 14:09:05 UTC 2025
  network time: Sun, 06 Jul 2025 14:09:06 GMT

@petrochenkov petrochenkov self-assigned this Jul 6, 2025
impl Sub for S {
//~^ ERROR: the trait bound `S: Sup` is not satisfied
type A = ();
//~^ ERROR: the trait bound `S: Sup` is not satisfied
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not the desired end game, yet. This is rather a demonstration that this patch allows name resolution to associate A with that from trait Sup correctly.

@dingxiangfei2009
Copy link
Contributor Author

dingxiangfei2009 commented Jul 7, 2025

cc @tmandry @tomassedovic

The patch is also to unblock arbitrary_self_types.

The next steps are

  • (before landing this patch) gate the supertrait behaviour behind #[rustc_supertrait_in_subtrait_impl]
  • Teach hir-analysis to generate an impl for supertraits
  • Mark Deref with a builtin attribute #[rustc_supertrait_in_subtrait_impl], move Target from Deref to Receiver
    • Test the set up with crater

@petrochenkov petrochenkov added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants