-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Suggest using slice when encountering let x = ""[..];
#46249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
fa6ae4c
cde0023
97d8d04
fa44927
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
compile-fail style comments to tests
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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` | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add
//~ ERRORcomments. Ui tests work like compile-fail nowThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.