Skip to content

Commit f945fd8

Browse files
committed
fix rust-lang#95310: ICE about async generators
1 parent be52b4a commit f945fd8

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

compiler/rustc_typeck/src/collect/type_of.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,9 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
579579
debug!("no constraints in typeck results");
580580
return;
581581
}
582+
if matches!(self.tcx.type_of(def_id).kind(), ty::Error(..)) {
583+
self.tcx.sess.abort_if_errors();
584+
}
582585
// Use borrowck to get the type with unerased regions.
583586
let concrete_opaque_types = &self.tcx.mir_borrowck(def_id).concrete_opaque_types;
584587
debug!(?concrete_opaque_types);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#![crate_type="lib"]
2+
#![feature(generators)]
3+
#![feature(generic_associated_types)]
4+
#![feature(type_alias_impl_trait)]
5+
6+
// edition:2021
7+
8+
trait Service {
9+
type Future<'f>: std::future::Future + 'f
10+
where
11+
Self: 'f;
12+
13+
fn spawn<'f>(&'f mut self) -> Self::Future<'f>;
14+
}
15+
16+
struct Blah;
17+
18+
impl Service for Blah {
19+
type Future<'f> = impl std::future::Future<Output = &'static i32> + 'f;
20+
21+
fn spawn<'f>(&'f mut self) -> Self::Future<'f> {
22+
//~^ ERROR: type mismatch resolving
23+
async move {
24+
//~^ ERROR: type mismatch resolving
25+
yield &1; //~ ERROR: `async` generators are not yet supported
26+
}
27+
}
28+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error[E0727]: `async` generators are not yet supported
2+
--> $DIR/async-generator-issue-95310.rs:25:13
3+
|
4+
LL | yield &1;
5+
| ^^^^^^^^
6+
7+
error[E0271]: type mismatch resolving `<[static generator@$DIR/async-generator-issue-95310.rs:23:20: 26:10] as Generator<ResumeTy>>::Yield == ()`
8+
--> $DIR/async-generator-issue-95310.rs:23:20
9+
|
10+
LL | async move {
11+
| ____________________^
12+
LL | |
13+
LL | | yield &1;
14+
LL | | }
15+
| |_________^ expected `()`, found `&{integer}`
16+
|
17+
note: required by a bound in `from_generator`
18+
--> $SRC_DIR/core/src/future/mod.rs:LL:COL
19+
|
20+
LL | T: Generator<ResumeTy, Yield = ()>,
21+
| ^^^^^^^^^^ required by this bound in `from_generator`
22+
23+
error[E0271]: type mismatch resolving `<impl Future<Output = [async output]> as Future>::Output == &'static i32`
24+
--> $DIR/async-generator-issue-95310.rs:21:35
25+
|
26+
LL | fn spawn<'f>(&'f mut self) -> Self::Future<'f> {
27+
| ^^^^^^^^^^^^^^^^ expected `&i32`, found `()`
28+
29+
error: aborting due to 3 previous errors
30+
31+
Some errors have detailed explanations: E0271, E0727.
32+
For more information about an error, try `rustc --explain E0271`.

0 commit comments

Comments
 (0)