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