Skip to content

Commit 16d152c

Browse files
Add failing tests
1 parent 100199c commit 16d152c

File tree

4 files changed

+175
-3
lines changed

4 files changed

+175
-3
lines changed

tests/ui/parser/bad-fn-ptr-qualifier.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,15 @@ pub type FTT6 = for<'a> const async unsafe extern "C" fn();
2323
//~^ ERROR an `fn` pointer type cannot be `const`
2424
//~| ERROR an `fn` pointer type cannot be `async`
2525

26+
// Tests with qualifiers in the wrong order
27+
pub type W1 = unsafe const fn();
28+
//~^ ERROR an `fn` pointer type cannot be `const`
29+
//~| ERROR expected one of `extern` or `fn`, found keyword `const`
30+
pub type W2 = unsafe async fn();
31+
//~^ ERROR an `fn` pointer type cannot be `async`
32+
//~| ERROR expected one of `extern` or `fn`, found keyword `async`
33+
pub type W3 = for<'a> unsafe const fn();
34+
//~^ ERROR an `fn` pointer type cannot be `const`
35+
//~| ERROR expected one of `extern` or `fn`, found keyword `const`
36+
2637
fn main() {}

tests/ui/parser/bad-fn-ptr-qualifier.stderr

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,5 +222,80 @@ LL - pub type FTT6 = for<'a> const async unsafe extern "C" fn();
222222
LL + pub type FTT6 = for<'a> const unsafe extern "C" fn();
223223
|
224224

225-
error: aborting due to 16 previous errors
225+
error: expected one of `extern` or `fn`, found keyword `const`
226+
--> $DIR/bad-fn-ptr-qualifier.rs:27:22
227+
|
228+
LL | pub type W1 = unsafe const fn();
229+
| -------^^^^^
230+
| | |
231+
| | expected one of `extern` or `fn`
232+
| help: `const` must come before `unsafe`: `const unsafe`
233+
|
234+
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
235+
236+
error: an `fn` pointer type cannot be `const`
237+
--> $DIR/bad-fn-ptr-qualifier.rs:27:15
238+
|
239+
LL | pub type W1 = unsafe const fn();
240+
| ^^^^^^^-----^^^^^
241+
| |
242+
| `const` because of this
243+
|
244+
help: remove the `const` qualifier
245+
|
246+
LL - pub type W1 = unsafe const fn();
247+
LL + pub type W1 = const fn();
248+
|
249+
250+
error: expected one of `extern` or `fn`, found keyword `async`
251+
--> $DIR/bad-fn-ptr-qualifier.rs:30:22
252+
|
253+
LL | pub type W2 = unsafe async fn();
254+
| -------^^^^^
255+
| | |
256+
| | expected one of `extern` or `fn`
257+
| help: `async` must come before `unsafe`: `async unsafe`
258+
|
259+
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
260+
261+
error: an `fn` pointer type cannot be `async`
262+
--> $DIR/bad-fn-ptr-qualifier.rs:30:15
263+
|
264+
LL | pub type W2 = unsafe async fn();
265+
| ^^^^^^^-----^^^^^
266+
| |
267+
| `async` because of this
268+
|
269+
help: remove the `async` qualifier
270+
|
271+
LL - pub type W2 = unsafe async fn();
272+
LL + pub type W2 = async fn();
273+
|
274+
275+
error: expected one of `extern` or `fn`, found keyword `const`
276+
--> $DIR/bad-fn-ptr-qualifier.rs:33:30
277+
|
278+
LL | pub type W3 = for<'a> unsafe const fn();
279+
| -------^^^^^
280+
| | |
281+
| | expected one of `extern` or `fn`
282+
| help: `const` must come before `unsafe`: `const unsafe`
283+
|
284+
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
285+
286+
error: an `fn` pointer type cannot be `const`
287+
--> $DIR/bad-fn-ptr-qualifier.rs:33:15
288+
|
289+
LL | pub type W3 = for<'a> unsafe const fn();
290+
| ^^^^^^^^^^^^^^^-----^^^^^
291+
| |
292+
| `const` because of this
293+
|
294+
help: remove the `const` qualifier
295+
|
296+
LL - pub type W3 = for<'a> unsafe const fn();
297+
LL + pub type W3 = for<'a> const fn();
298+
|
299+
300+
error: aborting due to 22 previous errors
226301

tests/ui/parser/recover/recover-const-async-fn-ptr.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ type FT6 = for<'a> const async unsafe extern "C" fn();
2020
//~^ ERROR an `fn` pointer type cannot be `const`
2121
//~| ERROR an `fn` pointer type cannot be `async`
2222

23+
// Tests with qualifiers in the wrong order
24+
type W1 = unsafe const fn();
25+
//~^ ERROR an `fn` pointer type cannot be `const`
26+
//~| ERROR expected one of `extern` or `fn`, found keyword `const`
27+
type W2 = unsafe async fn();
28+
//~^ ERROR an `fn` pointer type cannot be `async`
29+
//~| ERROR expected one of `extern` or `fn`, found keyword `async`
30+
type W3 = for<'a> unsafe const fn();
31+
//~^ ERROR an `fn` pointer type cannot be `const`
32+
//~| ERROR expected one of `extern` or `fn`, found keyword `const`
33+
2334
fn main() {
2435
let _recovery_witness: () = 0; //~ ERROR mismatched types
2536
}

tests/ui/parser/recover/recover-const-async-fn-ptr.stderr

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,89 @@ LL - type FT6 = for<'a> const async unsafe extern "C" fn();
222222
LL + type FT6 = for<'a> const unsafe extern "C" fn();
223223
|
224224

225+
error: expected one of `extern` or `fn`, found keyword `const`
226+
--> $DIR/recover-const-async-fn-ptr.rs:24:18
227+
|
228+
LL | type W1 = unsafe const fn();
229+
| -------^^^^^
230+
| | |
231+
| | expected one of `extern` or `fn`
232+
| help: `const` must come before `unsafe`: `const unsafe`
233+
|
234+
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
235+
236+
error: an `fn` pointer type cannot be `const`
237+
--> $DIR/recover-const-async-fn-ptr.rs:24:11
238+
|
239+
LL | type W1 = unsafe const fn();
240+
| ^^^^^^^-----^^^^^
241+
| |
242+
| `const` because of this
243+
|
244+
help: remove the `const` qualifier
245+
|
246+
LL - type W1 = unsafe const fn();
247+
LL + type W1 = const fn();
248+
|
249+
250+
error: expected one of `extern` or `fn`, found keyword `async`
251+
--> $DIR/recover-const-async-fn-ptr.rs:27:18
252+
|
253+
LL | type W2 = unsafe async fn();
254+
| -------^^^^^
255+
| | |
256+
| | expected one of `extern` or `fn`
257+
| help: `async` must come before `unsafe`: `async unsafe`
258+
|
259+
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
260+
261+
error: an `fn` pointer type cannot be `async`
262+
--> $DIR/recover-const-async-fn-ptr.rs:27:11
263+
|
264+
LL | type W2 = unsafe async fn();
265+
| ^^^^^^^-----^^^^^
266+
| |
267+
| `async` because of this
268+
|
269+
help: remove the `async` qualifier
270+
|
271+
LL - type W2 = unsafe async fn();
272+
LL + type W2 = async fn();
273+
|
274+
275+
error: expected one of `extern` or `fn`, found keyword `const`
276+
--> $DIR/recover-const-async-fn-ptr.rs:30:26
277+
|
278+
LL | type W3 = for<'a> unsafe const fn();
279+
| -------^^^^^
280+
| | |
281+
| | expected one of `extern` or `fn`
282+
| help: `const` must come before `unsafe`: `const unsafe`
283+
|
284+
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
285+
286+
error: an `fn` pointer type cannot be `const`
287+
--> $DIR/recover-const-async-fn-ptr.rs:30:11
288+
|
289+
LL | type W3 = for<'a> unsafe const fn();
290+
| ^^^^^^^^^^^^^^^-----^^^^^
291+
| |
292+
| `const` because of this
293+
|
294+
help: remove the `const` qualifier
295+
|
296+
LL - type W3 = for<'a> unsafe const fn();
297+
LL + type W3 = for<'a> const fn();
298+
|
299+
225300
error[E0308]: mismatched types
226-
--> $DIR/recover-const-async-fn-ptr.rs:24:33
301+
--> $DIR/recover-const-async-fn-ptr.rs:35:33
227302
|
228303
LL | let _recovery_witness: () = 0;
229304
| -- ^ expected `()`, found integer
230305
| |
231306
| expected due to this
232307

233-
error: aborting due to 17 previous errors
308+
error: aborting due to 23 previous errors
234309

235310
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)