]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/user-annotations/adt-nullary-enums.rs
7a8f55a800b9268b54ed68e4d8e9a66857e544e1
[rust.git] / src / test / ui / nll / user-annotations / adt-nullary-enums.rs
1 // Unit test for the "user substitutions" that are annotated on each
2 // node.
3
4 #![feature(nll)]
5 #![allow(warnings)]
6
7 use std::cell::Cell;
8
9 enum SomeEnum<T> {
10     SomeVariant(T),
11     SomeOtherVariant,
12 }
13
14 fn combine<T>(_: T, _: T) { }
15
16 fn no_annot() {
17     let c = 66;
18     combine(SomeEnum::SomeVariant(Cell::new(&c)), SomeEnum::SomeOtherVariant);
19 }
20
21 fn annot_underscore() {
22     let c = 66;
23     combine(SomeEnum::SomeVariant(Cell::new(&c)), SomeEnum::SomeOtherVariant::<Cell<_>>);
24 }
25
26 fn annot_reference_any_lifetime() {
27     let c = 66;
28     combine(SomeEnum::SomeVariant(Cell::new(&c)), SomeEnum::SomeOtherVariant::<Cell<&u32>>);
29 }
30
31 fn annot_reference_static_lifetime() {
32     let c = 66;
33     combine(
34         SomeEnum::SomeVariant(Cell::new(&c)), //~ ERROR
35         SomeEnum::SomeOtherVariant::<Cell<&'static u32>>,
36     );
37 }
38
39 fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
40     let c = 66;
41     combine(
42         SomeEnum::SomeVariant(Cell::new(&c)), //~ ERROR
43         SomeEnum::SomeOtherVariant::<Cell<&'a u32>>,
44     );
45 }
46
47 fn annot_reference_named_lifetime_ok<'a>(c: &'a u32) {
48     combine(SomeEnum::SomeVariant(Cell::new(c)), SomeEnum::SomeOtherVariant::<Cell<&'a u32>>);
49 }
50
51 fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
52     let _closure = || {
53         let c = 66;
54         combine(
55             SomeEnum::SomeVariant(Cell::new(&c)), //~ ERROR
56             SomeEnum::SomeOtherVariant::<Cell<&'a u32>>,
57         );
58     };
59 }
60
61 fn annot_reference_named_lifetime_in_closure_ok<'a>(c: &'a u32) {
62     let _closure = || {
63         combine(
64             SomeEnum::SomeVariant(Cell::new(c)),
65             SomeEnum::SomeOtherVariant::<Cell<&'a u32>>,
66         );
67     };
68 }
69
70 fn main() { }