Skip to content

Commit

Permalink
Add compile-fail style comments to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Nov 25, 2017
1 parent fa6ae4c commit cde0023
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
17 changes: 16 additions & 1 deletion src/test/ui/suggestions/str-array-assignment.rs
Expand Up @@ -8,10 +8,25 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() {
fn main() { //~ NOTE expected `()` because of default return type
let s = "abc";
let t = if true { s[..2] } else { s };
//~^ ERROR if and else have incompatible types
//~| NOTE expected str, found &str
//~| NOTE expected type
let u: &str = if true { s[..2] } else { s };
//~^ ERROR mismatched types
//~| NOTE expected &str, found str
//~| NOTE expected type
let v = s[..2];
//~^ ERROR the trait bound `str: std::marker::Sized` is not satisfied
//~| NOTE consider a slice instead
//~| NOTE `str` does not have a constant size known at compile-time
//~| HELP the trait `std::marker::Sized` is not implemented for `str`
//~| NOTE all local variables must have a statically known size
let w: &str = s[..2];
//~^ ERROR mismatched types
//~| NOTE expected &str, found str
//~| NOTE expected type
//~| HELP try with `&s[..2]`
}
14 changes: 7 additions & 7 deletions src/test/ui/suggestions/str-array-assignment.stderr
Expand Up @@ -8,21 +8,21 @@ error[E0308]: if and else have incompatible types
found type `&str`

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

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

error[E0308]: mismatched types
--> $DIR/str-array-assignment.rs:16:17
--> $DIR/str-array-assignment.rs:27:17
|
16 | let w: &str = s[..2];
27 | let w: &str = s[..2];
| ^^^^^^ expected &str, found str
|
= note: expected type `&str`
Expand Down

0 comments on commit cde0023

Please sign in to comment.