forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissue-90528-unsizing-suggestion-2.rs
42 lines (37 loc) · 1.32 KB
/
issue-90528-unsizing-suggestion-2.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Issue #90528: provide helpful suggestions when a trait bound is unsatisfied
// due to a missed unsizing coercion.
//
// This test exercises array variables and a trait implemented on immmutable slices.
trait Read {}
impl Read for &[u8] {}
fn wants_read(_: impl Read) {}
fn main() {
let x = [0u8];
wants_read(x);
//~^ ERROR the trait bound `[u8; 1]: Read` is not satisfied
//~| HELP the following implementations were found
//~| HELP convert the array
//~| SUGGESTION &x[..]
wants_read(&x);
//~^ ERROR the trait bound `&[u8; 1]: Read` is not satisfied
//~| HELP the following implementations were found
//~| HELP convert the array
//~| SUGGESTION &x[..]
wants_read(&x[..]);
let x = &[0u8];
wants_read(x);
//~^ ERROR the trait bound `&[u8; 1]: Read` is not satisfied
//~| HELP the following implementations were found
//~| HELP convert the array
//~| SUGGESTION &x[..]
wants_read(&x);
//~^ ERROR the trait bound `&&[u8; 1]: Read` is not satisfied
//~| HELP the following implementations were found
wants_read(*x);
//~^ ERROR the trait bound `[u8; 1]: Read` is not satisfied
//~| HELP the following implementations were found
//~| HELP convert the array
//~| SUGGESTION &*x[..]
// ^^^^^^^ bad suggestion
wants_read(&x[..]);
}