Skip to content

Commit 31271ed

Browse files
committed
Add some tests
1 parent d808395 commit 31271ed

10 files changed

+249
-0
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
trait Trait {}
2+
3+
impl Trait for u32 {}
4+
5+
struct Bar<T>(T);
6+
7+
impl Bar<u32> {
8+
fn foo(self) {}
9+
}
10+
11+
fn foo(x: bool) -> Bar<impl Sized> {
12+
//~^ ERROR: cycle detected
13+
if x {
14+
let x = foo(false);
15+
x.foo();
16+
//~^ ERROR: no method named `foo` found
17+
}
18+
todo!()
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
error[E0599]: no method named `foo` found for struct `Bar<impl Sized>` in the current scope
2+
--> $DIR/method-resolution.rs:15:11
3+
|
4+
LL | struct Bar<T>(T);
5+
| ------------- method `foo` not found for this struct
6+
...
7+
LL | x.foo();
8+
| ^^^ method not found in `Bar<impl Sized>`
9+
|
10+
= note: the method was found for
11+
- `Bar<u32>`
12+
13+
error[E0391]: cycle detected when computing type of opaque `foo::{opaque#0}`
14+
--> $DIR/method-resolution.rs:11:24
15+
|
16+
LL | fn foo(x: bool) -> Bar<impl Sized> {
17+
| ^^^^^^^^^^
18+
|
19+
note: ...which requires type-checking `foo`...
20+
--> $DIR/method-resolution.rs:15:9
21+
|
22+
LL | x.foo();
23+
| ^
24+
= note: ...which requires evaluating trait selection obligation `Bar<foo::{opaque#0}>: core::marker::Unpin`...
25+
= note: ...which again requires computing type of opaque `foo::{opaque#0}`, completing the cycle
26+
note: cycle used when computing type of `foo::{opaque#0}`
27+
--> $DIR/method-resolution.rs:11:24
28+
|
29+
LL | fn foo(x: bool) -> Bar<impl Sized> {
30+
| ^^^^^^^^^^
31+
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
32+
33+
error: aborting due to 2 previous errors
34+
35+
Some errors have detailed explanations: E0391, E0599.
36+
For more information about an error, try `rustc --explain E0391`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
type Foo = impl Sized;
4+
5+
struct Bar<T>(T);
6+
7+
impl Bar<Foo> {
8+
fn bar(self) {}
9+
}
10+
11+
impl Bar<u32> {
12+
fn foo(self) {
13+
self.bar()
14+
//~^ ERROR: no method named `bar`
15+
}
16+
}
17+
18+
fn foo() -> Foo {
19+
42_u32
20+
}
21+
22+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0599]: no method named `bar` found for struct `Bar<u32>` in the current scope
2+
--> $DIR/method_resolution.rs:13:14
3+
|
4+
LL | struct Bar<T>(T);
5+
| ------------- method `bar` not found for this struct
6+
...
7+
LL | self.bar()
8+
| ^^^ method not found in `Bar<u32>`
9+
|
10+
= note: the method was found for
11+
- `Bar<Foo>`
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0599`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
type Foo = impl Sized;
4+
//~^ ERROR: cycle
5+
6+
struct Bar<T>(T);
7+
8+
impl Bar<Foo> {
9+
fn bar(self) {
10+
self.foo()
11+
//~^ ERROR: no method named `foo`
12+
}
13+
}
14+
15+
impl Bar<u32> {
16+
fn foo(self) {}
17+
}
18+
19+
fn foo() -> Foo {
20+
42_u32
21+
}
22+
23+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
error[E0599]: no method named `foo` found for struct `Bar<Foo>` in the current scope
2+
--> $DIR/method_resolution2.rs:10:14
3+
|
4+
LL | struct Bar<T>(T);
5+
| ------------- method `foo` not found for this struct
6+
...
7+
LL | self.foo()
8+
| ^^^ method not found in `Bar<Foo>`
9+
|
10+
= note: the method was found for
11+
- `Bar<u32>`
12+
13+
error[E0391]: cycle detected when computing type of opaque `Foo::{opaque#0}`
14+
--> $DIR/method_resolution2.rs:3:12
15+
|
16+
LL | type Foo = impl Sized;
17+
| ^^^^^^^^^^
18+
|
19+
note: ...which requires type-checking `<impl at $DIR/method_resolution2.rs:8:1: 8:14>::bar`...
20+
--> $DIR/method_resolution2.rs:10:9
21+
|
22+
LL | self.foo()
23+
| ^^^^
24+
= note: ...which requires evaluating trait selection obligation `Bar<Foo>: core::marker::Unpin`...
25+
= note: ...which again requires computing type of opaque `Foo::{opaque#0}`, completing the cycle
26+
note: cycle used when computing type of `Foo::{opaque#0}`
27+
--> $DIR/method_resolution2.rs:3:12
28+
|
29+
LL | type Foo = impl Sized;
30+
| ^^^^^^^^^^
31+
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
32+
33+
error: aborting due to 2 previous errors
34+
35+
Some errors have detailed explanations: E0391, E0599.
36+
For more information about an error, try `rustc --explain E0391`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#![feature(type_alias_impl_trait, arbitrary_self_types)]
2+
3+
type Foo = impl Copy;
4+
5+
#[derive(Copy, Clone)]
6+
struct Bar<T>(T);
7+
8+
impl Bar<Foo> {
9+
fn bar(self: Bar<u32>) {
10+
//~^ ERROR: invalid `self` parameter
11+
self.foo()
12+
}
13+
fn baz(self: &Bar<u32>) {
14+
//~^ ERROR: invalid `self` parameter
15+
self.foo()
16+
}
17+
}
18+
19+
impl Bar<u32> {
20+
fn foo(self) {}
21+
}
22+
23+
fn foo() -> Foo {
24+
42_u32
25+
}
26+
27+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0307]: invalid `self` parameter type: Bar<u32>
2+
--> $DIR/method_resolution3.rs:9:18
3+
|
4+
LL | fn bar(self: Bar<u32>) {
5+
| ^^^^^^^^
6+
|
7+
= note: type of `self` must be `Self` or a type that dereferences to it
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`)
9+
10+
error[E0307]: invalid `self` parameter type: &Bar<u32>
11+
--> $DIR/method_resolution3.rs:13:18
12+
|
13+
LL | fn baz(self: &Bar<u32>) {
14+
| ^^^^^^^^^
15+
|
16+
= note: type of `self` must be `Self` or a type that dereferences to it
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`)
18+
19+
error: aborting due to 2 previous errors
20+
21+
For more information about this error, try `rustc --explain E0307`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#![feature(type_alias_impl_trait, arbitrary_self_types)]
2+
3+
type Foo = impl Copy;
4+
5+
#[derive(Copy, Clone)]
6+
struct Bar<T>(T);
7+
8+
impl Bar<Foo> {
9+
fn bar(self) {}
10+
}
11+
12+
impl Bar<u32> {
13+
fn foo(self: Bar<Foo>) {
14+
//~^ ERROR: invalid `self` parameter
15+
self.bar()
16+
}
17+
fn foomp(self: &Bar<Foo>) {
18+
//~^ ERROR: invalid `self` parameter
19+
self.bar()
20+
}
21+
}
22+
23+
fn foo() -> Foo {
24+
42_u32
25+
}
26+
27+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0307]: invalid `self` parameter type: Bar<Foo>
2+
--> $DIR/method_resolution4.rs:13:18
3+
|
4+
LL | fn foo(self: Bar<Foo>) {
5+
| ^^^^^^^^
6+
|
7+
= note: type of `self` must be `Self` or a type that dereferences to it
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`)
9+
10+
error[E0307]: invalid `self` parameter type: &Bar<Foo>
11+
--> $DIR/method_resolution4.rs:17:20
12+
|
13+
LL | fn foomp(self: &Bar<Foo>) {
14+
| ^^^^^^^^^
15+
|
16+
= note: type of `self` must be `Self` or a type that dereferences to it
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`)
18+
19+
error: aborting due to 2 previous errors
20+
21+
For more information about this error, try `rustc --explain E0307`.

0 commit comments

Comments
 (0)