@@ -15,6 +15,7 @@ use crate::ty::abstract_const::NotConstEvaluatable;
15
15
use crate :: ty:: { self , AdtKind , Ty } ;
16
16
use crate :: ty:: { GenericArgsRef , TyCtxt } ;
17
17
18
+ use hir:: def:: DefKind ;
18
19
use rustc_data_structures:: sync:: Lrc ;
19
20
use rustc_errors:: { Applicability , Diag , EmissionGuarantee } ;
20
21
use rustc_hir as hir;
@@ -1004,7 +1005,7 @@ pub enum CodegenObligationError {
1004
1005
pub enum DefiningAnchor < ' tcx > {
1005
1006
/// Define opaques which are in-scope of the current item being analyzed.
1006
1007
/// Also, eagerly replace these opaque types in `replace_opaque_types_with_inference_vars`.
1007
- Bind ( & ' tcx [ LocalDefId ] ) ,
1008
+ Bind { rpit_and_tait : & ' tcx [ LocalDefId ] , in_assoc_types : & ' tcx [ LocalDefId ] } ,
1008
1009
/// In contexts where we don't currently know what opaques are allowed to be
1009
1010
/// defined, such as (old solver) canonical queries, we will simply allow
1010
1011
/// opaques to be defined, but "bubble" them up in the canonical response or
@@ -1021,6 +1022,19 @@ pub enum DefiningAnchor<'tcx> {
1021
1022
1022
1023
impl < ' tcx > DefiningAnchor < ' tcx > {
1023
1024
pub fn bind ( tcx : TyCtxt < ' tcx > , item : LocalDefId ) -> Self {
1024
- Self :: Bind ( tcx. opaque_types_defined_by ( item) )
1025
+ Self :: Bind {
1026
+ rpit_and_tait : tcx. opaque_types_defined_by ( item) ,
1027
+ in_assoc_types : match tcx. def_kind ( item) {
1028
+ DefKind :: AssocFn | DefKind :: AssocConst | DefKind :: AssocTy => {
1029
+ let parent = tcx. local_parent ( item) ;
1030
+ if matches ! ( tcx. def_kind( parent) , DefKind :: Impl { of_trait: true } ) {
1031
+ tcx. impl_trait_in_assoc_types_defined_by ( item)
1032
+ } else {
1033
+ & [ ]
1034
+ }
1035
+ }
1036
+ _ => & [ ] ,
1037
+ } ,
1038
+ }
1025
1039
}
1026
1040
}
0 commit comments