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

Arbitrary self types v2: Weak & NonNull diagnostics #134264

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

adetaylor
Copy link
Contributor

This builds on top of #134262 which is more urgent to review and merge first. I'll likely rebase this PR once that lands.

This is the first part of the diagnostic enhancements planned for Arbitrary Self Types v2.

Various types can be used as method receivers, such as Rc<>, Box<> and Arc<>. The arbitrary self types v2 work allows further types to be made method receivers by implementing the Receiver trait.

With that in mind, it may come as a surprise to people when certain common types do not implement Receiver and thus cannot be used as a method receiver.

The RFC for arbitrary self types v2 therefore proposes emitting specific
lint hints for these cases:

  • NonNull
  • Weak
  • Raw pointers

The code already emits a hint for this third case, in that it advises folks that the arbitrary_self_types_pointers feature may meet their need. This PR adds diagnostic hints for the Weak and NonNull cases.

Tracking issue #44874

r? @wesleywiser

The recently landed PR to adjust arbitrary self types was a bit
overenthusiastic, advising folks to use the new Receiver trait even
before it's been stabilized. Revert to the older wording of the lint in
such cases.
@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 Dec 13, 2024
@adetaylor adetaylor changed the title Arbitrary self types v2: Weak Arbitrary self types v2: Weak & NonNull diagnostics Dec 13, 2024
@@ -1749,7 +1750,20 @@ fn check_method_receiver<'tcx>(
{
match receiver_validity_err {
ReceiverValidityError::DoesNotDeref if arbitrary_self_types_level.is_some() => {
tcx.dcx().emit_err(errors::InvalidReceiverTy { span, receiver_ty })
let hint = match receiver_ty
.ty_def_id()
Copy link
Member

@compiler-errors compiler-errors Dec 13, 2024

Choose a reason for hiding this comment

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

don't use this, it's an internal detail of the query system. use Ty::ty_adt_def to check that it's an adt.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks - will do

@compiler-errors

This comment was marked as duplicate.

@rustbot

This comment was marked as duplicate.

@compiler-errors
Copy link
Member

r? compiler-errors

@compiler-errors
Copy link
Member

maybe worth providing some background in the note to explain why Weak and NonNull don't implement Receiver, since i assume some people's first reaction after reading:

Weak does not implement Receiver

would be "ok, why don't I just suggest adding an impl to libstd?"

@rust-log-analyzer

This comment has been minimized.

Various types can be used as method receivers, such as Rc<>, Box<> and
Arc<>. The arbitrary self types v2 work allows further types to be made
method receivers by implementing the Receiver trait.

With that in mind, it may come as a surprise to people when certain
common types do not implement Receiver and thus cannot be used as a
method receiver.

The RFC for arbitrary self types v2 therefore proposes emitting specific
lint hints for these cases:
* NonNull
* Weak
* Raw pointers

The code already emits a hint for this third case, in that it advises
folks that the `arbitrary_self_types_pointers` feature may meet their
need. This PR adds diagnostic hints for the Weak and NonNull cases.
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants