]> git.lizzy.rs Git - rust.git/blob - src/test/ui/type-alias-impl-trait/type-alias-impl-trait.rs
Rollup merge of #92715 - chordtoll:empty-string, r=davidtwco
[rust.git] / src / test / ui / type-alias-impl-trait / type-alias-impl-trait.rs
1 // check-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!(my_iter(42u8).collect::<Vec<u8>>(), vec![42u8]);
15 }
16
17 // single definition
18 type Foo = impl std::fmt::Display;
19
20 fn foo() -> Foo {
21     "foo"
22 }
23
24 // two definitions
25 type Bar = impl std::fmt::Display;
26
27 fn bar1() -> Bar {
28     "bar1"
29 }
30
31 fn bar2() -> Bar {
32     "bar2"
33 }
34
35 type MyIter<T> = impl Iterator<Item = T>;
36
37 fn my_iter<T>(t: T) -> MyIter<T> {
38     std::iter::once(t)
39 }
40
41 fn my_iter2<T>(t: T) -> MyIter<T> {
42     std::iter::once(t)
43 }
44
45 // param names should not have an effect!
46 fn my_iter3<U>(u: U) -> MyIter<U> {
47     std::iter::once(u)
48 }
49
50 // param position should not have an effect!
51 fn my_iter4<U, V>(_: U, v: V) -> MyIter<V> {
52     std::iter::once(v)
53 }
54
55 // param names should not have an effect!
56 type MyOtherIter<T> = impl Iterator<Item = T>;
57
58 fn my_other_iter<U>(u: U) -> MyOtherIter<U> {
59     std::iter::once(u)
60 }
61
62 trait Trait {}
63 type GenericBound<'a, T: Trait + 'a> = impl Sized + 'a;
64
65 fn generic_bound<'a, T: Trait + 'a>(t: T) -> GenericBound<'a, T> {
66     t
67 }
68
69 mod pass_through {
70     pub type Passthrough<T: 'static> = impl Sized + 'static;
71
72     fn define_passthrough<T: 'static>(t: T) -> Passthrough<T> {
73         t
74     }
75 }
76
77 fn use_passthrough(x: pass_through::Passthrough<u32>) -> pass_through::Passthrough<u32> {
78     x
79 }