Skip to content

Commit

Permalink
add regression test for rust-lang#39808
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Mar 18, 2017
1 parent f7a6edb commit 93962af
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/test/run-pass/issue-39808.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
};
}

0 comments on commit 93962af

Please sign in to comment.