From 5d0a68d1d3589964f0f2a43d1eb65f4ebcd4c578 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sun, 14 Feb 2016 15:38:48 +0200 Subject: [PATCH] Do not expect blocks to have type str. --- src/librustc_typeck/check/mod.rs | 2 +- src/test/run-pass/coerce-expect-unsized.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 6a7bc9b6111..f890e087573 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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) diff --git a/src/test/run-pass/coerce-expect-unsized.rs b/src/test/run-pass/coerce-expect-unsized.rs index ee4ec24b7e3..f846ee8f3d0 100644 --- a/src/test/run-pass/coerce-expect-unsized.rs +++ b/src/test/run-pass/coerce-expect-unsized.rs @@ -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 _> = Box::new(|x| (x as u8));