Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add compile-fail style comments to tests
  • Loading branch information
estebank committed Nov 25, 2017
commit cde0023b5b71eb4ceafef31dd9036a268ba3b08d
17 changes: 16 additions & 1 deletion src/test/ui/suggestions/str-array-assignment.rs
Original file line number Diff line number Diff line change
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 };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add //~ ERROR comments. Ui tests work like compile-fail now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

//~^ 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
Original file line number Diff line number Diff line change
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks dubious. Could you look into this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I noticed that too. Still digging.

Copy link
Contributor

@arielb1 arielb1 Nov 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's also already the case on nightly. Feel free to ignore this and open an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...
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