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