1 // Test that various patterns also enforce types.
3 fn variable_no_initializer() {
9 fn tuple_no_initializer() {
13 let (y, z): (&'static u32, &'static u32);
17 fn ref_with_ascribed_static_type() -> u32 {
18 // Check the behavior in some wacky cases.
21 let ref z: &'static u32 = y;
25 fn ref_with_ascribed_any_type() -> u32 {
32 struct Single<T> { value: T }
34 fn struct_no_initializer() {
38 let Single { value: y }: Single<&'static u32>;
43 fn struct_no_initializer_must_normalize() {
44 trait Indirect { type Assoc; }
46 impl Indirect for StaticU32 { type Assoc = &'static u32; }
47 struct Single2<T: Indirect> { value: <T as Indirect>::Assoc }
50 let Single2 { value: mut _y }: Single2<StaticU32>;
54 fn variable_with_initializer() {
56 let y: &'static u32 = &x; //~ ERROR
59 fn underscore_with_initializer() {
61 let _: &'static u32 = &x; //~ ERROR
63 let _: Vec<&'static String> = vec![&String::new()];
64 //~^ ERROR temporary value dropped while borrowed [E0716]
66 let (_, a): (Vec<&'static String>, _) = (vec![&String::new()], 44);
67 //~^ ERROR temporary value dropped while borrowed [E0716]
69 let (_a, b): (Vec<&'static String>, _) = (vec![&String::new()], 44);
70 //~^ ERROR temporary value dropped while borrowed [E0716]
73 fn pair_underscores_with_initializer() {
75 let (_, _): (&'static u32, u32) = (&x, 44); //~ ERROR
78 fn pair_variable_with_initializer() {
80 let (y, _): (&'static u32, u32) = (&x, 44); //~ ERROR
83 fn struct_single_field_variable_with_initializer() {
85 let Single { value: y }: Single<&'static u32> = Single { value: &x }; //~ ERROR
88 fn struct_single_field_underscore_with_initializer() {
90 let Single { value: _ }: Single<&'static u32> = Single { value: &x }; //~ ERROR
93 struct Double<T> { value1: T, value2: T }
95 fn struct_double_field_underscore_with_initializer() {
97 let Double { value1: _, value2: _ }: Double<&'static u32> = Double {
103 fn static_to_a_to_static_through_variable<'a>(x: &'a u32) -> &'static u32 {
110 let y: &'a u32 = &22;
114 fn static_to_a_to_static_through_tuple<'a>(x: &'a u32) -> &'static u32 {
122 let (y, _z): (&'a u32, u32) = (&22, 44);
126 fn static_to_a_to_static_through_struct<'a>(_x: &'a u32) -> &'static u32 {
127 let Single { value: y }: Single<&'a u32> = Single { value: &22 };
131 fn a_to_static_then_static<'a>(x: &'a u32) -> &'static u32 {
132 let (y, _z): (&'static u32, u32) = (x, 44); //~ ERROR