@@ -33,8 +33,8 @@ use rustc::ty::subst::GenericArgKind;
3333use rustc:: ty:: subst:: { InternalSubsts , Subst } ;
3434use rustc:: ty:: util:: Discr ;
3535use rustc:: ty:: util:: IntTypeExt ;
36- use rustc:: ty:: { self , AdtKind , Const , DefIdTree , ToPolyTraitRef , Ty , TyCtxt , WithConstness } ;
37- use rustc:: ty:: { ReprOptions , ToPredicate } ;
36+ use rustc:: ty:: { self , AdtKind , Const , DefIdTree , ToPolyTraitRef , Ty , TyCtxt , TypeFoldable } ;
37+ use rustc:: ty:: { ReprOptions , ToPredicate , WithConstness } ;
3838use rustc_attr:: { list_contains_name, mark_used, InlineAttr , OptimizeAttr } ;
3939use rustc_data_structures:: captures:: Captures ;
4040use rustc_data_structures:: fx:: FxHashMap ;
@@ -1463,9 +1463,22 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
14631463 find_opaque_ty_constraints ( tcx, def_id)
14641464 }
14651465 // Opaque types desugared from `impl Trait`.
1466- ItemKind :: OpaqueTy ( hir:: OpaqueTy { impl_trait_fn : Some ( owner) , .. } ) => {
1467- tcx. mir_borrowck ( owner)
1468- . concrete_opaque_types
1466+ ItemKind :: OpaqueTy ( hir:: OpaqueTy {
1467+ impl_trait_fn : Some ( owner) , origin, ..
1468+ } ) => {
1469+ let concrete_types = match origin {
1470+ hir:: OpaqueTyOrigin :: FnReturn | hir:: OpaqueTyOrigin :: AsyncFn => {
1471+ & tcx. mir_borrowck ( owner) . concrete_opaque_types
1472+ }
1473+ hir:: OpaqueTyOrigin :: Misc => {
1474+ // We shouldn't leak borrowck results through impl Trait in bindings.
1475+ & tcx. typeck_tables_of ( owner) . concrete_opaque_types
1476+ }
1477+ hir:: OpaqueTyOrigin :: TypeAlias => {
1478+ span_bug ! ( item. span, "Type alias impl trait shouldn't have an owner" )
1479+ }
1480+ } ;
1481+ let concrete_ty = concrete_types
14691482 . get ( & def_id)
14701483 . map ( |opaque| opaque. concrete_type )
14711484 . unwrap_or_else ( || {
@@ -1480,7 +1493,16 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
14801493 ) ,
14811494 ) ;
14821495 tcx. types . err
1483- } )
1496+ } ) ;
1497+ debug ! ( "concrete_ty = {:?}" , concrete_ty) ;
1498+ if concrete_ty. has_erased_regions ( ) {
1499+ // FIXME(impl_trait_in_bindings) Handle this case.
1500+ tcx. sess . span_fatal (
1501+ item. span ,
1502+ "lifetimes in impl Trait types in bindings are not currently supported" ,
1503+ ) ;
1504+ }
1505+ concrete_ty
14841506 }
14851507 ItemKind :: Trait ( ..)
14861508 | ItemKind :: TraitAlias ( ..)
0 commit comments