@@ -7,7 +7,7 @@ use rustc_arena::DroplessArena;
7
7
use rustc_hir:: def:: DefKind ;
8
8
use rustc_hir:: def_id:: { DefId , LocalDefId } ;
9
9
use rustc_middle:: query:: Providers ;
10
- use rustc_middle:: ty:: { self , CrateVariancesMap , SubstsRef , Ty , TyCtxt } ;
10
+ use rustc_middle:: ty:: { self , CrateVariancesMap , ImplTraitInTraitData , SubstsRef , Ty , TyCtxt } ;
11
11
use rustc_middle:: ty:: { TypeSuperVisitable , TypeVisitable } ;
12
12
use std:: ops:: ControlFlow ;
13
13
@@ -51,20 +51,26 @@ fn variances_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Variance] {
51
51
| DefKind :: Struct
52
52
| DefKind :: Union
53
53
| DefKind :: Variant
54
- | DefKind :: Ctor ( ..) => { }
54
+ | DefKind :: Ctor ( ..) => {
55
+ // These are inferred.
56
+ let crate_map = tcx. crate_variances ( ( ) ) ;
57
+ return crate_map. variances . get ( & item_def_id. to_def_id ( ) ) . copied ( ) . unwrap_or ( & [ ] ) ;
58
+ }
55
59
DefKind :: OpaqueTy | DefKind :: ImplTraitPlaceholder => {
56
60
return variance_of_opaque ( tcx, item_def_id) ;
57
61
}
58
- _ => {
59
- // Variance not relevant.
60
- span_bug ! ( tcx. def_span( item_def_id) , "asked to compute variance for wrong kind of item" )
62
+ DefKind :: AssocTy => {
63
+ if let Some ( ImplTraitInTraitData :: Trait { .. } ) =
64
+ tcx. opt_rpitit_info ( item_def_id. to_def_id ( ) )
65
+ {
66
+ return variance_of_opaque ( tcx, item_def_id) ;
67
+ }
61
68
}
69
+ _ => { }
62
70
}
63
71
64
- // Everything else must be inferred.
65
-
66
- let crate_map = tcx. crate_variances ( ( ) ) ;
67
- crate_map. variances . get ( & item_def_id. to_def_id ( ) ) . copied ( ) . unwrap_or ( & [ ] )
72
+ // Variance not relevant.
73
+ span_bug ! ( tcx. def_span( item_def_id) , "asked to compute variance for wrong kind of item" ) ;
68
74
}
69
75
70
76
#[ instrument( level = "trace" , skip( tcx) , ret) ]
0 commit comments