1
Fork 0

Add compile-fail style comments to tests

This commit is contained in:
Esteban Küber 2017-11-25 06:19:39 -08:00
parent fa6ae4c828
commit cde0023b5b
2 changed files with 23 additions and 8 deletions

View file

@ -8,10 +8,25 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
fn main() { fn main() { //~ NOTE expected `()` because of default return type
let s = "abc"; let s = "abc";
let t = if true { s[..2] } else { s }; 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 }; let u: &str = if true { s[..2] } else { s };
//~^ ERROR mismatched types
//~| NOTE expected &str, found str
//~| NOTE expected type
let v = s[..2]; 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]; let w: &str = s[..2];
//~^ ERROR mismatched types
//~| NOTE expected &str, found str
//~| NOTE expected type
//~| HELP try with `&s[..2]`
} }

View file

@ -8,21 +8,21 @@ error[E0308]: if and else have incompatible types
found type `&str` found type `&str`
error[E0308]: mismatched types 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 | - 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 | ^^^^^^ expected &str, found str
| |
= note: expected type `&str` = note: expected type `&str`
found type `str` found type `str`
error[E0277]: the trait bound `str: std::marker::Sized` is not satisfied 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]` | ^ ------ help: consider a slice instead: `&s[..2]`
| | | |
| `str` does not have a constant size known at compile-time | `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
= note: all local variables must have a statically known size = note: all local variables must have a statically known size
error[E0308]: mismatched types 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 | ^^^^^^ expected &str, found str
| |
= note: expected type `&str` = note: expected type `&str`