3 #![feature(type_ascription)]
4 use std::future::Future;
7 // This tests the parser for "x as Y[z]". It errors, but we want to give useful
8 // errors and parse such that further code gives useful errors.
9 pub fn index_after_as_cast() {
10 vec![1, 2, 3] as Vec<i32>[0];
11 //~^ ERROR: casts cannot be followed by indexing
12 vec![1, 2, 3]: Vec<i32>[0];
13 //~^ ERROR: casts cannot be followed by indexing
16 pub fn index_after_cast_to_index() {
18 //~^ ERROR: casts cannot be followed by indexing
19 (&[0i32]): &[i32; 1][0];
20 //~^ ERROR: casts cannot be followed by indexing
23 pub fn cast_after_cast() {
24 if 5u64 as i32 as u16 == 0u16 {
27 if 5u64: u64: u64 == 0u64 {
30 let _ = 5u64: u64: u64 as u8 as i8 == 9i8;
31 let _ = 0i32: i32: i32;
32 let _ = 0 as i32: i32;
33 let _ = 0i32: i32 as i32;
34 let _ = 0 as i32 as i32;
35 let _ = 0i32: i32: i32 as u32 as i32;
38 // this tests that the precedence for `!x as Y.Z` is still what we expect
40 let x: i32 = &vec![1, 2, 3] as &Vec<i32>[0];
41 //~^ ERROR: casts cannot be followed by indexing
44 pub fn method_calls() {
46 //~^ ERROR: casts cannot be followed by a method call
48 //~^ ERROR: casts cannot be followed by a method call
54 if true { 33 } else { 44 } as i32.max(0),
55 //~^ ERROR: casts cannot be followed by a method call
56 if true { 33 } else { 44 }: i32.max(0)
57 //~^ ERROR: casts cannot be followed by a method call
61 pub fn in_condition() {
62 if 5u64 as i32.max(0) == 0 {
63 //~^ ERROR: casts cannot be followed by a method call
65 if 5u64: u64.max(0) == 0 {
66 //~^ ERROR: casts cannot be followed by a method call
70 pub fn inside_block() {
72 5u64 as u32.max(0) == 0
73 //~^ ERROR: casts cannot be followed by a method call
77 //~^ ERROR: casts cannot be followed by a method call
81 static bar: &[i32] = &(&[1,2,3] as &[i32][0..1]);
82 //~^ ERROR: casts cannot be followed by indexing
84 static bar2: &[i32] = &(&[1i32,2,3]: &[i32; 3][0..1]);
85 //~^ ERROR: casts cannot be followed by indexing
88 pub fn cast_then_try() -> Result<u64,u64> {
89 Err(0u64) as Result<u64,u64>?;
90 //~^ ERROR: casts cannot be followed by ?
91 Err(0u64): Result<u64,u64>?;
92 //~^ ERROR: casts cannot be followed by ?
97 pub fn cast_then_call() {
99 // type ascription won't actually do [unique drop fn type] -> fn(u8) casts.
100 let drop_ptr = drop as fn(u8);
102 //~^ ERROR: parenthesized type parameters may only be used with a `Fn` trait [E0214]
104 //~^ ERROR: parenthesized type parameters may only be used with a `Fn` trait [E0214]
107 pub fn cast_to_fn_should_work() {
108 let drop_ptr = drop as fn(u8);
113 pub fn parens_after_cast_error() {
114 let drop_ptr = drop as fn(u8);
116 //~^ ERROR: casts cannot be followed by a function call
118 //~^ ERROR: casts cannot be followed by a function call
121 pub async fn cast_then_await() {
122 Box::pin(noop()) as Pin<Box<dyn Future<Output = ()>>>.await;
123 //~^ ERROR: casts cannot be followed by `.await`
125 Box::pin(noop()): Pin<Box<_>>.await;
126 //~^ ERROR: casts cannot be followed by `.await`
129 pub async fn noop() {}
136 pub fn struct_field() {
137 Foo::default() as Foo.bar;
138 //~^ ERROR: cannot be followed by a field access
139 Foo::default(): Foo.bar;
140 //~^ ERROR: cannot be followed by a field access