@@ -101,7 +101,6 @@ pub use crate::{
101
101
PathResolution , Semantics , SemanticsImpl , SemanticsScope , TypeInfo , VisibleTraits ,
102
102
} ,
103
103
} ;
104
- pub use hir_ty:: method_resolution:: TyFingerprint ;
105
104
106
105
// Be careful with these re-exports.
107
106
//
@@ -151,8 +150,9 @@ pub use {
151
150
display:: { ClosureStyle , HirDisplay , HirDisplayError , HirWrite } ,
152
151
dyn_compatibility:: { DynCompatibilityViolation , MethodViolationCode } ,
153
152
layout:: LayoutError ,
153
+ method_resolution:: TyFingerprint ,
154
154
mir:: { MirEvalError , MirLowerError } ,
155
- CastError , FnAbi , PointerCast , Safety ,
155
+ CastError , FnAbi , PointerCast , Safety , Variance ,
156
156
} ,
157
157
// FIXME: Properly encapsulate mir
158
158
hir_ty:: { mir, Interner as ChalkTyInterner } ,
@@ -3957,6 +3957,22 @@ impl GenericParam {
3957
3957
GenericParam :: LifetimeParam ( it) => it. id . parent . into ( ) ,
3958
3958
}
3959
3959
}
3960
+
3961
+ pub fn variance ( self , db : & dyn HirDatabase ) -> Option < Variance > {
3962
+ let parent = match self {
3963
+ GenericParam :: TypeParam ( it) => it. id . parent ( ) ,
3964
+ // const parameters are always invariant
3965
+ GenericParam :: ConstParam ( _) => return None ,
3966
+ GenericParam :: LifetimeParam ( it) => it. id . parent ,
3967
+ } ;
3968
+ let generics = hir_ty:: generics:: generics ( db. upcast ( ) , parent) ;
3969
+ let index = match self {
3970
+ GenericParam :: TypeParam ( it) => generics. type_or_const_param_idx ( it. id . into ( ) ) ?,
3971
+ GenericParam :: ConstParam ( _) => return None ,
3972
+ GenericParam :: LifetimeParam ( it) => generics. lifetime_idx ( it. id ) ?,
3973
+ } ;
3974
+ db. variances_of ( parent) ?. get ( index) . copied ( )
3975
+ }
3960
3976
}
3961
3977
3962
3978
#[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash ) ]
0 commit comments