Skip to content

Commit c75f728

Browse files
committed
Add some tests
1 parent b28221e commit c75f728

38 files changed

+998
-0
lines changed
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`.
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+
}
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`.
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() {}
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`.
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`.
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() {}
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`.
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`.
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() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
error[E0599]: no method named `fmt` found for opaque type `impl Debug` in the current scope
2+
--> $DIR/call_method_without_import.rs:17:11
3+
|
4+
LL | x.fmt(f);
5+
| ^^^ method not found in `impl Debug`
6+
--> $SRC_DIR/core/src/fmt/mod.rs:LL:COL
7+
|
8+
= note: the method is available for `impl Debug` here
9+
|
10+
= help: items from traits can only be used if the trait is in scope
11+
help: trait `Debug` which provides `fmt` is implemented but not in scope; perhaps you want to import it
12+
|
13+
LL + use std::fmt::Debug;
14+
|
15+
16+
error[E0599]: no method named `fmt` found for mutable reference `&mut impl Debug` in the current scope
17+
--> $DIR/call_method_without_import.rs:26:11
18+
|
19+
LL | x.fmt(f);
20+
| ^^^ method not found in `&mut impl Debug`
21+
|
22+
= help: items from traits can only be used if the trait is in scope
23+
help: the following traits which provide `fmt` are implemented but not in scope; perhaps you want to import one of them
24+
|
25+
LL + use std::fmt::Binary;
26+
|
27+
LL + use std::fmt::Debug;
28+
|
29+
LL + use std::fmt::Display;
30+
|
31+
LL + use std::fmt::LowerExp;
32+
|
33+
and 5 other candidates
34+
35+
error: aborting due to 2 previous errors
36+
37+
For more information about this error, try `rustc --explain E0599`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//! Test that opaque types only pick up methods from traits in their bounds
2+
//! if the trait is imported.
3+
//!
4+
//! FIXME: always look through the bounds of an opaque type to see if there are
5+
//! methods that could be called on any of the bound traits, irrespective of
6+
//! imported traits.
7+
8+
//@ revisions: import no_import
9+
//@[import] check-pass
10+
11+
#[cfg(import)]
12+
use std::fmt::Debug as _;
13+
14+
fn foo(f: &mut std::fmt::Formatter<'_>) -> impl std::fmt::Debug {
15+
if false {
16+
let x = foo(f);
17+
x.fmt(f);
18+
//[no_import]~^ ERROR: no method named `fmt` found
19+
}
20+
()
21+
}
22+
23+
fn foo1(f: &mut std::fmt::Formatter<'_>) -> impl std::fmt::Debug {
24+
if false {
25+
let x = &mut foo(f);
26+
x.fmt(f);
27+
//[no_import]~^ ERROR: no method named `fmt` found
28+
}
29+
()
30+
}
31+
32+
// inconsistent with this
33+
fn bar<T>(t: impl std::fmt::Debug, f: &mut std::fmt::Formatter<'_>) {
34+
t.fmt(f);
35+
}
36+
37+
// and the desugared version, of course
38+
fn baz<T: std::fmt::Debug>(t: T, f: &mut std::fmt::Formatter<'_>) {
39+
t.fmt(f);
40+
}
41+
42+
fn main() {}
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`.

0 commit comments

Comments
 (0)