diff options
| author | bors <bors@rust-lang.org> | 2016-02-14 16:18:48 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-02-14 16:18:48 +0000 |
| commit | 004c4b4b7d581f54365bc621a23106e970120f99 (patch) | |
| tree | c7dbf1febbb78c90ef5182ac9bd5f2b9d451bdd0 | |
| parent | f3619ce026e3de5d26537de63b7d0cd7710a3b96 (diff) | |
| parent | 5d0a68d1d3589964f0f2a43d1eb65f4ebcd4c578 (diff) | |
| download | rust-004c4b4b7d581f54365bc621a23106e970120f99.tar.gz rust-004c4b4b7d581f54365bc621a23106e970120f99.zip | |
Auto merge of #31651 - eddyb:fix-26978, r=arielb1
Handles `str` being an expression's expected type, which was missing from #20083. Fixes #26978.
| -rw-r--r-- | src/librustc_typeck/check/mod.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/coerce-expect-unsized.rs | 7 |
2 files changed, 8 insertions, 1 deletions
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<Fn(isize) -> _> = Box::new(|x| (x as u8)); |
