Skip to content

Commit f7486ff

Browse files
committed
Add tests for #57994
1 parent 6d11b2f commit f7486ff

8 files changed

+167
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// run-rustfix
2+
#![allow(dead_code)]
3+
mod first {
4+
trait Foo { fn m(self: Box<Self>); }
5+
fn foo<T: Foo>(a: T) {
6+
Box::new(a).m(); //~ ERROR no method named `m` found
7+
}
8+
}
9+
mod second {
10+
use std::sync::Arc;
11+
trait Bar { fn m(self: Arc<Self>); }
12+
fn bar(b: impl Bar) {
13+
Arc::new(b).m(); //~ ERROR no method named `m` found
14+
}
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// run-rustfix
2+
#![allow(dead_code)]
3+
mod first {
4+
trait Foo { fn m(self: Box<Self>); }
5+
fn foo<T: Foo>(a: T) {
6+
a.m(); //~ ERROR no method named `m` found
7+
}
8+
}
9+
mod second {
10+
use std::sync::Arc;
11+
trait Bar { fn m(self: Arc<Self>); }
12+
fn bar(b: impl Bar) {
13+
b.m(); //~ ERROR no method named `m` found
14+
}
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
error[E0599]: no method named `m` found for type parameter `T` in the current scope
2+
--> $DIR/arbitrary_self_types_needing_box_or_arc_wrapping.rs:6:11
3+
|
4+
LL | trait Foo { fn m(self: Box<Self>); }
5+
| - --------- the method might not be found because of this arbitrary self type
6+
| |
7+
| the method is available for `Box<T>` here
8+
LL | fn foo<T: Foo>(a: T) {
9+
| - method `m` not found for this type parameter
10+
LL | a.m();
11+
| ^ method not found in `T`
12+
...
13+
LL | trait Bar { fn m(self: Arc<Self>); }
14+
| --------- the method might not be found because of this arbitrary self type
15+
|
16+
help: consider wrapping the receiver expression with the appropriate type
17+
|
18+
LL | Box::new(a).m();
19+
| +++++++++ +
20+
21+
error[E0599]: no method named `m` found for type parameter `impl Bar` in the current scope
22+
--> $DIR/arbitrary_self_types_needing_box_or_arc_wrapping.rs:13:11
23+
|
24+
LL | trait Foo { fn m(self: Box<Self>); }
25+
| --------- the method might not be found because of this arbitrary self type
26+
...
27+
LL | trait Bar { fn m(self: Arc<Self>); }
28+
| - --------- the method might not be found because of this arbitrary self type
29+
| |
30+
| the method is available for `Arc<impl Bar>` here
31+
LL | fn bar(b: impl Bar) {
32+
| -------- method `m` not found for this type parameter
33+
LL | b.m();
34+
| ^ method not found in `impl Bar`
35+
|
36+
help: consider wrapping the receiver expression with the appropriate type
37+
|
38+
LL | Arc::new(b).m();
39+
| +++++++++ +
40+
41+
error: aborting due to 2 previous errors
42+
43+
For more information about this error, try `rustc --explain E0599`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// run-rustfix
2+
use std::pin::Pin;
3+
struct S;
4+
5+
impl S {
6+
fn x(self: Pin<&mut Self>) {
7+
}
8+
}
9+
10+
fn main() {
11+
Pin::new(&mut S).x(); //~ ERROR no method named `x` found
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// run-rustfix
2+
use std::pin::Pin;
3+
struct S;
4+
5+
impl S {
6+
fn x(self: Pin<&mut Self>) {
7+
}
8+
}
9+
10+
fn main() {
11+
S.x(); //~ ERROR no method named `x` found
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0599]: no method named `x` found for struct `S` in the current scope
2+
--> $DIR/arbitrary_self_types_needing_mut_pin.rs:11:7
3+
|
4+
LL | struct S;
5+
| -------- method `x` not found for this struct
6+
...
7+
LL | fn x(self: Pin<&mut Self>) {
8+
| - the method is available for `Pin<&mut S>` here
9+
...
10+
LL | S.x();
11+
| ^ method not found in `S`
12+
|
13+
help: consider wrapping the receiver expression with the appropriate type
14+
|
15+
LL | Pin::new(&mut S).x();
16+
| +++++++++++++ +
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0599`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use std::pin::Pin;
2+
struct S;
3+
4+
impl S {
5+
fn x(self: Pin<&mut Self>) {
6+
}
7+
}
8+
9+
fn main() {
10+
Pin::new(S).x();
11+
//~^ ERROR the trait bound `S: Deref` is not satisfied
12+
//~| ERROR no method named `x` found for struct `Pin` in the current scope
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error[E0277]: the trait bound `S: Deref` is not satisfied
2+
--> $DIR/arbitrary_self_types_pin_needing_borrow.rs:10:14
3+
|
4+
LL | Pin::new(S).x();
5+
| -------- ^ the trait `Deref` is not implemented for `S`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
note: required by a bound in `Pin::<P>::new`
10+
--> $SRC_DIR/core/src/pin.rs:LL:COL
11+
help: consider borrowing here
12+
|
13+
LL | Pin::new(&S).x();
14+
| +
15+
LL | Pin::new(&mut S).x();
16+
| ++++
17+
18+
error[E0599]: no method named `x` found for struct `Pin` in the current scope
19+
--> $DIR/arbitrary_self_types_pin_needing_borrow.rs:10:17
20+
|
21+
LL | Pin::new(S).x();
22+
| ^ method not found in `Pin<S>`
23+
|
24+
note: method is available for `Pin<&mut S>`
25+
--> $DIR/arbitrary_self_types_pin_needing_borrow.rs:5:5
26+
|
27+
LL | fn x(self: Pin<&mut Self>) {
28+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
29+
30+
error: aborting due to 2 previous errors
31+
32+
Some errors have detailed explanations: E0277, E0599.
33+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)