@@ -3,7 +3,7 @@ use crate::astconv::AstConv;
33use rustc_hir as hir;
44use rustc_infer:: traits:: util;
55use rustc_middle:: ty:: subst:: InternalSubsts ;
6- use rustc_middle:: ty:: { self , DefIdTree , TyCtxt } ;
6+ use rustc_middle:: ty:: { self , DefIdTree , ImplTraitInTraitData , Ty , TyCtxt } ;
77use rustc_span:: def_id:: DefId ;
88use rustc_span:: Span ;
99
@@ -58,17 +58,10 @@ fn opaque_type_bounds<'tcx>(
5858 tcx : TyCtxt < ' tcx > ,
5959 opaque_def_id : DefId ,
6060 ast_bounds : & ' tcx [ hir:: GenericBound < ' tcx > ] ,
61+ item_ty : Ty < ' tcx > ,
6162 span : Span ,
62- in_trait : bool ,
6363) -> & ' tcx [ ( ty:: Predicate < ' tcx > , Span ) ] {
6464 ty:: print:: with_no_queries!( {
65- let substs = InternalSubsts :: identity_for_item( tcx, opaque_def_id) ;
66- let item_ty = if in_trait {
67- tcx. mk_projection( opaque_def_id, substs)
68- } else {
69- tcx. mk_opaque( opaque_def_id, substs)
70- } ;
71-
7265 let icx = ItemCtxt :: new( tcx, opaque_def_id) ;
7366 let mut bounds = icx. astconv( ) . compute_bounds( item_ty, ast_bounds) ;
7467 // Opaque types are implicitly sized unless a `?Sized` bound is found
@@ -83,7 +76,16 @@ pub(super) fn explicit_item_bounds(
8376 tcx : TyCtxt < ' _ > ,
8477 def_id : DefId ,
8578) -> & ' _ [ ( ty:: Predicate < ' _ > , Span ) ] {
86- let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id. expect_local ( ) ) ;
79+ let rpitit_info = if let Some ( ImplTraitInTraitData :: Trait { opaque_def_id, .. } ) =
80+ tcx. opt_rpitit_info ( def_id)
81+ {
82+ Some ( opaque_def_id)
83+ } else {
84+ None
85+ } ;
86+
87+ let bounds_def_id = rpitit_info. unwrap_or ( def_id) ;
88+ let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( bounds_def_id. expect_local ( ) ) ;
8789 match tcx. hir ( ) . get ( hir_id) {
8890 hir:: Node :: TraitItem ( hir:: TraitItem {
8991 kind : hir:: TraitItemKind :: Type ( bounds, _) ,
@@ -94,7 +96,15 @@ pub(super) fn explicit_item_bounds(
9496 kind : hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy { bounds, in_trait, .. } ) ,
9597 span,
9698 ..
97- } ) => opaque_type_bounds ( tcx, def_id, bounds, * span, * in_trait) ,
99+ } ) => {
100+ let substs = InternalSubsts :: identity_for_item ( tcx, def_id) ;
101+ let item_ty = if * in_trait && rpitit_info. is_none ( ) {
102+ tcx. mk_projection ( def_id, substs)
103+ } else {
104+ tcx. mk_opaque ( def_id, substs)
105+ } ;
106+ opaque_type_bounds ( tcx, bounds_def_id, bounds, item_ty, * span)
107+ }
98108 _ => bug ! ( "item_bounds called on {:?}" , def_id) ,
99109 }
100110}
0 commit comments