]> git.proxmox.com Git - rustc.git/blob - src/test/ui/type-alias-impl-trait/type-alias-impl-trait.rs
New upstream version 1.38.0+dfsg1
[rustc.git] / src / test / ui / type-alias-impl-trait / type-alias-impl-trait.rs
1 // run-pass
2
3 #![allow(dead_code)]
4 #![allow(unused_assignments)]
5 #![allow(unused_variables)]
6 #![feature(type_alias_impl_trait)]
7
8 fn main() {
9 assert_eq!(foo().to_string(), "foo");
10 assert_eq!(bar1().to_string(), "bar1");
11 assert_eq!(bar2().to_string(), "bar2");
12 let mut x = bar1();
13 x = bar2();
14 assert_eq!(boo::boo().to_string(), "boo");
15 assert_eq!(my_iter(42u8).collect::<Vec<u8>>(), vec![42u8]);
16 }
17
18 // single definition
19 type Foo = impl std::fmt::Display;
20
21 fn foo() -> Foo {
22 "foo"
23 }
24
25 // two definitions
26 type Bar = impl std::fmt::Display;
27
28 fn bar1() -> Bar {
29 "bar1"
30 }
31
32 fn bar2() -> Bar {
33 "bar2"
34 }
35
36 // definition in submodule
37 type Boo = impl std::fmt::Display;
38
39 mod boo {
40 pub fn boo() -> super::Boo {
41 "boo"
42 }
43 }
44
45 type MyIter<T> = impl Iterator<Item = T>;
46
47 fn my_iter<T>(t: T) -> MyIter<T> {
48 std::iter::once(t)
49 }
50
51 fn my_iter2<T>(t: T) -> MyIter<T> {
52 std::iter::once(t)
53 }
54
55 // param names should not have an effect!
56 fn my_iter3<U>(u: U) -> MyIter<U> {
57 std::iter::once(u)
58 }
59
60 // param position should not have an effect!
61 fn my_iter4<U, V>(_: U, v: V) -> MyIter<V> {
62 std::iter::once(v)
63 }
64
65 // param names should not have an effect!
66 type MyOtherIter<T> = impl Iterator<Item = T>;
67
68 fn my_other_iter<U>(u: U) -> MyOtherIter<U> {
69 std::iter::once(u)
70 }
71
72 trait Trait {}
73 type GenericBound<'a, T: Trait> = impl Sized + 'a;
74
75 fn generic_bound<'a, T: Trait + 'a>(t: T) -> GenericBound<'a, T> {
76 t
77 }
78
79 mod pass_through {
80 pub type Passthrough<T> = impl Sized + 'static;
81
82 fn define_passthrough<T: 'static>(t: T) -> Passthrough<T> {
83 t
84 }
85 }
86
87 fn use_passthrough(x: pass_through::Passthrough<u32>) -> pass_through::Passthrough<u32> {
88 x
89 }