error[E0308]: if and else have incompatible types --> $DIR/str-array-assignment.rs:13:11 | 13 | let t = if true { s[..2] } else { s }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected str, found &str | = note: expected type `str` found type `&str` error[E0308]: mismatched types --> $DIR/str-array-assignment.rs:15:27 | 11 | fn main() { | - expected `()` because of default return type ... 15 | 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:17:7 | 17 | let v = s[..2]; | ^ ------ help: consider borrowing here: `&s[..2]` | | | `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 error[E0308]: mismatched types --> $DIR/str-array-assignment.rs:19:17 | 19 | let w: &str = s[..2]; | ^^^^^^ | | | expected &str, found str | help: consider borrowing here: `&s[..2]` | = note: expected type `&str` found type `str` error: aborting due to 4 previous errors You've got a few errors: E0277, E0308 If you want more information on an error, try using "rustc --explain E0277"