From db9fe1c86ea3c45a459f2ff63db2aef658ee3b7f Mon Sep 17 00:00:00 2001 From: Ozaren Date: Tue, 18 Dec 2018 23:18:20 -0500 Subject: added test to show motivation for modified TryFrom impl --- src/test/run-pass/try_from.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/test/run-pass/try_from.rs (limited to 'src/test') diff --git a/src/test/run-pass/try_from.rs b/src/test/run-pass/try_from.rs new file mode 100644 index 00000000000..3f2eb98f861 --- /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(); +} -- cgit 1.4.1-3-g733a5