Skip to content

Commit f5710e8

Browse files
committed
Add some tests
1 parent f30b2ee commit f5710e8

22 files changed

+579
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
error[E0599]: no method named `bar` found for struct `Bar<impl Sized>` in the current scope
2+
--> $DIR/method-resolution.rs:23:11
3+
|
4+
LL | struct Bar<T>(T);
5+
| ------------- method `bar` not found for this struct
6+
...
7+
LL | x.bar();
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:19: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:23:9
21+
|
22+
LL | x.bar();
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:19: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`.
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//! Check that we do not constrain hidden types during method resolution.
2+
//! Otherwise we'd pick up that calling `bar` can be satisfied iff `u32`
3+
//! is the hidden type of the RPIT.
4+
5+
//@ revisions: current next
6+
//@[next] compile-flags: -Znext-solver
7+
//@[next] check-pass
8+
9+
trait Trait {}
10+
11+
impl Trait for u32 {}
12+
13+
struct Bar<T>(T);
14+
15+
impl Bar<u32> {
16+
fn bar(self) {}
17+
}
18+
19+
fn foo(x: bool) -> Bar<impl Sized> {
20+
//[current]~^ ERROR: cycle detected
21+
if x {
22+
let x = foo(false);
23+
x.bar();
24+
//[current]~^ ERROR: no method named `bar` found
25+
}
26+
todo!()
27+
}
28+
29+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0034]: multiple applicable items in scope
2+
--> $DIR/method-resolution2.rs:25:11
3+
|
4+
LL | x.bar();
5+
| ^^^ multiple `bar` found
6+
|
7+
note: candidate #1 is defined in an impl for the type `Bar<T>`
8+
--> $DIR/method-resolution2.rs:19:5
9+
|
10+
LL | fn bar(self) {}
11+
| ^^^^^^^^^^^^
12+
note: candidate #2 is defined in an impl for the type `Bar<u32>`
13+
--> $DIR/method-resolution2.rs:15:5
14+
|
15+
LL | fn bar(self) {}
16+
| ^^^^^^^^^^^^
17+
18+
error: aborting due to 1 previous error
19+
20+
For more information about this error, try `rustc --explain E0034`.
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//! Check that the method call does not constrain the RPIT to `i32`, even though
2+
//! `i32` is the only trait that satisfies the RPIT's trait bounds.
3+
4+
//@ revisions: current next
5+
//@[next] compile-flags: -Znext-solver
6+
//@[current] check-pass
7+
8+
trait Trait {}
9+
10+
impl Trait for i32 {}
11+
12+
struct Bar<T>(T);
13+
14+
impl Bar<u32> {
15+
fn bar(self) {}
16+
}
17+
18+
impl<T: Trait> Bar<T> {
19+
fn bar(self) {}
20+
}
21+
22+
fn foo(x: bool) -> Bar<impl Trait> {
23+
if x {
24+
let x = foo(false);
25+
x.bar();
26+
//[next]~^ ERROR: multiple applicable items in scope
27+
}
28+
Bar(42_i32)
29+
}
30+
31+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
error[E0599]: no method named `bar` found for struct `Bar<impl Sized>` in the current scope
2+
--> $DIR/method-resolution3.rs:22:11
3+
|
4+
LL | struct Bar<T>(T);
5+
| ------------- method `bar` not found for this struct
6+
...
7+
LL | x.bar();
8+
| ^^^ method not found in `Bar<impl Sized>`
9+
|
10+
= note: the method was found for
11+
- `Bar<i32>`
12+
- `Bar<u32>`
13+
14+
error[E0391]: cycle detected when computing type of opaque `foo::{opaque#0}`
15+
--> $DIR/method-resolution3.rs:18:24
16+
|
17+
LL | fn foo(x: bool) -> Bar<impl Sized> {
18+
| ^^^^^^^^^^
19+
|
20+
note: ...which requires type-checking `foo`...
21+
--> $DIR/method-resolution3.rs:22:9
22+
|
23+
LL | x.bar();
24+
| ^
25+
= note: ...which requires evaluating trait selection obligation `Bar<foo::{opaque#0}>: core::marker::Unpin`...
26+
= note: ...which again requires computing type of opaque `foo::{opaque#0}`, completing the cycle
27+
note: cycle used when computing type of `foo::{opaque#0}`
28+
--> $DIR/method-resolution3.rs:18:24
29+
|
30+
LL | fn foo(x: bool) -> Bar<impl Sized> {
31+
| ^^^^^^^^^^
32+
= 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
33+
34+
error: aborting due to 2 previous errors
35+
36+
Some errors have detailed explanations: E0391, E0599.
37+
For more information about an error, try `rustc --explain E0391`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0034]: multiple applicable items in scope
2+
--> $DIR/method-resolution3.rs:22:11
3+
|
4+
LL | x.bar();
5+
| ^^^ multiple `bar` found
6+
|
7+
note: candidate #1 is defined in an impl for the type `Bar<i32>`
8+
--> $DIR/method-resolution3.rs:15:5
9+
|
10+
LL | fn bar(self) {}
11+
| ^^^^^^^^^^^^
12+
note: candidate #2 is defined in an impl for the type `Bar<u32>`
13+
--> $DIR/method-resolution3.rs:11:5
14+
|
15+
LL | fn bar(self) {}
16+
| ^^^^^^^^^^^^
17+
18+
error: aborting due to 1 previous error
19+
20+
For more information about this error, try `rustc --explain E0034`.
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//! Check that we consider `Bar<impl Sized>` to successfully unify
2+
//! with both `Bar<u32>` and `Bar<i32>` (in isolation), so we bail
3+
//! out with ambiguity.
4+
5+
//@ revisions: current next
6+
//@[next] compile-flags: -Znext-solver
7+
8+
struct Bar<T>(T);
9+
10+
impl Bar<u32> {
11+
fn bar(self) {}
12+
}
13+
14+
impl Bar<i32> {
15+
fn bar(self) {}
16+
}
17+
18+
fn foo(x: bool) -> Bar<impl Sized> {
19+
//[current]~^ ERROR: cycle
20+
if x {
21+
let x = foo(false);
22+
x.bar();
23+
//[current]~^ ERROR: no method named `bar`
24+
//[next]~^^ ERROR: multiple applicable items in scope
25+
}
26+
todo!()
27+
}
28+
29+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/method-resolution4.rs:13:9
3+
|
4+
LL | foo(false).next().unwrap();
5+
| ^^^^^^^^^^ cannot infer type
6+
7+
error[E0308]: mismatched types
8+
--> $DIR/method-resolution4.rs:16:5
9+
|
10+
LL | fn foo(b: bool) -> impl Iterator<Item = ()> {
11+
| ------------------------ the expected opaque type
12+
...
13+
LL | std::iter::empty()
14+
| ^^^^^^^^^^^^^^^^^^ types differ
15+
|
16+
= note: expected opaque type `impl Iterator<Item = ()>`
17+
found struct `std::iter::Empty<_>`
18+
19+
error: aborting due to 2 previous errors
20+
21+
Some errors have detailed explanations: E0282, E0308.
22+
For more information about an error, try `rustc --explain E0282`.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! The recursive method call yields the opaque type. The
2+
//! `next` method call then constrains the hidden type to `&mut _`
3+
//! because `next` takes `&mut self`. We never resolve the inference
4+
//! variable, but get a type mismatch when comparing `&mut _` with
5+
//! `std::iter::Empty`.
6+
7+
//@[current] check-pass
8+
//@ revisions: current next
9+
//@[next] compile-flags: -Znext-solver
10+
11+
fn foo(b: bool) -> impl Iterator<Item = ()> {
12+
if b {
13+
foo(false).next().unwrap();
14+
//[next]~^ type annotations needed
15+
}
16+
std::iter::empty()
17+
//[next]~^ mismatched types
18+
}
19+
20+
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:20: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,19 @@
1+
error[E0284]: type annotations needed: cannot satisfy `_ == Foo`
2+
--> $DIR/method_resolution.rs:14:12
3+
|
4+
LL | fn bar(self) {}
5+
| ^^^^ cannot satisfy `_ == Foo`
6+
7+
error[E0599]: no method named `bar` found for struct `Bar<u32>` in the current scope
8+
--> $DIR/method_resolution.rs:20:14
9+
|
10+
LL | struct Bar<T>(T);
11+
| ------------- method `bar` not found for this struct
12+
...
13+
LL | self.bar()
14+
| ^^^ method cannot be called on `Bar<u32>` due to unsatisfied trait bounds
15+
16+
error: aborting due to 2 previous errors
17+
18+
Some errors have detailed explanations: E0284, E0599.
19+
For more information about an error, try `rustc --explain E0284`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//! check that we do not unify `Bar<Foo>` with `BAr<u32>`, even though the
2+
//! `bar` method call can be resolved unambiguously by doing so.
3+
4+
//@ revisions: current next
5+
//@[next] compile-flags: -Znext-solver
6+
7+
#![feature(type_alias_impl_trait)]
8+
9+
type Foo = impl Sized;
10+
11+
struct Bar<T>(T);
12+
13+
impl Bar<Foo> {
14+
fn bar(self) {}
15+
//[next]~^ ERROR type annotations needed: cannot satisfy `_ == Foo`
16+
}
17+
18+
impl Bar<u32> {
19+
fn foo(self) {
20+
self.bar()
21+
//~^ ERROR: no method named `bar`
22+
}
23+
}
24+
25+
fn foo() -> Foo {
26+
42_u32
27+
}
28+
29+
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:17: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:10:12
15+
|
16+
LL | type Foo = impl Sized;
17+
| ^^^^^^^^^^
18+
|
19+
note: ...which requires type-checking `<impl at $DIR/method_resolution2.rs:15:1: 15:14>::bar`...
20+
--> $DIR/method_resolution2.rs:17: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:10: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,30 @@
1+
//! check that we do not unify `Bar<Foo>` with `BAr<u32>`, even though the
2+
//! `foo` method call can be resolved unambiguously by doing so.
3+
4+
//@ revisions: current next
5+
//@[next] compile-flags: -Znext-solver
6+
//@[next] check-pass
7+
8+
#![feature(type_alias_impl_trait)]
9+
10+
type Foo = impl Sized;
11+
//[current]~^ ERROR: cycle
12+
13+
struct Bar<T>(T);
14+
15+
impl Bar<Foo> {
16+
fn bar(self) {
17+
self.foo()
18+
//[current]~^ ERROR: no method named `foo`
19+
}
20+
}
21+
22+
impl Bar<u32> {
23+
fn foo(self) {}
24+
}
25+
26+
fn foo() -> Foo {
27+
42_u32
28+
}
29+
30+
fn main() {}

0 commit comments

Comments
 (0)