Debian Codegraph @

gcc/testsuite/rust/compile/issue-1893.rs

raw
1 #[lang = "sized"]
2 pub trait Sized {}
3
4 pub enum Option<T> {
5 None,
6 Some(T),
7 }
8
9 pub enum Result<T, E> {
10 Ok(T),
11 Err(E),
12 }
13
14 pub trait TryFrom<T> {
15 type Error;
16
17 fn try_from(value: T) -> Result<Self, Self::Error>;
18 }
19
20 pub trait From<T> {
21 fn from(_: T) -> Self;
22 }
23
24 impl<T> From<T> for T {
25 fn from(t: T) -> T {
26 t
27 }
28 }
29
30 impl<T, U> TryFrom<U> for T
31 where
32 T: From<U>,
33 {
34 type Error = !;
35
36 fn try_from(value: U) -> Result<Self, Self::Error> {
37 Result::Ok(T::from(value))
38 }
39 }
40
41 pub fn test(n: usize) {
42 let _a = <usize>::try_from(n);
43 }