Skip to content

Commit 988a4ba

Browse files
Rollup merge of rust-lang#62712 - limira:self-type-help, r=estebank
Update the help message on error for self type Fix rust-lang#62609
2 parents df21a6f + b7cbd4e commit 988a4ba

File tree

6 files changed

+18
-14
lines changed

6 files changed

+18
-14
lines changed

src/librustc_typeck/check/wfcheck.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,10 @@ fn check_method_receiver<'fcx, 'tcx>(
769769
method: &ty::AssocItem,
770770
self_ty: Ty<'tcx>,
771771
) {
772+
const HELP_FOR_SELF_TYPE: &str =
773+
"consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, \
774+
`self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one \
775+
of the previous types except `Self`)";
772776
// Check that the method has a valid receiver type, given the type `Self`.
773777
debug!("check_method_receiver({:?}, self_ty={:?})",
774778
method, self_ty);
@@ -805,7 +809,7 @@ fn check_method_receiver<'fcx, 'tcx>(
805809
fcx.tcx.sess.diagnostic().mut_span_err(
806810
span, &format!("invalid method receiver type: {:?}", receiver_ty)
807811
).note("type of `self` must be `Self` or a type that dereferences to it")
808-
.help("consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`")
812+
.help(HELP_FOR_SELF_TYPE)
809813
.code(DiagnosticId::Error("E0307".into()))
810814
.emit();
811815
}
@@ -823,14 +827,14 @@ fn check_method_receiver<'fcx, 'tcx>(
823827
the `arbitrary_self_types` feature",
824828
receiver_ty,
825829
),
826-
).help("consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`")
830+
).help(HELP_FOR_SELF_TYPE)
827831
.emit();
828832
} else {
829833
// Report error; would not have worked with `arbitrary_self_types`.
830834
fcx.tcx.sess.diagnostic().mut_span_err(
831835
span, &format!("invalid method receiver type: {:?}", receiver_ty)
832836
).note("type must be `Self` or a type that dereferences to it")
833-
.help("consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`")
837+
.help(HELP_FOR_SELF_TYPE)
834838
.code(DiagnosticId::Error("E0307".into()))
835839
.emit();
836840
}

src/test/ui/feature-gates/feature-gate-arbitrary-self-types.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | fn foo(self: Ptr<Self>);
66
|
77
= note: for more information, see https://github.com/rust-lang/rust/issues/44874
88
= help: add `#![feature(arbitrary_self_types)]` to the crate attributes to enable
9-
= help: consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`
9+
= help: 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`)
1010

1111
error[E0658]: `Ptr<Bar>` cannot be used as the type of `self` without the `arbitrary_self_types` feature
1212
--> $DIR/feature-gate-arbitrary-self-types.rs:22:18
@@ -16,7 +16,7 @@ LL | fn foo(self: Ptr<Self>) {}
1616
|
1717
= note: for more information, see https://github.com/rust-lang/rust/issues/44874
1818
= help: add `#![feature(arbitrary_self_types)]` to the crate attributes to enable
19-
= help: consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`
19+
= help: 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`)
2020

2121
error[E0658]: `std::boxed::Box<Ptr<Bar>>` cannot be used as the type of `self` without the `arbitrary_self_types` feature
2222
--> $DIR/feature-gate-arbitrary-self-types.rs:26:18
@@ -26,7 +26,7 @@ LL | fn bar(self: Box<Ptr<Self>>) {}
2626
|
2727
= note: for more information, see https://github.com/rust-lang/rust/issues/44874
2828
= help: add `#![feature(arbitrary_self_types)]` to the crate attributes to enable
29-
= help: consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`
29+
= help: 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`)
3030

3131
error: aborting due to 3 previous errors
3232

src/test/ui/feature-gates/feature-gate-arbitrary_self_types-raw-pointer.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | fn bar(self: *const Self);
66
|
77
= note: for more information, see https://github.com/rust-lang/rust/issues/44874
88
= help: add `#![feature(arbitrary_self_types)]` to the crate attributes to enable
9-
= help: consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`
9+
= help: 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`)
1010

1111
error[E0658]: `*const Foo` cannot be used as the type of `self` without the `arbitrary_self_types` feature
1212
--> $DIR/feature-gate-arbitrary_self_types-raw-pointer.rs:4:18
@@ -16,7 +16,7 @@ LL | fn foo(self: *const Self) {}
1616
|
1717
= note: for more information, see https://github.com/rust-lang/rust/issues/44874
1818
= help: add `#![feature(arbitrary_self_types)]` to the crate attributes to enable
19-
= help: consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`
19+
= help: 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`)
2020

2121
error[E0658]: `*const ()` cannot be used as the type of `self` without the `arbitrary_self_types` feature
2222
--> $DIR/feature-gate-arbitrary_self_types-raw-pointer.rs:14:18
@@ -26,7 +26,7 @@ LL | fn bar(self: *const Self) {}
2626
|
2727
= note: for more information, see https://github.com/rust-lang/rust/issues/44874
2828
= help: add `#![feature(arbitrary_self_types)]` to the crate attributes to enable
29-
= help: consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`
29+
= help: 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`)
3030

3131
error: aborting due to 3 previous errors
3232

src/test/ui/issues/issue-56806.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn dyn_instead_of_self(self: Box<dyn Trait>);
55
| ^^^^^^^^^^^^^^
66
|
77
= note: type must be `Self` or a type that dereferences to it
8-
= help: consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`
8+
= help: 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`)
99

1010
error: aborting due to previous error
1111

src/test/ui/span/issue-27522.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn handler(self: &SomeType);
55
| ^^^^^^^^^
66
|
77
= note: type must be `Self` or a type that dereferences to it
8-
= help: consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`
8+
= help: 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`)
99

1010
error: aborting due to previous error
1111

src/test/ui/ufcs/ufcs-explicit-self-bad.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn foo(self: isize, x: isize) -> isize {
55
| ^^^^^
66
|
77
= note: type must be `Self` or a type that dereferences to it
8-
= help: consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`
8+
= help: 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`)
99

1010
error[E0307]: invalid method receiver type: Bar<isize>
1111
--> $DIR/ufcs-explicit-self-bad.rs:19:18
@@ -14,7 +14,7 @@ LL | fn foo(self: Bar<isize>, x: isize) -> isize {
1414
| ^^^^^^^^^^
1515
|
1616
= note: type must be `Self` or a type that dereferences to it
17-
= help: consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`
17+
= help: 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`)
1818

1919
error[E0307]: invalid method receiver type: &Bar<usize>
2020
--> $DIR/ufcs-explicit-self-bad.rs:23:18
@@ -23,7 +23,7 @@ LL | fn bar(self: &Bar<usize>, x: isize) -> isize {
2323
| ^^^^^^^^^^^
2424
|
2525
= note: type must be `Self` or a type that dereferences to it
26-
= help: consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`
26+
= help: 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`)
2727

2828
error[E0308]: mismatched method receiver
2929
--> $DIR/ufcs-explicit-self-bad.rs:37:21

0 commit comments

Comments
 (0)