]> git.lizzy.rs Git - rust.git/commitdiff
Do not expect blocks to have type str.
authorEduard Burtescu <edy.burt@gmail.com>
Sun, 14 Feb 2016 13:38:48 +0000 (15:38 +0200)
committerEduard Burtescu <edy.burt@gmail.com>
Sun, 14 Feb 2016 13:38:48 +0000 (15:38 +0200)
src/librustc_typeck/check/mod.rs
src/test/run-pass/coerce-expect-unsized.rs

index 6a7bc9b61116d8a18b91f0ecb3654ce344c798ce..f890e087573b5ceb3f21563c47550a0932bc1ca0 100644 (file)
@@ -3828,7 +3828,7 @@ impl<'tcx> Expectation<'tcx> {
     /// for examples of where this comes up,.
     fn rvalue_hint(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> Expectation<'tcx> {
         match tcx.struct_tail(ty).sty {
-            ty::TySlice(_) | ty::TyTrait(..) => {
+            ty::TySlice(_) | ty::TyStr | ty::TyTrait(..) => {
                 ExpectRvalueLikeUnsized(ty)
             }
             _ => ExpectHasType(ty)
index ee4ec24b7e3dad97370ca4831ad9d57806656861..f846ee8f3d0b924035886db8f93ecda1c4464404 100644 (file)
@@ -44,6 +44,13 @@ pub fn main() {
     let _: &Debug = &if true { false } else { true };
     let _: &Debug = &match true { true => 'a', false => 'b' };
 
+    let _: &str = &{ String::new() };
+    let _: &str = &if true { String::from("...") } else { 5.to_string() };
+    let _: &str = &match true {
+        true => format!("{}", false),
+        false => ["x", "y"].join("+")
+    };
+
     let _: Box<[isize]> = Box::new([1, 2, 3]);
     let _: Box<Fn(isize) -> _> = Box::new(|x| (x as u8));