diff --git a/src/test/run-pass/try_from.rs b/src/test/run-pass/try_from.rs new file mode 100644 index 000000000000..3f2eb98f861a --- /dev/null +++ b/src/test/run-pass/try_from.rs @@ -0,0 +1,43 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// This test relies on `TryFrom` being auto impl for all `T: Into` +// and `TryInto` being auto impl for all `U: TryFrom` + +// This test was added to show the motivation for doing this +// over `TryFrom` being auto impl for all `T: From` + +#![feature(try_from, never_type)] + +use std::convert::TryInto; + +struct Foo { + t: T +} + +/* +// This fails to compile due to coherence restrictions +// as of rust version 1.32.x +impl From> for Box { + fn from(foo: Foo) -> Box { + Box::new(foo.t) + } +} +*/ + +impl Into> for Foo { + fn into(self) -> Box { + Box::new(self.t) + } +} + +pub fn main() { + let _: Result, !> = Foo { t: 10 }.try_into(); +}