Skip to content

Add more context to dyn-compatibility diagnostic for receiver-less associated functions - #160428

Open
xyz-harshal wants to merge 1 commit into
rust-lang:mainfrom
xyz-harshal:fix-dyn-compat-diagnostic-159492
Open

Add more context to dyn-compatibility diagnostic for receiver-less associated functions#160428
xyz-harshal wants to merge 1 commit into
rust-lang:mainfrom
xyz-harshal:fix-dyn-compat-diagnostic-159492

Conversation

@xyz-harshal

@xyz-harshal xyz-harshal commented Aug 3, 2026

Copy link
Copy Markdown

Fixes #159492

Expands the two suggestion messages for the "no self parameter"
dyn-compatibility violation to explain why each fix works, per the issue.

Before:
help: consider turning create into a method by giving it a &self argument
help: alternatively, consider constraining create so it does not apply to trait objects

After:
help: consider turning create into a method by giving it a &self argument, so that it is accessible through the trait object's vtable
help: alternatively, consider constraining create so it is explicitly marked as not applying to trait objects

Only the two strings in DynCompatibilityViolationSolution::add_to
(rustc_middle/src/traits/mod.rs) changed — no logic, applicability, or span changes.

Added a regression test using the issue's exact example
(tests/ui/dyn-compatibility/static-constructor-prevents-dyn-no-api-guidance.rs).

Verified against a locally-built rustc; full tests/ui suite passes
(21643 passed, 0 failed). Note: next-solver compare-mode has pre-existing,
unrelated failures on 3 tests in this directory, confirmed present on main
without this diff.

…sociated functions

Explains that a method without `self` cannot be dispatched through
a trait object's vtable, and that `where Self: Sized` explicitly
opts a method out of dyn-compatibility requirements.

Fixes rust-lang#159492
Copilot AI review requested due to automatic review settings August 3, 2026 10:28
@rustbot rustbot added 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. labels Aug 3, 2026
@rustbot

rustbot commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @khyperia (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
Why was this reviewer chosen?

The reviewer was selected based on:

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

@rustbot

rustbot commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

This comment was marked as low quality.

@josetorrs

Copy link
Copy Markdown
Contributor

Was Copilot manually invoked?

@xyz-harshal

Copy link
Copy Markdown
Author

Was Copilot manually invoked?

Nope.

@khyperia

khyperia commented Aug 4, 2026

Copy link
Copy Markdown
Member

thank you for the PR!

please follow the advice given by rustbot about the commit message, thanks ❤️

out of curiosity, did you write entirety of the PR description yourself, or was an LLM used in any part of the writing process?

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 4, 2026
@rustbot

rustbot commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

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

@apiraino

apiraino commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

hey @xyz-harshal

as per our LLM policy, please disable Copilot in your GitHub settings and don't trigger unprompted reviews from bots in our repository.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Be more pedagogic on why assoc fns without receiver aren't dyn-safe

6 participants