Skip to content

Commit

Permalink
Add tests for #57994
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Aug 4, 2023
1 parent 6d11b2f commit f7486ff
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// run-rustfix
#![allow(dead_code)]
mod first {
trait Foo { fn m(self: Box<Self>); }
fn foo<T: Foo>(a: T) {
Box::new(a).m(); //~ ERROR no method named `m` found
}
}
mod second {
use std::sync::Arc;
trait Bar { fn m(self: Arc<Self>); }
fn bar(b: impl Bar) {
Arc::new(b).m(); //~ ERROR no method named `m` found
}
}

fn main() {}
17 changes: 17 additions & 0 deletions tests/ui/self/arbitrary_self_types_needing_box_or_arc_wrapping.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// run-rustfix
#![allow(dead_code)]
mod first {
trait Foo { fn m(self: Box<Self>); }
fn foo<T: Foo>(a: T) {
a.m(); //~ ERROR no method named `m` found
}
}
mod second {
use std::sync::Arc;
trait Bar { fn m(self: Arc<Self>); }
fn bar(b: impl Bar) {
b.m(); //~ ERROR no method named `m` found
}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
error[E0599]: no method named `m` found for type parameter `T` in the current scope
--> $DIR/arbitrary_self_types_needing_box_or_arc_wrapping.rs:6:11
|
LL | trait Foo { fn m(self: Box<Self>); }
| - --------- the method might not be found because of this arbitrary self type
| |
| the method is available for `Box<T>` here
LL | fn foo<T: Foo>(a: T) {
| - method `m` not found for this type parameter
LL | a.m();
| ^ method not found in `T`
...
LL | trait Bar { fn m(self: Arc<Self>); }
| --------- the method might not be found because of this arbitrary self type
|
help: consider wrapping the receiver expression with the appropriate type
|
LL | Box::new(a).m();
| +++++++++ +

error[E0599]: no method named `m` found for type parameter `impl Bar` in the current scope
--> $DIR/arbitrary_self_types_needing_box_or_arc_wrapping.rs:13:11
|
LL | trait Foo { fn m(self: Box<Self>); }
| --------- the method might not be found because of this arbitrary self type
...
LL | trait Bar { fn m(self: Arc<Self>); }
| - --------- the method might not be found because of this arbitrary self type
| |
| the method is available for `Arc<impl Bar>` here
LL | fn bar(b: impl Bar) {
| -------- method `m` not found for this type parameter
LL | b.m();
| ^ method not found in `impl Bar`
|
help: consider wrapping the receiver expression with the appropriate type
|
LL | Arc::new(b).m();
| +++++++++ +

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0599`.
12 changes: 12 additions & 0 deletions tests/ui/self/arbitrary_self_types_needing_mut_pin.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// run-rustfix
use std::pin::Pin;
struct S;

impl S {
fn x(self: Pin<&mut Self>) {
}
}

fn main() {
Pin::new(&mut S).x(); //~ ERROR no method named `x` found
}
12 changes: 12 additions & 0 deletions tests/ui/self/arbitrary_self_types_needing_mut_pin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// run-rustfix
use std::pin::Pin;
struct S;

impl S {
fn x(self: Pin<&mut Self>) {
}
}

fn main() {
S.x(); //~ ERROR no method named `x` found
}
20 changes: 20 additions & 0 deletions tests/ui/self/arbitrary_self_types_needing_mut_pin.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error[E0599]: no method named `x` found for struct `S` in the current scope
--> $DIR/arbitrary_self_types_needing_mut_pin.rs:11:7
|
LL | struct S;
| -------- method `x` not found for this struct
...
LL | fn x(self: Pin<&mut Self>) {
| - the method is available for `Pin<&mut S>` here
...
LL | S.x();
| ^ method not found in `S`
|
help: consider wrapping the receiver expression with the appropriate type
|
LL | Pin::new(&mut S).x();
| +++++++++++++ +

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.
13 changes: 13 additions & 0 deletions tests/ui/self/arbitrary_self_types_pin_needing_borrow.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use std::pin::Pin;
struct S;

impl S {
fn x(self: Pin<&mut Self>) {
}
}

fn main() {
Pin::new(S).x();
//~^ ERROR the trait bound `S: Deref` is not satisfied
//~| ERROR no method named `x` found for struct `Pin` in the current scope
}
33 changes: 33 additions & 0 deletions tests/ui/self/arbitrary_self_types_pin_needing_borrow.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
error[E0277]: the trait bound `S: Deref` is not satisfied
--> $DIR/arbitrary_self_types_pin_needing_borrow.rs:10:14
|
LL | Pin::new(S).x();
| -------- ^ the trait `Deref` is not implemented for `S`
| |
| required by a bound introduced by this call
|
note: required by a bound in `Pin::<P>::new`
--> $SRC_DIR/core/src/pin.rs:LL:COL
help: consider borrowing here
|
LL | Pin::new(&S).x();
| +
LL | Pin::new(&mut S).x();
| ++++

error[E0599]: no method named `x` found for struct `Pin` in the current scope
--> $DIR/arbitrary_self_types_pin_needing_borrow.rs:10:17
|
LL | Pin::new(S).x();
| ^ method not found in `Pin<S>`
|
note: method is available for `Pin<&mut S>`
--> $DIR/arbitrary_self_types_pin_needing_borrow.rs:5:5
|
LL | fn x(self: Pin<&mut Self>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.

0 comments on commit f7486ff

Please sign in to comment.