]> git.proxmox.com Git - rustc.git/blob - src/test/ui/type-alias-impl-trait/type-alias-impl-trait2.rs
New upstream version 1.67.1+dfsg1
[rustc.git] / src / test / ui / type-alias-impl-trait / type-alias-impl-trait2.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 use defining_use_scope::*;
18
19 mod defining_use_scope {
20 // single definition
21 pub type Foo = impl std::fmt::Display;
22
23 pub fn foo() -> Foo {
24 "foo"
25 }
26
27 // two definitions
28 pub type Bar = impl std::fmt::Display;
29
30 pub fn bar1() -> Bar {
31 "bar1"
32 }
33
34 pub fn bar2() -> Bar {
35 "bar2"
36 }
37
38 pub type MyIter<T> = impl Iterator<Item = T>;
39
40 pub fn my_iter<T>(t: T) -> MyIter<T> {
41 std::iter::once(t)
42 }
43
44 fn my_iter2<T>(t: T) -> MyIter<T> {
45 std::iter::once(t)
46 }
47
48 // param names should not have an effect!
49 fn my_iter3<U>(u: U) -> MyIter<U> {
50 std::iter::once(u)
51 }
52
53 // param position should not have an effect!
54 fn my_iter4<U, V>(_: U, v: V) -> MyIter<V> {
55 std::iter::once(v)
56 }
57
58 // param names should not have an effect!
59 type MyOtherIter<T> = impl Iterator<Item = T>;
60
61 fn my_other_iter<U>(u: U) -> MyOtherIter<U> {
62 std::iter::once(u)
63 }
64
65 trait Trait {}
66 type GenericBound<'a, T: Trait + 'a> = impl Sized + 'a;
67
68 fn generic_bound<'a, T: Trait + 'a>(t: T) -> GenericBound<'a, T> {
69 t
70 }
71
72 mod pass_through {
73 pub type Passthrough<T: 'static> = impl Sized + 'static;
74
75 fn define_passthrough<T: 'static>(t: T) -> Passthrough<T> {
76 t
77 }
78 }
79
80 fn use_passthrough(x: pass_through::Passthrough<u32>) -> pass_through::Passthrough<u32> {
81 x
82 }
83
84 }