Skip to content

Commit f001e8c

Browse files
committed
Fix an ICE with TAITs and Future
1 parent 6cc0a76 commit f001e8c

File tree

3 files changed

+68
-5
lines changed

3 files changed

+68
-5
lines changed

compiler/rustc_middle/src/ty/error.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -769,11 +769,16 @@ fn foo(&self) -> Self::T { String::new() }
769769
) -> bool {
770770
let assoc = self.associated_item(proj_ty.item_def_id);
771771
if let ty::Opaque(def_id, _) = *proj_ty.self_ty().kind() {
772-
let opaque_local_def_id = def_id.expect_local();
773-
let opaque_hir_id = self.hir().local_def_id_to_hir_id(opaque_local_def_id);
774-
let opaque_hir_ty = match &self.hir().expect_item(opaque_hir_id).kind {
775-
hir::ItemKind::OpaqueTy(opaque_hir_ty) => opaque_hir_ty,
776-
_ => bug!("The HirId comes from a `ty::Opaque`"),
772+
let opaque_local_def_id = def_id.as_local();
773+
let opaque_hir_ty = if let Some(opaque_local_def_id) = opaque_local_def_id {
774+
let hir = self.hir();
775+
let opaque_hir_id = hir.local_def_id_to_hir_id(opaque_local_def_id);
776+
match &hir.expect_item(opaque_hir_id).kind {
777+
hir::ItemKind::OpaqueTy(opaque_hir_ty) => opaque_hir_ty,
778+
_ => bug!("The HirId comes from a `ty::Opaque`"),
779+
}
780+
} else {
781+
return false;
777782
};
778783

779784
let (trait_ref, assoc_substs) = proj_ty.trait_ref_and_own_substs(self);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// edition:2018
2+
3+
#![feature(type_alias_impl_trait)]
4+
5+
use std::future::Future;
6+
7+
type G<'a, T> = impl Future<Output = ()>;
8+
//~^ ERROR: type mismatch resolving `<impl Future as Future>::Output == ()`
9+
//~| ERROR: the trait bound `T: Trait` is not satisfied
10+
11+
trait Trait {
12+
type F: Future<Output = ()>;
13+
14+
fn f(&self) -> Self::F;
15+
16+
fn g<'a>(&'a self) -> G<'a, Self>
17+
where
18+
Self: Sized,
19+
{
20+
async move { self.f().await }
21+
}
22+
}
23+
24+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
error[E0271]: type mismatch resolving `<impl Future as Future>::Output == ()`
2+
--> $DIR/issue-89686.rs:7:17
3+
|
4+
LL | type G<'a, T> = impl Future<Output = ()>;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type
6+
...
7+
LL | async move { self.f().await }
8+
| ------------------ the found `async` block
9+
|
10+
::: $SRC_DIR/core/src/future/mod.rs:LL:COL
11+
|
12+
LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
13+
| ------------------------------- the found opaque type
14+
|
15+
= note: expected unit type `()`
16+
found associated type `<impl Future as Future>::Output`
17+
= help: consider constraining the associated type `<impl Future as Future>::Output` to `()`
18+
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
19+
20+
error[E0277]: the trait bound `T: Trait` is not satisfied
21+
--> $DIR/issue-89686.rs:7:17
22+
|
23+
LL | type G<'a, T> = impl Future<Output = ()>;
24+
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T`
25+
|
26+
help: consider restricting type parameter `T`
27+
|
28+
LL | type G<'a, T: Trait> = impl Future<Output = ()>;
29+
| +++++++
30+
31+
error: aborting due to 2 previous errors
32+
33+
Some errors have detailed explanations: E0271, E0277.
34+
For more information about an error, try `rustc --explain E0271`.

0 commit comments

Comments
 (0)