Add more context to dyn-compatibility diagnostic for receiver-less associated functions - #160428
Add more context to dyn-compatibility diagnostic for receiver-less associated functions#160428xyz-harshal wants to merge 1 commit into
Conversation
…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
|
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 (
Why was this reviewer chosen?The reviewer was selected based on:
|
|
|
Was Copilot manually invoked? |
Nope. |
|
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 |
|
Reminder, once the PR becomes ready for a review, use |
|
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 |
Fixes #159492
Expands the two suggestion messages for the "no
selfparameter"dyn-compatibility violation to explain why each fix works, per the issue.
Before:
help: consider turning
createinto a method by giving it a&selfargumenthelp: alternatively, consider constraining
createso it does not apply to trait objectsAfter:
help: consider turning
createinto a method by giving it a&selfargument, so that it is accessible through the trait object's vtablehelp: alternatively, consider constraining
createso it is explicitly marked as not applying to trait objectsOnly 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/uisuite passes(21643 passed, 0 failed). Note:
next-solvercompare-mode has pre-existing,unrelated failures on 3 tests in this directory, confirmed present on
mainwithout this diff.