Skip to content

Commit c75f728

Browse files
committed
Add some tests
1 parent b28221e commit c75f728

38 files changed

+998
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/call_method_ambiguous.rs:29:13
3+
|
4+
LL | let mut iter = foo(n - 1, m);
5+
| ^^^^^^^^
6+
LL |
7+
LL | assert_eq!(iter.get(), 1);
8+
| ---- type must be known at this point
9+
|
10+
help: consider giving `iter` an explicit type
11+
|
12+
LL | let mut iter: /* Type */ = foo(n - 1, m);
13+
| ++++++++++++
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0282`.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//@ revisions: current next
2+
//@[next] compile-flags: -Znext-solver
3+
//@[current] run-pass
4+
5+
#![feature(precise_capturing)]
6+
#![allow(incomplete_features)]
7+
8+
trait Get {
9+
fn get(&mut self) -> u32;
10+
}
11+
12+
impl Get for () {
13+
fn get(&mut self) -> u32 {
14+
0
15+
}
16+
}
17+
18+
impl<T> Get for &mut T
19+
where
20+
T: Get,
21+
{
22+
fn get(&mut self) -> u32 {
23+
T::get(self) + 1
24+
}
25+
}
26+
27+
fn foo(n: usize, m: &mut ()) -> impl use<'_> Get {
28+
if n > 0 {
29+
let mut iter = foo(n - 1, m);
30+
//[next]~^ type annotations needed
31+
assert_eq!(iter.get(), 1);
32+
}
33+
m
34+
}
35+
36+
fn main() {
37+
let g = foo(1, &mut ()).get();
38+
assert_eq!(g, 1);
39+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/call_method_on_inherent_impl.rs:18:13
3+
|
4+
LL | let x = my_foo();
5+
| ^
6+
LL |
7+
LL | x.my_debug();
8+
| - type must be known at this point
9+
|
10+
help: consider giving `x` an explicit type
11+
|
12+
LL | let x: /* Type */ = my_foo();
13+
| ++++++++++++
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0282`.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//@ revisions: current next
2+
//@[next] compile-flags: -Znext-solver
3+
//@[current] check-pass
4+
5+
trait MyDebug {
6+
fn my_debug(&self);
7+
}
8+
9+
impl<T> MyDebug for T
10+
where
11+
T: std::fmt::Debug,
12+
{
13+
fn my_debug(&self) {}
14+
}
15+
16+
fn my_foo() -> impl std::fmt::Debug {
17+
if false {
18+
let x = my_foo();
19+
//[next]~^ type annotations needed
20+
x.my_debug();
21+
}
22+
()
23+
}
24+
25+
fn main() {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0599]: no method named `my_debug` found for reference `&impl Debug` in the current scope
2+
--> $DIR/call_method_on_inherent_impl_on_rigid_type.rs:16:11
3+
|
4+
LL | x.my_debug();
5+
| ^^^^^^^^ method not found in `&impl Debug`
6+
|
7+
= help: items from traits can only be used if the trait is implemented and in scope
8+
note: `MyDebug` defines an item `my_debug`, perhaps you need to implement it
9+
--> $DIR/call_method_on_inherent_impl_on_rigid_type.rs:4:1
10+
|
11+
LL | trait MyDebug {
12+
| ^^^^^^^^^^^^^
13+
14+
error: aborting due to 1 previous error
15+
16+
For more information about this error, try `rustc --explain E0599`.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0282]: type annotations needed for `&_`
2+
--> $DIR/call_method_on_inherent_impl_on_rigid_type.rs:14:13
3+
|
4+
LL | let x = &my_foo();
5+
| ^
6+
LL |
7+
LL | x.my_debug();
8+
| -------- type must be known at this point
9+
|
10+
help: consider giving `x` an explicit type, where the placeholders `_` are specified
11+
|
12+
LL | let x: &_ = &my_foo();
13+
| ++++
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0282`.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@ revisions: current next
2+
//@[next] compile-flags: -Znext-solver
3+
4+
trait MyDebug {
5+
fn my_debug(&self);
6+
}
7+
8+
impl MyDebug for &() {
9+
fn my_debug(&self) {}
10+
}
11+
12+
fn my_foo() -> impl std::fmt::Debug {
13+
if false {
14+
let x = &my_foo();
15+
//[next]~^ ERROR: type annotations needed
16+
x.my_debug();
17+
//[current]~^ ERROR: no method named `my_debug`
18+
}
19+
()
20+
}
21+
22+
fn main() {}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
error[E0599]: no method named `my_debug` found for opaque type `impl Debug` in the current scope
2+
--> $DIR/call_method_on_inherent_impl_ref.rs:20:11
3+
|
4+
LL | fn my_debug(&self);
5+
| -------- the method is available for `&impl Debug` here
6+
...
7+
LL | x.my_debug();
8+
| ^^^^^^^^ method not found in `impl Debug`
9+
|
10+
= help: items from traits can only be used if the trait is implemented and in scope
11+
note: `MyDebug` defines an item `my_debug`, perhaps you need to implement it
12+
--> $DIR/call_method_on_inherent_impl_ref.rs:4:1
13+
|
14+
LL | trait MyDebug {
15+
| ^^^^^^^^^^^^^
16+
17+
error[E0391]: cycle detected when computing type of opaque `my_foo::{opaque#0}`
18+
--> $DIR/call_method_on_inherent_impl_ref.rs:15:16
19+
|
20+
LL | fn my_foo() -> impl std::fmt::Debug {
21+
| ^^^^^^^^^^^^^^^^^^^^
22+
|
23+
note: ...which requires type-checking `my_foo`...
24+
--> $DIR/call_method_on_inherent_impl_ref.rs:20:9
25+
|
26+
LL | x.my_debug();
27+
| ^
28+
= note: ...which requires evaluating trait selection obligation `my_foo::{opaque#0}: core::marker::Unpin`...
29+
= note: ...which again requires computing type of opaque `my_foo::{opaque#0}`, completing the cycle
30+
note: cycle used when computing type of `my_foo::{opaque#0}`
31+
--> $DIR/call_method_on_inherent_impl_ref.rs:15:16
32+
|
33+
LL | fn my_foo() -> impl std::fmt::Debug {
34+
| ^^^^^^^^^^^^^^^^^^^^
35+
= 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
36+
37+
error: aborting due to 2 previous errors
38+
39+
Some errors have detailed explanations: E0391, E0599.
40+
For more information about an error, try `rustc --explain E0391`.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/call_method_on_inherent_impl_ref.rs:18:13
3+
|
4+
LL | let x = my_foo();
5+
| ^
6+
LL |
7+
LL | x.my_debug();
8+
| - type must be known at this point
9+
|
10+
help: consider giving `x` an explicit type
11+
|
12+
LL | let x: /* Type */ = my_foo();
13+
| ++++++++++++
14+
15+
error[E0282]: type annotations needed for `&_`
16+
--> $DIR/call_method_on_inherent_impl_ref.rs:28:13
17+
|
18+
LL | let x = &my_bar();
19+
| ^
20+
LL |
21+
LL | x.my_debug();
22+
| -------- type must be known at this point
23+
|
24+
help: consider giving `x` an explicit type, where the placeholders `_` are specified
25+
|
26+
LL | let x: &_ = &my_bar();
27+
| ++++
28+
29+
error: aborting due to 2 previous errors
30+
31+
For more information about this error, try `rustc --explain E0282`.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//@ revisions: current next
2+
//@[next] compile-flags: -Znext-solver
3+
4+
trait MyDebug {
5+
fn my_debug(&self);
6+
}
7+
8+
impl<T> MyDebug for &T
9+
where
10+
T: std::fmt::Debug,
11+
{
12+
fn my_debug(&self) {}
13+
}
14+
15+
fn my_foo() -> impl std::fmt::Debug {
16+
//[current]~^ cycle
17+
if false {
18+
let x = my_foo();
19+
//[next]~^ type annotations needed
20+
x.my_debug();
21+
//[current]~^ no method named `my_debug` found
22+
}
23+
()
24+
}
25+
26+
fn my_bar() -> impl std::fmt::Debug {
27+
if false {
28+
let x = &my_bar();
29+
//[next]~^ type annotations needed
30+
x.my_debug();
31+
}
32+
()
33+
}
34+
35+
fn main() {}

0 commit comments

Comments
 (0)