Rollup merge of #62241 - Centril:fix-async-unsafe-order, r=petrochenkov
Always parse 'async unsafe fn' + properly ban in 2015 Parse `async unsafe fn` not `unsafe async fn` in implementations. We also take the opportunity to properly ban `async fn` in Rust 2015 when they are inside implementations. Closes https://github.com/rust-lang/rust/issues/62232. cc https://github.com/rust-lang/rust/pull/61319, https://github.com/rust-lang/rust/issues/62121, and https://github.com/rust-lang/rust/issues/62149. r? @petrochenkov
This commit is contained in:
commit
43eba5fef2
7 changed files with 77 additions and 28 deletions
|
|
@ -134,11 +134,15 @@ trait Bar {
|
|||
}
|
||||
|
||||
impl Foo {
|
||||
async fn async_method(x: u8) -> u8 {
|
||||
async fn async_assoc_item(x: u8) -> u8 {
|
||||
unsafe {
|
||||
unsafe_async_fn(x).await
|
||||
}
|
||||
}
|
||||
|
||||
async unsafe fn async_unsafe_assoc_item(x: u8) -> u8 {
|
||||
unsafe_async_fn(x).await
|
||||
}
|
||||
}
|
||||
|
||||
fn test_future_yields_once_then_returns<F, Fut>(f: F)
|
||||
|
|
@ -180,12 +184,17 @@ fn main() {
|
|||
async_fn,
|
||||
generic_async_fn,
|
||||
async_fn_with_internal_borrow,
|
||||
Foo::async_method,
|
||||
Foo::async_assoc_item,
|
||||
|x| {
|
||||
async move {
|
||||
unsafe { unsafe_async_fn(x).await }
|
||||
}
|
||||
},
|
||||
|x| {
|
||||
async move {
|
||||
unsafe { Foo::async_unsafe_assoc_item(x).await }
|
||||
}
|
||||
},
|
||||
}
|
||||
test_with_borrow! {
|
||||
async_block_with_borrow_named_lifetime,
|
||||
|
|
|
|||
|
|
@ -28,6 +28,12 @@ fn main() {
|
|||
async fn foo() {} //~ ERROR `async fn` is not permitted in the 2015 edition
|
||||
}
|
||||
|
||||
accept_item! {
|
||||
impl Foo {
|
||||
async fn bar() {} //~ ERROR `async fn` is not permitted in the 2015 edition
|
||||
}
|
||||
}
|
||||
|
||||
let inside_closure = || {
|
||||
async fn bar() {} //~ ERROR `async fn` is not permitted in the 2015 edition
|
||||
};
|
||||
|
|
|
|||
|
|
@ -23,7 +23,19 @@ LL | async fn async_baz() {
|
|||
| ^^^^^
|
||||
|
||||
error[E0670]: `async fn` is not permitted in the 2015 edition
|
||||
--> $DIR/edition-deny-async-fns-2015.rs:32:9
|
||||
--> $DIR/edition-deny-async-fns-2015.rs:16:5
|
||||
|
|
||||
LL | async fn foo() {}
|
||||
| ^^^^^
|
||||
|
||||
error[E0670]: `async fn` is not permitted in the 2015 edition
|
||||
--> $DIR/edition-deny-async-fns-2015.rs:20:5
|
||||
|
|
||||
LL | async fn foo() {}
|
||||
| ^^^^^
|
||||
|
||||
error[E0670]: `async fn` is not permitted in the 2015 edition
|
||||
--> $DIR/edition-deny-async-fns-2015.rs:38:9
|
||||
|
|
||||
LL | async fn bar() {}
|
||||
| ^^^^^
|
||||
|
|
@ -35,10 +47,10 @@ LL | async fn foo() {}
|
|||
| ^^^^^
|
||||
|
||||
error[E0670]: `async fn` is not permitted in the 2015 edition
|
||||
--> $DIR/edition-deny-async-fns-2015.rs:16:5
|
||||
--> $DIR/edition-deny-async-fns-2015.rs:33:13
|
||||
|
|
||||
LL | async fn foo() {}
|
||||
| ^^^^^
|
||||
LL | async fn bar() {}
|
||||
| ^^^^^
|
||||
|
||||
error[E0706]: trait fns cannot be declared `async`
|
||||
--> $DIR/edition-deny-async-fns-2015.rs:20:5
|
||||
|
|
@ -46,12 +58,6 @@ error[E0706]: trait fns cannot be declared `async`
|
|||
LL | async fn foo() {}
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0670]: `async fn` is not permitted in the 2015 edition
|
||||
--> $DIR/edition-deny-async-fns-2015.rs:20:5
|
||||
|
|
||||
LL | async fn foo() {}
|
||||
| ^^^^^
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0670`.
|
||||
|
|
|
|||
11
src/test/ui/async-await/no-unsafe-async.rs
Normal file
11
src/test/ui/async-await/no-unsafe-async.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
// edition:2018
|
||||
|
||||
struct S;
|
||||
|
||||
impl S {
|
||||
#[cfg(FALSE)]
|
||||
unsafe async fn g() {} //~ ERROR expected one of `extern` or `fn`, found `async`
|
||||
}
|
||||
|
||||
#[cfg(FALSE)]
|
||||
unsafe async fn f() {} //~ ERROR expected one of `extern`, `fn`, or `{`, found `async`
|
||||
14
src/test/ui/async-await/no-unsafe-async.stderr
Normal file
14
src/test/ui/async-await/no-unsafe-async.stderr
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
error: expected one of `extern` or `fn`, found `async`
|
||||
--> $DIR/no-unsafe-async.rs:7:12
|
||||
|
|
||||
LL | unsafe async fn g() {}
|
||||
| ^^^^^ expected one of `extern` or `fn` here
|
||||
|
||||
error: expected one of `extern`, `fn`, or `{`, found `async`
|
||||
--> $DIR/no-unsafe-async.rs:11:8
|
||||
|
|
||||
LL | unsafe async fn f() {}
|
||||
| ^^^^^ expected one of `extern`, `fn`, or `{` here
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue