@@ -30,7 +30,7 @@ use rustc::ty::subst::GenericArgKind;
30
30
use rustc:: ty:: subst:: { InternalSubsts , Subst } ;
31
31
use rustc:: ty:: util:: Discr ;
32
32
use 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 } ;
34
34
use rustc:: ty:: { ReprOptions , ToPredicate } ;
35
35
use rustc_data_structures:: captures:: Captures ;
36
36
use rustc_data_structures:: fx:: FxHashMap ;
@@ -1352,9 +1352,22 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
1352
1352
find_opaque_ty_constraints ( tcx, def_id)
1353
1353
}
1354
1354
// 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
1358
1371
. get ( & def_id)
1359
1372
. map ( |opaque| opaque. concrete_type )
1360
1373
. unwrap_or_else ( || {
@@ -1369,7 +1382,16 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
1369
1382
) ,
1370
1383
) ;
1371
1384
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
1373
1395
}
1374
1396
ItemKind :: Trait ( ..)
1375
1397
| ItemKind :: TraitAlias ( ..)
0 commit comments