Skip to content

Commit fa1f547

Browse files
committed
Add more double cast + method call tests
1 parent 8ef3da0 commit fa1f547

File tree

2 files changed

+105
-22
lines changed

2 files changed

+105
-22
lines changed

src/test/ui/parser/issue-35813-postfix-after-cast.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,29 @@ pub fn cast_after_cast() {
3535
let _ = 0i32: i32: i32 as u32 as i32;
3636
}
3737

38+
pub fn cast_cast_method_call() {
39+
let _ = 0i32: i32: i32.count_ones();
40+
//~^ ERROR: casts cannot be followed by a method call
41+
let _ = 0 as i32: i32.count_ones();
42+
//~^ ERROR: casts cannot be followed by a method call
43+
let _ = 0i32: i32 as i32.count_ones();
44+
//~^ ERROR: casts cannot be followed by a method call
45+
let _ = 0 as i32 as i32.count_ones();
46+
//~^ ERROR: casts cannot be followed by a method call
47+
let _ = 0i32: i32: i32 as u32 as i32.count_ones();
48+
//~^ ERROR: casts cannot be followed by a method call
49+
let _ = 0i32: i32.count_ones(): u32;
50+
//~^ ERROR: casts cannot be followed by a method call
51+
let _ = 0 as i32.count_ones(): u32;
52+
//~^ ERROR: casts cannot be followed by a method call
53+
let _ = 0i32: i32.count_ones() as u32;
54+
//~^ ERROR: casts cannot be followed by a method call
55+
let _ = 0 as i32.count_ones() as u32;
56+
//~^ ERROR: casts cannot be followed by a method call
57+
let _ = 0i32: i32: i32.count_ones() as u32 as i32;
58+
//~^ ERROR: casts cannot be followed by a method call
59+
}
60+
3861
// this tests that the precedence for `!x as Y.Z` is still what we expect
3962
pub fn precedence() {
4063
let x: i32 = &vec![1, 2, 3] as &Vec<i32>[0];

src/test/ui/parser/issue-35813-postfix-after-cast.stderr

Lines changed: 82 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,68 +22,128 @@ error: casts cannot be followed by indexing
2222
LL | (&[0i32]): &[i32; 1][0];
2323
| ^^^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `((&[0i32]): &[i32; 1])`
2424

25+
error: casts cannot be followed by a method call
26+
--> $DIR/issue-35813-postfix-after-cast.rs:39:13
27+
|
28+
LL | let _ = 0i32: i32: i32.count_ones();
29+
| ^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(0i32: i32: i32)`
30+
31+
error: casts cannot be followed by a method call
32+
--> $DIR/issue-35813-postfix-after-cast.rs:41:13
33+
|
34+
LL | let _ = 0 as i32: i32.count_ones();
35+
| ^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(0 as i32: i32)`
36+
37+
error: casts cannot be followed by a method call
38+
--> $DIR/issue-35813-postfix-after-cast.rs:43:13
39+
|
40+
LL | let _ = 0i32: i32 as i32.count_ones();
41+
| ^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(0i32: i32 as i32)`
42+
43+
error: casts cannot be followed by a method call
44+
--> $DIR/issue-35813-postfix-after-cast.rs:45:13
45+
|
46+
LL | let _ = 0 as i32 as i32.count_ones();
47+
| ^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(0 as i32 as i32)`
48+
49+
error: casts cannot be followed by a method call
50+
--> $DIR/issue-35813-postfix-after-cast.rs:47:13
51+
|
52+
LL | let _ = 0i32: i32: i32 as u32 as i32.count_ones();
53+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(0i32: i32: i32 as u32 as i32)`
54+
55+
error: casts cannot be followed by a method call
56+
--> $DIR/issue-35813-postfix-after-cast.rs:49:13
57+
|
58+
LL | let _ = 0i32: i32.count_ones(): u32;
59+
| ^^^^^^^^^ help: try surrounding the expression in parentheses: `(0i32: i32)`
60+
61+
error: casts cannot be followed by a method call
62+
--> $DIR/issue-35813-postfix-after-cast.rs:51:13
63+
|
64+
LL | let _ = 0 as i32.count_ones(): u32;
65+
| ^^^^^^^^ help: try surrounding the expression in parentheses: `(0 as i32)`
66+
67+
error: casts cannot be followed by a method call
68+
--> $DIR/issue-35813-postfix-after-cast.rs:53:13
69+
|
70+
LL | let _ = 0i32: i32.count_ones() as u32;
71+
| ^^^^^^^^^ help: try surrounding the expression in parentheses: `(0i32: i32)`
72+
73+
error: casts cannot be followed by a method call
74+
--> $DIR/issue-35813-postfix-after-cast.rs:55:13
75+
|
76+
LL | let _ = 0 as i32.count_ones() as u32;
77+
| ^^^^^^^^ help: try surrounding the expression in parentheses: `(0 as i32)`
78+
79+
error: casts cannot be followed by a method call
80+
--> $DIR/issue-35813-postfix-after-cast.rs:57:13
81+
|
82+
LL | let _ = 0i32: i32: i32.count_ones() as u32 as i32;
83+
| ^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(0i32: i32: i32)`
84+
2585
error: casts cannot be followed by indexing
26-
--> $DIR/issue-35813-postfix-after-cast.rs:40:18
86+
--> $DIR/issue-35813-postfix-after-cast.rs:63:18
2787
|
2888
LL | let x: i32 = &vec![1, 2, 3] as &Vec<i32>[0];
2989
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(&vec![1, 2, 3] as &Vec<i32>)`
3090

3191
error: casts cannot be followed by a method call
32-
--> $DIR/issue-35813-postfix-after-cast.rs:45:5
92+
--> $DIR/issue-35813-postfix-after-cast.rs:68:5
3393
|
3494
LL | 0 as i32.max(0);
3595
| ^^^^^^^^ help: try surrounding the expression in parentheses: `(0 as i32)`
3696

3797
error: casts cannot be followed by a method call
38-
--> $DIR/issue-35813-postfix-after-cast.rs:47:5
98+
--> $DIR/issue-35813-postfix-after-cast.rs:70:5
3999
|
40100
LL | 0: i32.max(0);
41101
| ^^^^^^ help: try surrounding the expression in parentheses: `(0: i32)`
42102

43103
error: casts cannot be followed by a method call
44-
--> $DIR/issue-35813-postfix-after-cast.rs:62:8
104+
--> $DIR/issue-35813-postfix-after-cast.rs:85:8
45105
|
46106
LL | if 5u64 as i32.max(0) == 0 {
47107
| ^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(5u64 as i32)`
48108

49109
error: casts cannot be followed by a method call
50-
--> $DIR/issue-35813-postfix-after-cast.rs:65:8
110+
--> $DIR/issue-35813-postfix-after-cast.rs:88:8
51111
|
52112
LL | if 5u64: u64.max(0) == 0 {
53113
| ^^^^^^^^^ help: try surrounding the expression in parentheses: `(5u64: u64)`
54114

55115
error: casts cannot be followed by a method call
56-
--> $DIR/issue-35813-postfix-after-cast.rs:72:9
116+
--> $DIR/issue-35813-postfix-after-cast.rs:95:9
57117
|
58118
LL | 5u64 as u32.max(0) == 0
59119
| ^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(5u64 as u32)`
60120

61121
error: casts cannot be followed by a method call
62-
--> $DIR/issue-35813-postfix-after-cast.rs:76:9
122+
--> $DIR/issue-35813-postfix-after-cast.rs:99:9
63123
|
64124
LL | 5u64: u64.max(0) == 0
65125
| ^^^^^^^^^ help: try surrounding the expression in parentheses: `(5u64: u64)`
66126

67127
error: casts cannot be followed by indexing
68-
--> $DIR/issue-35813-postfix-after-cast.rs:81:24
128+
--> $DIR/issue-35813-postfix-after-cast.rs:104:24
69129
|
70130
LL | static bar: &[i32] = &(&[1,2,3] as &[i32][0..1]);
71131
| ^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(&[1,2,3] as &[i32])`
72132

73133
error: casts cannot be followed by indexing
74-
--> $DIR/issue-35813-postfix-after-cast.rs:84:25
134+
--> $DIR/issue-35813-postfix-after-cast.rs:107:25
75135
|
76136
LL | static bar2: &[i32] = &(&[1i32,2,3]: &[i32; 3][0..1]);
77137
| ^^^^^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(&[1i32,2,3]: &[i32; 3])`
78138

79139
error: casts cannot be followed by ?
80-
--> $DIR/issue-35813-postfix-after-cast.rs:89:5
140+
--> $DIR/issue-35813-postfix-after-cast.rs:112:5
81141
|
82142
LL | Err(0u64) as Result<u64,u64>?;
83143
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(Err(0u64) as Result<u64,u64>)`
84144

85145
error: casts cannot be followed by ?
86-
--> $DIR/issue-35813-postfix-after-cast.rs:91:5
146+
--> $DIR/issue-35813-postfix-after-cast.rs:114:5
87147
|
88148
LL | Err(0u64): Result<u64,u64>?;
89149
| ^^^^^^^^^-^^^^^^^^^^^^^^^^
@@ -94,25 +154,25 @@ LL | Err(0u64): Result<u64,u64>?;
94154
= note: see issue #23416 <https://github.com/rust-lang/rust/issues/23416> for more information
95155

96156
error: casts cannot be followed by a function call
97-
--> $DIR/issue-35813-postfix-after-cast.rs:115:5
157+
--> $DIR/issue-35813-postfix-after-cast.rs:138:5
98158
|
99159
LL | drop as fn(u8)(0);
100160
| ^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(drop as fn(u8))`
101161

102162
error: casts cannot be followed by a function call
103-
--> $DIR/issue-35813-postfix-after-cast.rs:117:5
163+
--> $DIR/issue-35813-postfix-after-cast.rs:140:5
104164
|
105165
LL | drop_ptr: fn(u8)(0);
106166
| ^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(drop_ptr: fn(u8))`
107167

108168
error: casts cannot be followed by `.await`
109-
--> $DIR/issue-35813-postfix-after-cast.rs:122:5
169+
--> $DIR/issue-35813-postfix-after-cast.rs:145:5
110170
|
111171
LL | Box::pin(noop()) as Pin<Box<dyn Future<Output = ()>>>.await;
112172
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(Box::pin(noop()) as Pin<Box<dyn Future<Output = ()>>>)`
113173

114174
error: casts cannot be followed by `.await`
115-
--> $DIR/issue-35813-postfix-after-cast.rs:125:5
175+
--> $DIR/issue-35813-postfix-after-cast.rs:148:5
116176
|
117177
LL | Box::pin(noop()): Pin<Box<_>>.await;
118178
| ^^^^^^^^^^^^^^^^-^^^^^^^^^^^^
@@ -123,41 +183,41 @@ LL | Box::pin(noop()): Pin<Box<_>>.await;
123183
= note: see issue #23416 <https://github.com/rust-lang/rust/issues/23416> for more information
124184

125185
error: casts cannot be followed by a field access
126-
--> $DIR/issue-35813-postfix-after-cast.rs:137:5
186+
--> $DIR/issue-35813-postfix-after-cast.rs:160:5
127187
|
128188
LL | Foo::default() as Foo.bar;
129189
| ^^^^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(Foo::default() as Foo)`
130190

131191
error: casts cannot be followed by a field access
132-
--> $DIR/issue-35813-postfix-after-cast.rs:139:5
192+
--> $DIR/issue-35813-postfix-after-cast.rs:162:5
133193
|
134194
LL | Foo::default(): Foo.bar;
135195
| ^^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(Foo::default(): Foo)`
136196

137197
error: casts cannot be followed by a method call
138-
--> $DIR/issue-35813-postfix-after-cast.rs:54:9
198+
--> $DIR/issue-35813-postfix-after-cast.rs:77:9
139199
|
140200
LL | if true { 33 } else { 44 } as i32.max(0),
141201
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(if true { 33 } else { 44 } as i32)`
142202

143203
error: casts cannot be followed by a method call
144-
--> $DIR/issue-35813-postfix-after-cast.rs:56:9
204+
--> $DIR/issue-35813-postfix-after-cast.rs:79:9
145205
|
146206
LL | if true { 33 } else { 44 }: i32.max(0)
147207
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try surrounding the expression in parentheses: `(if true { 33 } else { 44 }: i32)`
148208

149209
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
150-
--> $DIR/issue-35813-postfix-after-cast.rs:101:13
210+
--> $DIR/issue-35813-postfix-after-cast.rs:124:13
151211
|
152212
LL | drop as F();
153213
| ^^^ only `Fn` traits may use parentheses
154214

155215
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
156-
--> $DIR/issue-35813-postfix-after-cast.rs:103:15
216+
--> $DIR/issue-35813-postfix-after-cast.rs:126:15
157217
|
158218
LL | drop_ptr: F();
159219
| ^^^ only `Fn` traits may use parentheses
160220

161-
error: aborting due to 25 previous errors
221+
error: aborting due to 35 previous errors
162222

163223
For more information about this error, try `rustc --explain E0214`.

0 commit comments

Comments
 (0)