Skip to content

Commit 35a98a7

Browse files
committed
gather_explicit_predicates_of return empty for OpaqueTyOrigin::AsyncFn
1 parent 4642ec9 commit 35a98a7

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

compiler/rustc_typeck/src/collect.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -2158,7 +2158,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
21582158
}
21592159
ItemKind::OpaqueTy(OpaqueTy {
21602160
ref generics,
2161-
origin: hir::OpaqueTyOrigin::AsyncFn(..) | hir::OpaqueTyOrigin::FnReturn(..),
2161+
origin: hir::OpaqueTyOrigin::FnReturn(..),
21622162
..
21632163
}) => {
21642164
// return-position impl trait
@@ -2181,6 +2181,25 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
21812181

21822182
generics
21832183
}
2184+
ItemKind::OpaqueTy(OpaqueTy {
2185+
origin: hir::OpaqueTyOrigin::AsyncFn(..), ..
2186+
}) => {
2187+
// return-position impl trait
2188+
//
2189+
// We don't inherit predicates from the parent here:
2190+
// If we have, say `fn f<'a, T: 'a>() -> impl Sized {}`
2191+
// then the return type is `f::<'static, T>::{{opaque}}`.
2192+
//
2193+
// If we inherited the predicates of `f` then we would
2194+
// require that `T: 'static` to show that the return
2195+
// type is well-formed.
2196+
//
2197+
// The only way to have something with this opaque type
2198+
// is from the return type of the containing function,
2199+
// which will ensure that the function's predicates
2200+
// hold.
2201+
return ty::GenericPredicates { parent: None, predicates: &[] };
2202+
}
21842203
ItemKind::OpaqueTy(OpaqueTy {
21852204
ref generics,
21862205
origin: hir::OpaqueTyOrigin::TyAlias,

0 commit comments

Comments
 (0)