diff options
| author | Adrian Taylor <adetaylor@chromium.org> | 2024-12-13 15:40:37 +0000 |
|---|---|---|
| committer | Adrian Taylor <adetaylor@chromium.org> | 2024-12-13 15:40:37 +0000 |
| commit | 174dae607c40ca65f5589b22062775a95846f12d (patch) | |
| tree | 29c6f30703998c8a1375988a1a0927def6a72885 /compiler/rustc_hir_analysis | |
| parent | dd436ae2a628c523c967a7876873a96c44b1e382 (diff) | |
| download | rust-174dae607c40ca65f5589b22062775a95846f12d.tar.gz rust-174dae607c40ca65f5589b22062775a95846f12d.zip | |
Arbitrary self types v2: adjust diagnostic.
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.
Diffstat (limited to 'compiler/rustc_hir_analysis')
| -rw-r--r-- | compiler/rustc_hir_analysis/messages.ftl | 6 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/check/wfcheck.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/errors.rs | 10 |
3 files changed, 23 insertions, 1 deletions
diff --git a/compiler/rustc_hir_analysis/messages.ftl b/compiler/rustc_hir_analysis/messages.ftl index 25feb95d5df..a2df0ba265c 100644 --- a/compiler/rustc_hir_analysis/messages.ftl +++ b/compiler/rustc_hir_analysis/messages.ftl @@ -246,6 +246,12 @@ hir_analysis_invalid_receiver_ty = invalid `self` parameter type: `{$receiver_ty hir_analysis_invalid_receiver_ty_help = consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box<Self>`, `self: Rc<Self>`, or `self: Arc<Self>` +hir_analysis_invalid_receiver_ty_help_no_arbitrary_self_types = + consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`) + +hir_analysis_invalid_receiver_ty_no_arbitrary_self_types = invalid `self` parameter type: `{$receiver_ty}` + .note = type of `self` must be `Self` or a type that dereferences to it + hir_analysis_invalid_union_field = field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union .note = union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>` diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 57264d0bd2a..e6ef29de965 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1748,9 +1748,15 @@ fn check_method_receiver<'tcx>( // Report error; would not have worked with `arbitrary_self_types[_pointers]`. { match receiver_validity_err { - ReceiverValidityError::DoesNotDeref => { + ReceiverValidityError::DoesNotDeref if arbitrary_self_types_level.is_some() => { tcx.dcx().emit_err(errors::InvalidReceiverTy { span, receiver_ty }) } + ReceiverValidityError::DoesNotDeref => { + tcx.dcx().emit_err(errors::InvalidReceiverTyNoArbitrarySelfTypes { + span, + receiver_ty, + }) + } ReceiverValidityError::MethodGenericParamUsed => { tcx.dcx().emit_err(errors::InvalidGenericReceiverTy { span, receiver_ty }) } diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index 7f62ccc91f0..5ab6faf3b7c 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -1656,6 +1656,16 @@ pub(crate) struct NonConstRange { } #[derive(Diagnostic)] +#[diag(hir_analysis_invalid_receiver_ty_no_arbitrary_self_types, code = E0307)] +#[note] +#[help(hir_analysis_invalid_receiver_ty_help_no_arbitrary_self_types)] +pub(crate) struct InvalidReceiverTyNoArbitrarySelfTypes<'tcx> { + #[primary_span] + pub span: Span, + pub receiver_ty: Ty<'tcx>, +} + +#[derive(Diagnostic)] #[diag(hir_analysis_invalid_receiver_ty, code = E0307)] #[note] #[help(hir_analysis_invalid_receiver_ty_help)] |
