Skip to content

Commit cde0023

Browse files
committed
Add compile-fail style comments to tests
1 parent fa6ae4c commit cde0023

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/test/ui/suggestions/str-array-assignment.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,25 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
fn main() {
11+
fn main() { //~ NOTE expected `()` because of default return type
1212
let s = "abc";
1313
let t = if true { s[..2] } else { s };
14+
//~^ ERROR if and else have incompatible types
15+
//~| NOTE expected str, found &str
16+
//~| NOTE expected type
1417
let u: &str = if true { s[..2] } else { s };
18+
//~^ ERROR mismatched types
19+
//~| NOTE expected &str, found str
20+
//~| NOTE expected type
1521
let v = s[..2];
22+
//~^ ERROR the trait bound `str: std::marker::Sized` is not satisfied
23+
//~| NOTE consider a slice instead
24+
//~| NOTE `str` does not have a constant size known at compile-time
25+
//~| HELP the trait `std::marker::Sized` is not implemented for `str`
26+
//~| NOTE all local variables must have a statically known size
1627
let w: &str = s[..2];
28+
//~^ ERROR mismatched types
29+
//~| NOTE expected &str, found str
30+
//~| NOTE expected type
31+
//~| HELP try with `&s[..2]`
1732
}

src/test/ui/suggestions/str-array-assignment.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ error[E0308]: if and else have incompatible types
88
found type `&str`
99

1010
error[E0308]: mismatched types
11-
--> $DIR/str-array-assignment.rs:14:27
11+
--> $DIR/str-array-assignment.rs:17:27
1212
|
13-
11 | fn main() {
13+
11 | fn main() { //~ NOTE expected `()` because of default return type
1414
| - expected `()` because of default return type
1515
...
16-
14 | let u: &str = if true { s[..2] } else { s };
16+
17 | let u: &str = if true { s[..2] } else { s };
1717
| ^^^^^^ expected &str, found str
1818
|
1919
= note: expected type `&str`
2020
found type `str`
2121

2222
error[E0277]: the trait bound `str: std::marker::Sized` is not satisfied
23-
--> $DIR/str-array-assignment.rs:15:7
23+
--> $DIR/str-array-assignment.rs:21:7
2424
|
25-
15 | let v = s[..2];
25+
21 | let v = s[..2];
2626
| ^ ------ help: consider a slice instead: `&s[..2]`
2727
| |
2828
| `str` does not have a constant size known at compile-time
@@ -31,9 +31,9 @@ error[E0277]: the trait bound `str: std::marker::Sized` is not satisfied
3131
= note: all local variables must have a statically known size
3232

3333
error[E0308]: mismatched types
34-
--> $DIR/str-array-assignment.rs:16:17
34+
--> $DIR/str-array-assignment.rs:27:17
3535
|
36-
16 | let w: &str = s[..2];
36+
27 | let w: &str = s[..2];
3737
| ^^^^^^ expected &str, found str
3838
|
3939
= note: expected type `&str`

0 commit comments

Comments
 (0)