1
1
use rustc_data_structures:: fx:: FxHashSet ;
2
- use rustc_data_structures:: vec_map:: VecMap ;
3
2
use rustc_errors:: { Applicability , ErrorReported , StashKey } ;
4
3
use rustc_hir as hir;
5
4
use rustc_hir:: def:: { DefKind , Res } ;
@@ -10,7 +9,7 @@ use rustc_hir::{HirId, Node};
10
9
use rustc_middle:: hir:: map:: Map ;
11
10
use rustc_middle:: ty:: subst:: { GenericArgKind , InternalSubsts } ;
12
11
use rustc_middle:: ty:: util:: IntTypeExt ;
13
- use rustc_middle:: ty:: { self , DefIdTree , OpaqueTypeKey , Ty , TyCtxt , TypeFoldable } ;
12
+ use rustc_middle:: ty:: { self , DefIdTree , Ty , TyCtxt , TypeFoldable } ;
14
13
use rustc_span:: symbol:: Ident ;
15
14
use rustc_span:: { Span , DUMMY_SP } ;
16
15
@@ -347,36 +346,36 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
347
346
}
348
347
// Opaque types desugared from `impl Trait`.
349
348
ItemKind :: OpaqueTy ( OpaqueTy { impl_trait_fn : Some ( owner) , .. } ) => {
350
- let concrete_ty = find_concrete_ty_from_def_id (
351
- & tcx . mir_borrowck ( owner. expect_local ( ) ) . concrete_opaque_types ,
352
- def_id . to_def_id ( ) ,
353
- )
354
- . map ( |& ( _ , concrete_ty) | concrete_ty)
355
- . unwrap_or_else ( || {
356
- tcx. sess . delay_span_bug (
357
- DUMMY_SP ,
358
- & format ! (
359
- "owner {:?} has no opaque type for {:?} in its typeck results" ,
360
- owner, def_id,
361
- ) ,
362
- ) ;
363
- if let Some ( ErrorReported ) =
364
- tcx. typeck ( owner. expect_local ( ) ) . tainted_by_errors
365
- {
366
- // Some error in the
367
- // owner fn prevented us from populating
368
- // the `concrete_opaque_types` table.
369
- tcx. ty_error ( )
370
- } else {
371
- // We failed to resolve the opaque type or it
372
- // resolves to itself. Return the non-revealed
373
- // type, which should result in E0720.
374
- tcx. mk_opaque (
375
- def_id. to_def_id ( ) ,
376
- InternalSubsts :: identity_for_item ( tcx, def_id. to_def_id ( ) ) ,
377
- )
378
- }
379
- } ) ;
349
+ let concrete_ty = tcx
350
+ . mir_borrowck ( owner. expect_local ( ) )
351
+ . concrete_opaque_types
352
+ . get_by ( | ( key , _ ) | key . def_id == def_id . to_def_id ( ) )
353
+ . map ( |concrete_ty| * concrete_ty)
354
+ . unwrap_or_else ( || {
355
+ tcx. sess . delay_span_bug (
356
+ DUMMY_SP ,
357
+ & format ! (
358
+ "owner {:?} has no opaque type for {:?} in its typeck results" ,
359
+ owner, def_id,
360
+ ) ,
361
+ ) ;
362
+ if let Some ( ErrorReported ) =
363
+ tcx. typeck ( owner. expect_local ( ) ) . tainted_by_errors
364
+ {
365
+ // Some error in the
366
+ // owner fn prevented us from populating
367
+ // the `concrete_opaque_types` table.
368
+ tcx. ty_error ( )
369
+ } else {
370
+ // We failed to resolve the opaque type or it
371
+ // resolves to itself. Return the non-revealed
372
+ // type, which should result in E0720.
373
+ tcx. mk_opaque (
374
+ def_id. to_def_id ( ) ,
375
+ InternalSubsts :: identity_for_item ( tcx, def_id. to_def_id ( ) ) ,
376
+ )
377
+ }
378
+ } ) ;
380
379
debug ! ( "concrete_ty = {:?}" , concrete_ty) ;
381
380
concrete_ty
382
381
}
@@ -516,11 +515,12 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
516
515
}
517
516
// Calling `mir_borrowck` can lead to cycle errors through
518
517
// const-checking, avoid calling it if we don't have to.
519
- if find_concrete_ty_from_def_id (
520
- & self . tcx . typeck ( def_id) . concrete_opaque_types ,
521
- self . def_id ,
522
- )
523
- . is_none ( )
518
+ if self
519
+ . tcx
520
+ . typeck ( def_id)
521
+ . concrete_opaque_types
522
+ . get_by ( |( key, _) | key. def_id == self . def_id )
523
+ . is_none ( )
524
524
{
525
525
debug ! (
526
526
"find_opaque_ty_constraints: no constraint for `{:?}` at `{:?}`" ,
@@ -531,7 +531,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
531
531
// Use borrowck to get the type with unerased regions.
532
532
let concrete_opaque_types = & self . tcx . mir_borrowck ( def_id) . concrete_opaque_types ;
533
533
if let Some ( ( opaque_type_key, concrete_type) ) =
534
- find_concrete_ty_from_def_id ( concrete_opaque_types, self . def_id )
534
+ concrete_opaque_types. iter ( ) . find ( | ( key , _ ) | key . def_id == self . def_id )
535
535
{
536
536
debug ! (
537
537
"find_opaque_ty_constraints: found constraint for `{:?}` at `{:?}`: {:?}" ,
@@ -705,31 +705,32 @@ fn let_position_impl_trait_type(tcx: TyCtxt<'_>, opaque_ty_id: LocalDefId) -> Ty
705
705
let opaque_ty_def_id = opaque_ty_id. to_def_id ( ) ;
706
706
707
707
let owner_typeck_results = tcx. typeck ( scope_def_id) ;
708
- let concrete_ty =
709
- find_concrete_ty_from_def_id ( & owner_typeck_results. concrete_opaque_types , opaque_ty_def_id)
710
- . map ( |& ( _, concrete_ty) | concrete_ty)
711
- . unwrap_or_else ( || {
712
- tcx. sess . delay_span_bug (
713
- DUMMY_SP ,
714
- & format ! (
715
- "owner {:?} has no opaque type for {:?} in its typeck results" ,
716
- scope_def_id, opaque_ty_id
717
- ) ,
718
- ) ;
719
- if let Some ( ErrorReported ) = owner_typeck_results. tainted_by_errors {
720
- // Some error in the owner fn prevented us from populating the
721
- // `concrete_opaque_types` table.
722
- tcx. ty_error ( )
723
- } else {
724
- // We failed to resolve the opaque type or it resolves to
725
- // itself. Return the non-revealed type, which should result in
726
- // E0720.
727
- tcx. mk_opaque (
728
- opaque_ty_def_id,
729
- InternalSubsts :: identity_for_item ( tcx, opaque_ty_def_id) ,
730
- )
731
- }
732
- } ) ;
708
+ let concrete_ty = owner_typeck_results
709
+ . concrete_opaque_types
710
+ . get_by ( |( key, _) | key. def_id == opaque_ty_def_id)
711
+ . map ( |concrete_ty| * concrete_ty)
712
+ . unwrap_or_else ( || {
713
+ tcx. sess . delay_span_bug (
714
+ DUMMY_SP ,
715
+ & format ! (
716
+ "owner {:?} has no opaque type for {:?} in its typeck results" ,
717
+ scope_def_id, opaque_ty_id
718
+ ) ,
719
+ ) ;
720
+ if let Some ( ErrorReported ) = owner_typeck_results. tainted_by_errors {
721
+ // Some error in the owner fn prevented us from populating the
722
+ // `concrete_opaque_types` table.
723
+ tcx. ty_error ( )
724
+ } else {
725
+ // We failed to resolve the opaque type or it resolves to
726
+ // itself. Return the non-revealed type, which should result in
727
+ // E0720.
728
+ tcx. mk_opaque (
729
+ opaque_ty_def_id,
730
+ InternalSubsts :: identity_for_item ( tcx, opaque_ty_def_id) ,
731
+ )
732
+ }
733
+ } ) ;
733
734
debug ! ( "concrete_ty = {:?}" , concrete_ty) ;
734
735
if concrete_ty. has_erased_regions ( ) {
735
736
// FIXME(impl_trait_in_bindings) Handle this case.
@@ -803,10 +804,3 @@ fn check_feature_inherent_assoc_ty(tcx: TyCtxt<'_>, span: Span) {
803
804
. emit ( ) ;
804
805
}
805
806
}
806
-
807
- fn find_concrete_ty_from_def_id < ' tcx > (
808
- concrete_opaque_types : & ' tcx VecMap < OpaqueTypeKey < ' tcx > , Ty < ' tcx > > ,
809
- def_id : DefId ,
810
- ) -> Option < & ' tcx ( OpaqueTypeKey < ' tcx > , Ty < ' tcx > ) > {
811
- concrete_opaque_types. iter ( ) . find ( |( opaque_type_key, _) | opaque_type_key. def_id == def_id)
812
- }
0 commit comments