Skip to content

Commit 1f03ede

Browse files
Bless tests, fix ICE with ImplTraitPlaceholder
1 parent 7077530 commit 1f03ede

13 files changed

+245
-192
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,8 +1960,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19601960
//
19611961
// Then, we will create `fn foo(..) -> Foo<'_, '_>`, and
19621962
// hence the elision takes place at the fn site.
1963-
let future_bound =
1964-
this.lower_async_fn_output_type_to_future_bound(output, fn_def_id, span);
1963+
let future_bound = this.lower_async_fn_output_type_to_future_bound(
1964+
output,
1965+
span,
1966+
ImplTraitContext::ReturnPositionOpaqueTy {
1967+
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
1968+
},
1969+
);
19651970

19661971
let generic_params = this.arena.alloc_from_iter(collected_lifetimes.iter().map(
19671972
|&(new_node_id, lifetime, _)| {
@@ -2064,17 +2069,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20642069
fn_node_id: NodeId,
20652070
opaque_ty_node_id: NodeId,
20662071
) -> hir::FnRetTy<'hir> {
2067-
let span = output.span();
2068-
2069-
let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::Async, span, None);
2070-
2071-
let fn_def_id = self.local_def_id(fn_node_id);
2072-
20732072
let kind = self.lower_impl_trait_in_trait(output.span(), opaque_ty_node_id, |lctx| {
2074-
let bound =
2075-
lctx.lower_async_fn_output_type_to_future_bound(output, fn_def_id, output.span());
2073+
let bound = lctx.lower_async_fn_output_type_to_future_bound(
2074+
output,
2075+
output.span(),
2076+
ImplTraitContext::Disallowed(ImplTraitPosition::TraitReturn),
2077+
);
20762078
arena_vec![lctx; bound]
20772079
});
2080+
2081+
let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::Async, output.span(), None);
20782082
let opaque_ty = self.ty(opaque_ty_span, kind);
20792083
hir::FnRetTy::Return(self.arena.alloc(opaque_ty))
20802084
}
@@ -2083,19 +2087,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20832087
fn lower_async_fn_output_type_to_future_bound(
20842088
&mut self,
20852089
output: &FnRetTy,
2086-
fn_def_id: LocalDefId,
20872090
span: Span,
2091+
mut nested_impl_trait_context: ImplTraitContext,
20882092
) -> hir::GenericBound<'hir> {
20892093
// Compute the `T` in `Future<Output = T>` from the return type.
20902094
let output_ty = match output {
20912095
FnRetTy::Ty(ty) => {
20922096
// Not `OpaqueTyOrigin::AsyncFn`: that's only used for the
20932097
// `impl Future` opaque type that `async fn` implicitly
20942098
// generates.
2095-
let mut context = ImplTraitContext::ReturnPositionOpaqueTy {
2096-
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
2097-
};
2098-
self.lower_ty(ty, &mut context)
2099+
self.lower_ty(ty, &mut nested_impl_trait_context)
20992100
}
21002101
FnRetTy::Default(ret_ty_span) => self.arena.alloc(self.ty_tup(*ret_ty_span, &[])),
21012102
};

compiler/rustc_typeck/src/check/closure.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use super::{check_fn, Expectation, FnCtxt, GeneratorTypes};
44

55
use crate::astconv::AstConv;
66
use crate::rustc_middle::ty::subst::Subst;
7+
use hir::def::DefKind;
78
use rustc_hir as hir;
89
use rustc_hir::def_id::DefId;
910
use rustc_hir::lang_items::LangItem;
@@ -680,9 +681,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
680681
.map(|e| e.map_bound(|e| *e).transpose_tuple2())
681682
.find_map(|(p, s)| get_future_output(p.subst(self.tcx, substs), s.0))?,
682683
ty::Error(_) => return None,
684+
ty::Projection(proj)
685+
if self.tcx.def_kind(proj.item_def_id) == DefKind::ImplTraitPlaceholder =>
686+
{
687+
self.tcx
688+
.bound_explicit_item_bounds(proj.item_def_id)
689+
.transpose_iter()
690+
.map(|e| e.map_bound(|e| *e).transpose_tuple2())
691+
.find_map(|(p, s)| get_future_output(p.subst(self.tcx, proj.substs), s.0))?
692+
}
683693
_ => span_bug!(
684694
self.tcx.def_span(expr_def_id),
685-
"async fn generator return type not an inference variable"
695+
"async fn generator return type not an inference variable: {ret_ty}"
686696
),
687697
};
688698

src/test/ui/async-await/async-trait-fn.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// edition:2018
22
trait T {
33
async fn foo() {} //~ ERROR functions in traits cannot be declared `async`
4+
//~^ ERROR mismatched types
45
async fn bar(&self) {} //~ ERROR functions in traits cannot be declared `async`
6+
//~^ ERROR mismatched types
57
async fn baz() { //~ ERROR functions in traits cannot be declared `async`
8+
//~^ ERROR mismatched types
69
// Nested item must not ICE.
710
fn a() {}
811
}

src/test/ui/async-await/async-trait-fn.stderr

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,89 @@ error[E0706]: functions in traits cannot be declared `async`
22
--> $DIR/async-trait-fn.rs:3:5
33
|
44
LL | async fn foo() {}
5-
| -----^^^^^^^^^^^^
5+
| -----^^^^^^^^^
66
| |
77
| `async` because of this
88
|
99
= note: `async` trait functions are not currently supported
1010
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
11+
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
12+
= help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
1113

1214
error[E0706]: functions in traits cannot be declared `async`
13-
--> $DIR/async-trait-fn.rs:4:5
15+
--> $DIR/async-trait-fn.rs:5:5
1416
|
1517
LL | async fn bar(&self) {}
16-
| -----^^^^^^^^^^^^^^^^^
18+
| -----^^^^^^^^^^^^^^
1719
| |
1820
| `async` because of this
1921
|
2022
= note: `async` trait functions are not currently supported
2123
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
24+
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
25+
= help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
2226

2327
error[E0706]: functions in traits cannot be declared `async`
24-
--> $DIR/async-trait-fn.rs:5:5
28+
--> $DIR/async-trait-fn.rs:7:5
29+
|
30+
LL | async fn baz() {
31+
| -----^^^^^^^^^
32+
| |
33+
| `async` because of this
34+
|
35+
= note: `async` trait functions are not currently supported
36+
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
37+
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
38+
= help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
39+
40+
error[E0308]: mismatched types
41+
--> $DIR/async-trait-fn.rs:3:20
42+
|
43+
LL | async fn foo() {}
44+
| ^^ expected associated type, found opaque type
45+
|
46+
::: $SRC_DIR/core/src/future/mod.rs:LL:COL
47+
|
48+
LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
49+
| ------------------------------- the found opaque type
50+
|
51+
= note: expected associated type `<Self as T>::foo::{opaque#0}`
52+
found opaque type `impl Future<Output = ()>`
53+
54+
error[E0308]: mismatched types
55+
--> $DIR/async-trait-fn.rs:5:25
56+
|
57+
LL | async fn bar(&self) {}
58+
| ^^ expected associated type, found opaque type
59+
|
60+
::: $SRC_DIR/core/src/future/mod.rs:LL:COL
61+
|
62+
LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
63+
| ------------------------------- the found opaque type
64+
|
65+
= note: expected associated type `<Self as T>::bar::{opaque#0}`
66+
found opaque type `impl Future<Output = ()>`
67+
68+
error[E0308]: mismatched types
69+
--> $DIR/async-trait-fn.rs:7:20
2570
|
2671
LL | async fn baz() {
27-
| ^----
28-
| |
29-
| _____`async` because of this
30-
| |
72+
| ____________________^
73+
LL | |
3174
LL | | // Nested item must not ICE.
3275
LL | | fn a() {}
3376
LL | | }
34-
| |_____^
77+
| |_____^ expected associated type, found opaque type
3578
|
36-
= note: `async` trait functions are not currently supported
37-
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
79+
::: $SRC_DIR/core/src/future/mod.rs:LL:COL
80+
|
81+
LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
82+
| ------------------------------- the found opaque type
83+
|
84+
= note: expected associated type `<Self as T>::baz::{opaque#0}`
85+
found opaque type `impl Future<Output = ()>`
3886

39-
error: aborting due to 3 previous errors
87+
error: aborting due to 6 previous errors
4088

41-
For more information about this error, try `rustc --explain E0706`.
89+
Some errors have detailed explanations: E0308, E0706.
90+
For more information about an error, try `rustc --explain E0308`.

src/test/ui/async-await/edition-deny-async-fns-2015.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ impl Foo {
1616

1717
trait Bar {
1818
async fn foo() {} //~ ERROR `async fn` is not permitted in Rust 2015
19-
//~^ ERROR functions in traits cannot be declared `async`
19+
//~^ ERROR functions in traits cannot be declared `async`
20+
//~| ERROR mismatched types
2021
}
2122

2223
fn main() {

src/test/ui/async-await/edition-deny-async-fns-2015.stderr

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ LL | async fn foo() {}
5353
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
5454

5555
error[E0670]: `async fn` is not permitted in Rust 2015
56-
--> $DIR/edition-deny-async-fns-2015.rs:36:9
56+
--> $DIR/edition-deny-async-fns-2015.rs:37:9
5757
|
5858
LL | async fn bar() {}
5959
| ^^^^^ to use `async fn`, switch to Rust 2018 or later
@@ -62,7 +62,7 @@ LL | async fn bar() {}
6262
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
6363

6464
error[E0670]: `async fn` is not permitted in Rust 2015
65-
--> $DIR/edition-deny-async-fns-2015.rs:26:9
65+
--> $DIR/edition-deny-async-fns-2015.rs:27:9
6666
|
6767
LL | async fn foo() {}
6868
| ^^^^^ to use `async fn`, switch to Rust 2018 or later
@@ -71,7 +71,7 @@ LL | async fn foo() {}
7171
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
7272

7373
error[E0670]: `async fn` is not permitted in Rust 2015
74-
--> $DIR/edition-deny-async-fns-2015.rs:31:13
74+
--> $DIR/edition-deny-async-fns-2015.rs:32:13
7575
|
7676
LL | async fn bar() {}
7777
| ^^^^^ to use `async fn`, switch to Rust 2018 or later
@@ -83,14 +83,30 @@ error[E0706]: functions in traits cannot be declared `async`
8383
--> $DIR/edition-deny-async-fns-2015.rs:18:5
8484
|
8585
LL | async fn foo() {}
86-
| -----^^^^^^^^^^^^
86+
| -----^^^^^^^^^
8787
| |
8888
| `async` because of this
8989
|
9090
= note: `async` trait functions are not currently supported
9191
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
92+
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
93+
= help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
9294

93-
error: aborting due to 10 previous errors
95+
error[E0308]: mismatched types
96+
--> $DIR/edition-deny-async-fns-2015.rs:18:20
97+
|
98+
LL | async fn foo() {}
99+
| ^^ expected associated type, found opaque type
100+
|
101+
::: $SRC_DIR/core/src/future/mod.rs:LL:COL
102+
|
103+
LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
104+
| ------------------------------- the found opaque type
105+
|
106+
= note: expected associated type `<Self as Bar>::foo::{opaque#0}`
107+
found opaque type `impl Future<Output = ()>`
108+
109+
error: aborting due to 11 previous errors
94110

95-
Some errors have detailed explanations: E0670, E0706.
96-
For more information about an error, try `rustc --explain E0670`.
111+
Some errors have detailed explanations: E0308, E0670, E0706.
112+
For more information about an error, try `rustc --explain E0308`.

src/test/ui/async-await/issues/issue-95307.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ LL | async fn new() -> [u8; _];
88
|
99
= note: `async` trait functions are not currently supported
1010
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
11+
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
12+
= help: add `#![feature(return_position_impl_trait_in_trait)]` to the crate attributes to enable
1113

1214
error: in expressions, `_` can only be used on the left-hand side of an assignment
1315
--> $DIR/issue-95307.rs:7:28

src/test/ui/parser/fn-header-semantic-fail.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ fn main() {
2727
struct Y;
2828
impl X for Y {
2929
async fn ft1() {} //~ ERROR functions in traits cannot be declared `async`
30-
//~^ ERROR has an incompatible type for trait
3130
unsafe fn ft2() {} // OK.
3231
const fn ft3() {} //~ ERROR functions in traits cannot be declared const
3332
extern "C" fn ft4() {}
@@ -36,7 +35,6 @@ fn main() {
3635
//~| ERROR functions in traits cannot be declared const
3736
//~| ERROR functions cannot be both `const` and `async`
3837
//~| ERROR cycle detected
39-
//~| ERROR has an incompatible type for trait
4038
}
4139

4240
impl Y {

0 commit comments

Comments
 (0)