Skip to content

Implement derives for Reborrow and CoerceShared#156338

Open
P8L1 wants to merge 1 commit intorust-lang:mainfrom
P8L1:derive-reborrow-coerce-shared
Open

Implement derives for Reborrow and CoerceShared#156338
P8L1 wants to merge 1 commit intorust-lang:mainfrom
P8L1:derive-reborrow-coerce-shared

Conversation

@P8L1
Copy link
Copy Markdown
Contributor

@P8L1 P8L1 commented May 8, 2026

This adds built-in derive support for the experimental Reborrow and CoerceShared marker traits behind #![feature(reborrow)].

The derives generate the same marker impls users would write manually, while preserving the existing coherence and structural validation path for the experimental reborrow traits.

Please note this impl:

  • Preserves generics, lifetimes, const params, and where clauses in generated impls.
  • Preserves multiple lifetime parameters in generated impls instead of duplicating the current experimental one-lifetime limitation in the derive layer.
  • Requires an explicit CoerceShared target type through the derive helper attribute.
  • Adds UI coverage for valid derives, feature gating, malformed helper attributes, unsupported item kinds, validation failures, and multiple-lifetime derive behavior.
  • Makes the derive layer future-proof for multiple lifetimes: it preserves all lifetime parameters and generates the same impl shape as a manual impl.

Part of #145612
Part of rust-lang/rust-project-goals#399

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 8, 2026

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 8, 2026
@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. labels May 8, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 8, 2026

r? @tiif

rustbot has assigned @tiif.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 18 candidates

@rust-log-analyzer

This comment has been minimized.

@P8L1 P8L1 force-pushed the derive-reborrow-coerce-shared branch 2 times, most recently from c515771 to 1a83d37 Compare May 8, 2026 19:01
@rust-log-analyzer

This comment has been minimized.

@P8L1 P8L1 force-pushed the derive-reborrow-coerce-shared branch from 1a83d37 to 8e2ead2 Compare May 8, 2026 20:06
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

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

Please separate the rust-analyzer changes to a new PR in the rust-analyzer repo, there is no reason for them to be here.

View changes since this review

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 9, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 9, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 9, 2026
@P8L1 P8L1 force-pushed the derive-reborrow-coerce-shared branch from 8e2ead2 to 0d49f18 Compare May 9, 2026 20:18
@P8L1
Copy link
Copy Markdown
Contributor Author

P8L1 commented May 9, 2026

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 9, 2026
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants