@@ -33,8 +33,8 @@ use rustc::ty::subst::GenericArgKind;
33
33
use rustc:: ty:: subst:: { InternalSubsts , Subst } ;
34
34
use rustc:: ty:: util:: Discr ;
35
35
use 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 } ;
38
38
use rustc_attr:: { list_contains_name, mark_used, InlineAttr , OptimizeAttr } ;
39
39
use rustc_data_structures:: captures:: Captures ;
40
40
use rustc_data_structures:: fx:: FxHashMap ;
@@ -1463,9 +1463,22 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
1463
1463
find_opaque_ty_constraints ( tcx, def_id)
1464
1464
}
1465
1465
// 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
1469
1482
. get ( & def_id)
1470
1483
. map ( |opaque| opaque. concrete_type )
1471
1484
. unwrap_or_else ( || {
@@ -1480,7 +1493,16 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
1480
1493
) ,
1481
1494
) ;
1482
1495
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
1484
1506
}
1485
1507
ItemKind :: Trait ( ..)
1486
1508
| ItemKind :: TraitAlias ( ..)
0 commit comments