File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ // This test relies on `TryFrom` being auto impl for all `T: Into`
12
+ // and `TryInto` being auto impl for all `U: TryFrom`
13
+
14
+ // This test was added to show the motivation for doing this
15
+ // over `TryFrom` being auto impl for all `T: From`
16
+
17
+ #![ feature( try_from, never_type) ]
18
+
19
+ use std:: convert:: TryInto ;
20
+
21
+ struct Foo < T > {
22
+ t : T
23
+ }
24
+
25
+ /*
26
+ // This fails to compile due to coherence restrictions
27
+ // as of rust version 1.32.x
28
+ impl<T> From<Foo<T>> for Box<T> {
29
+ fn from(foo: Foo<T>) -> Box<T> {
30
+ Box::new(foo.t)
31
+ }
32
+ }
33
+ */
34
+
35
+ impl < T > Into < Box < T > > for Foo < T > {
36
+ fn into ( self ) -> Box < T > {
37
+ Box :: new ( self . t )
38
+ }
39
+ }
40
+
41
+ pub fn main ( ) {
42
+ let _: Result < Box < i32 > , !> = Foo { t : 10 } . try_into ( ) ;
43
+ }
You can’t perform that action at this time.
0 commit comments