@@ -30,7 +30,7 @@ use rustc::ty::subst::GenericArgKind;
3030use rustc:: ty:: subst:: { InternalSubsts , Subst } ;
3131use rustc:: ty:: util:: Discr ;
3232use rustc:: ty:: util:: IntTypeExt ;
33- use rustc:: ty:: { self , AdtKind , Const , DefIdTree , ToPolyTraitRef , Ty , TyCtxt } ;
33+ use rustc:: ty:: { self , AdtKind , Const , DefIdTree , ToPolyTraitRef , Ty , TyCtxt , TypeFoldable } ;
3434use rustc:: ty:: { ReprOptions , ToPredicate } ;
3535use rustc_data_structures:: captures:: Captures ;
3636use rustc_data_structures:: fx:: FxHashMap ;
@@ -1352,9 +1352,22 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
13521352 find_opaque_ty_constraints ( tcx, def_id)
13531353 }
13541354 // Opaque types desugared from `impl Trait`.
1355- ItemKind :: OpaqueTy ( hir:: OpaqueTy { impl_trait_fn : Some ( owner) , .. } ) => {
1356- tcx. mir_borrowck ( owner)
1357- . concrete_opaque_types
1355+ ItemKind :: OpaqueTy ( hir:: OpaqueTy {
1356+ impl_trait_fn : Some ( owner) , origin, ..
1357+ } ) => {
1358+ let concrete_types = match origin {
1359+ hir:: OpaqueTyOrigin :: FnReturn | hir:: OpaqueTyOrigin :: AsyncFn => {
1360+ & tcx. mir_borrowck ( owner) . concrete_opaque_types
1361+ }
1362+ hir:: OpaqueTyOrigin :: Misc => {
1363+ // We shouldn't leak borrowck results through impl Trait in bindings.
1364+ & tcx. typeck_tables_of ( owner) . concrete_opaque_types
1365+ }
1366+ hir:: OpaqueTyOrigin :: TypeAlias => {
1367+ span_bug ! ( item. span, "Type alias impl trait shouldn't have an owner" )
1368+ }
1369+ } ;
1370+ let concrete_ty = concrete_types
13581371 . get ( & def_id)
13591372 . map ( |opaque| opaque. concrete_type )
13601373 . unwrap_or_else ( || {
@@ -1369,7 +1382,16 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
13691382 ) ,
13701383 ) ;
13711384 tcx. types . err
1372- } )
1385+ } ) ;
1386+ debug ! ( "concrete_ty = {:?}" , concrete_ty) ;
1387+ if concrete_ty. has_erased_regions ( ) {
1388+ // FIXME(impl_trait_in_bindings) Handle this case.
1389+ tcx. sess . span_fatal (
1390+ item. span ,
1391+ "lifetimes in impl Trait types in bindings are not currently supported" ,
1392+ ) ;
1393+ }
1394+ concrete_ty
13731395 }
13741396 ItemKind :: Trait ( ..)
13751397 | ItemKind :: TraitAlias ( ..)
0 commit comments