Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,21 @@ pub fn suggest_impl_trait<'tcx>(
infcx.tcx.lang_items().future_output(),
format_as_assoc,
),
(
infcx.tcx.lang_items().async_fn_trait(),
infcx.tcx.lang_items().async_fn_once_output(),
format_as_parenthesized,
),
(
infcx.tcx.lang_items().async_fn_mut_trait(),
infcx.tcx.lang_items().async_fn_once_output(),
format_as_parenthesized,
),
(
infcx.tcx.lang_items().async_fn_once_trait(),
infcx.tcx.lang_items().async_fn_once_output(),
format_as_parenthesized,
),
(
infcx.tcx.lang_items().fn_trait(),
infcx.tcx.lang_items().fn_once_output(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
|
LL | fn ord<a>() -> _ {
| ^ not allowed in type signatures
|
help: replace with an appropriate return type
|
LL - fn ord<a>() -> _ {
LL + fn ord<a>() -> impl AsyncFn() {
|

error[E0392]: lifetime parameter `'g` is never used
--> $DIR/ice-async-closure-variance-issue-148488.rs:3:10
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#![allow(dead_code)]
//@ run-rustfix
//@ edition: 2021

// The suggestion should be `impl AsyncFn()` instead of something like `{async closure@...}`

fn test1() -> impl AsyncFn() {
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
//~| HELP replace with an appropriate return type
//~| SUGGESTION impl AsyncFn()
async || {}
}

fn test2() -> impl AsyncFn(i32) -> i32 {
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
//~| HELP replace with an appropriate return type
//~| SUGGESTION impl AsyncFn(i32) -> i32
async |x: i32| x + 1
}

fn test3() -> impl AsyncFn(i32, i32) -> i32 {
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
//~| HELP replace with an appropriate return type
//~| SUGGESTION impl AsyncFn(i32, i32) -> i32
async |x: i32, y: i32| x + y
}

fn test4() -> impl AsyncFn() {
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
//~| HELP replace with an appropriate return type
//~| SUGGESTION impl AsyncFn()
async || -> () { () }
}

fn test5() -> impl AsyncFn() -> i32 {
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
//~| HELP replace with an appropriate return type
//~| SUGGESTION impl AsyncFn() -> i32
let z = 42;
async move || z
}

fn test6() -> impl AsyncFnMut() -> i32 {
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
//~| HELP replace with an appropriate return type
//~| SUGGESTION impl AsyncFnMut() -> i32
let mut x = 0;
async move || {
x += 1;
x
}
}

fn test7() -> impl AsyncFnOnce() {
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
//~| HELP replace with an appropriate return type
//~| SUGGESTION impl AsyncFnOnce()
let s = String::from("hello");
async move || {
drop(s);
}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#![allow(dead_code)]
//@ run-rustfix
//@ edition: 2021

// The suggestion should be `impl AsyncFn()` instead of something like `{async closure@...}`

fn test1() -> _ {
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
//~| HELP replace with an appropriate return type
//~| SUGGESTION impl AsyncFn()
async || {}
}

fn test2() -> _ {
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
//~| HELP replace with an appropriate return type
//~| SUGGESTION impl AsyncFn(i32) -> i32
async |x: i32| x + 1
}

fn test3() -> _ {
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
//~| HELP replace with an appropriate return type
//~| SUGGESTION impl AsyncFn(i32, i32) -> i32
async |x: i32, y: i32| x + y
}

fn test4() -> _ {
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
//~| HELP replace with an appropriate return type
//~| SUGGESTION impl AsyncFn()
async || -> () { () }
}

fn test5() -> _ {
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
//~| HELP replace with an appropriate return type
//~| SUGGESTION impl AsyncFn() -> i32
let z = 42;
async move || z
}

fn test6() -> _ {
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
//~| HELP replace with an appropriate return type
//~| SUGGESTION impl AsyncFnMut() -> i32
let mut x = 0;
async move || {
x += 1;
x
}
}

fn test7() -> _ {
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
//~| HELP replace with an appropriate return type
//~| SUGGESTION impl AsyncFnOnce()
let s = String::from("hello");
async move || {
drop(s);
}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
--> $DIR/suggest-impl-async-fn-issue-148493.rs:7:15
|
LL | fn test1() -> _ {
| ^ not allowed in type signatures
|
help: replace with an appropriate return type
|
LL - fn test1() -> _ {
LL + fn test1() -> impl AsyncFn() {
|

error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
--> $DIR/suggest-impl-async-fn-issue-148493.rs:14:15
|
LL | fn test2() -> _ {
| ^ not allowed in type signatures
|
help: replace with an appropriate return type
|
LL - fn test2() -> _ {
LL + fn test2() -> impl AsyncFn(i32) -> i32 {
|

error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
--> $DIR/suggest-impl-async-fn-issue-148493.rs:21:15
|
LL | fn test3() -> _ {
| ^ not allowed in type signatures
|
help: replace with an appropriate return type
|
LL - fn test3() -> _ {
LL + fn test3() -> impl AsyncFn(i32, i32) -> i32 {
|

error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
--> $DIR/suggest-impl-async-fn-issue-148493.rs:28:15
|
LL | fn test4() -> _ {
| ^ not allowed in type signatures
|
help: replace with an appropriate return type
|
LL - fn test4() -> _ {
LL + fn test4() -> impl AsyncFn() {
|

error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
--> $DIR/suggest-impl-async-fn-issue-148493.rs:35:15
|
LL | fn test5() -> _ {
| ^ not allowed in type signatures
|
help: replace with an appropriate return type
|
LL - fn test5() -> _ {
LL + fn test5() -> impl AsyncFn() -> i32 {
|

error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
--> $DIR/suggest-impl-async-fn-issue-148493.rs:43:15
|
LL | fn test6() -> _ {
| ^ not allowed in type signatures
|
help: replace with an appropriate return type
|
LL - fn test6() -> _ {
LL + fn test6() -> impl AsyncFnMut() -> i32 {
|

error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
--> $DIR/suggest-impl-async-fn-issue-148493.rs:54:15
|
LL | fn test7() -> _ {
| ^ not allowed in type signatures
|
help: replace with an appropriate return type
|
LL - fn test7() -> _ {
LL + fn test7() -> impl AsyncFnOnce() {
|

error: aborting due to 7 previous errors

For more information about this error, try `rustc --explain E0121`.
Loading