add regression test for #39808

Fixes #39808
This commit is contained in:
Niko Matsakis 2017-03-18 15:22:48 -04:00
parent 2f526cc897
commit f11b7d33bb

View File

@ -8,14 +8,19 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Regression test: even though `Ok` is dead-code, its type needs to
// be influenced by the result of `Err` or else we get a "type
// variable unconstrained" error.
#![allow(unreachable_code)]
// Regression test for #39808. The type parameter of `Owned` was
// considered to be "unconstrained" because the type resulting from
// `format!` (`String`) was not being propagated upward, owing to the
// fact that the expression diverges.
use std::borrow::Cow;
fn main() {
let _ = if false {
Ok(return)
Cow::Owned(format!("{:?}", panic!())) /* as Cow<str> */ // uncomment to fix
} else {
Err("")
Cow::Borrowed("")
};
}