@@ -101,7 +101,6 @@ pub use crate::{
101101 PathResolution , Semantics , SemanticsImpl , SemanticsScope , TypeInfo , VisibleTraits ,
102102 } ,
103103} ;
104- pub use hir_ty:: method_resolution:: TyFingerprint ;
105104
106105// Be careful with these re-exports.
107106//
@@ -151,8 +150,9 @@ pub use {
151150 display:: { ClosureStyle , HirDisplay , HirDisplayError , HirWrite } ,
152151 dyn_compatibility:: { DynCompatibilityViolation , MethodViolationCode } ,
153152 layout:: LayoutError ,
153+ method_resolution:: TyFingerprint ,
154154 mir:: { MirEvalError , MirLowerError } ,
155- CastError , FnAbi , PointerCast , Safety ,
155+ CastError , FnAbi , PointerCast , Safety , Variance ,
156156 } ,
157157 // FIXME: Properly encapsulate mir
158158 hir_ty:: { mir, Interner as ChalkTyInterner } ,
@@ -3957,6 +3957,22 @@ impl GenericParam {
39573957 GenericParam :: LifetimeParam ( it) => it. id . parent . into ( ) ,
39583958 }
39593959 }
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+ }
39603976}
39613977
39623978#[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash ) ]
0 commit comments