@@ -198,7 +198,7 @@ fn report_forbidden_specialization(tcx: TyCtxt<'_>, impl_item: DefId, parent_imp
198
198
199
199
fn missing_items_err (
200
200
tcx : TyCtxt < ' _ > ,
201
- impl_span : Span ,
201
+ impl_def_id : LocalDefId ,
202
202
missing_items : & [ ty:: AssocItem ] ,
203
203
full_impl_span : Span ,
204
204
) {
@@ -211,6 +211,7 @@ fn missing_items_err(
211
211
. collect :: < Vec < _ > > ( )
212
212
. join ( "`, `" ) ;
213
213
214
+ let impl_span = tcx. def_span ( impl_def_id) ;
214
215
let mut err = struct_span_err ! (
215
216
tcx. sess,
216
217
impl_span,
@@ -229,7 +230,11 @@ fn missing_items_err(
229
230
tcx. sess . source_map ( ) . indentation_before ( sugg_sp) . unwrap_or_else ( || String :: new ( ) ) ;
230
231
231
232
for & trait_item in missing_items {
232
- let snippet = suggestion_signature ( trait_item, tcx) ;
233
+ let snippet = suggestion_signature (
234
+ tcx,
235
+ trait_item,
236
+ tcx. impl_trait_ref ( impl_def_id) . unwrap ( ) . subst_identity ( ) ,
237
+ ) ;
233
238
let code = format ! ( "{}{}\n {}" , padding, snippet, padding) ;
234
239
let msg = format ! ( "implement the missing item: `{snippet}`" ) ;
235
240
let appl = Applicability :: HasPlaceholders ;
@@ -301,11 +306,11 @@ fn default_body_is_unstable(
301
306
/// Re-sugar `ty::GenericPredicates` in a way suitable to be used in structured suggestions.
302
307
fn bounds_from_generic_predicates < ' tcx > (
303
308
tcx : TyCtxt < ' tcx > ,
304
- predicates : ty:: GenericPredicates < ' tcx > ,
309
+ predicates : impl IntoIterator < Item = ( ty:: Predicate < ' tcx > , Span ) > ,
305
310
) -> ( String , String ) {
306
311
let mut types: FxHashMap < Ty < ' tcx > , Vec < DefId > > = FxHashMap :: default ( ) ;
307
312
let mut projections = vec ! [ ] ;
308
- for ( predicate, _) in predicates. predicates {
313
+ for ( predicate, _) in predicates {
309
314
debug ! ( "predicate {:?}" , predicate) ;
310
315
let bound_predicate = predicate. kind ( ) ;
311
316
match bound_predicate. skip_binder ( ) {
@@ -367,7 +372,7 @@ fn fn_sig_suggestion<'tcx>(
367
372
tcx : TyCtxt < ' tcx > ,
368
373
sig : ty:: FnSig < ' tcx > ,
369
374
ident : Ident ,
370
- predicates : ty:: GenericPredicates < ' tcx > ,
375
+ predicates : impl IntoIterator < Item = ( ty:: Predicate < ' tcx > , Span ) > ,
371
376
assoc : ty:: AssocItem ,
372
377
) -> String {
373
378
let args = sig
@@ -436,7 +441,17 @@ pub fn ty_kind_suggestion(ty: Ty<'_>) -> Option<&'static str> {
436
441
/// Return placeholder code for the given associated item.
437
442
/// Similar to `ty::AssocItem::suggestion`, but appropriate for use as the code snippet of a
438
443
/// structured suggestion.
439
- fn suggestion_signature ( assoc : ty:: AssocItem , tcx : TyCtxt < ' _ > ) -> String {
444
+ fn suggestion_signature < ' tcx > (
445
+ tcx : TyCtxt < ' tcx > ,
446
+ assoc : ty:: AssocItem ,
447
+ impl_trait_ref : ty:: TraitRef < ' tcx > ,
448
+ ) -> String {
449
+ let substs = ty:: InternalSubsts :: identity_for_item ( tcx, assoc. def_id ) . rebase_onto (
450
+ tcx,
451
+ assoc. container_id ( tcx) ,
452
+ impl_trait_ref. with_self_ty ( tcx, tcx. types . self_param ) . substs ,
453
+ ) ;
454
+
440
455
match assoc. kind {
441
456
ty:: AssocKind :: Fn => {
442
457
// We skip the binder here because the binder would deanonymize all
@@ -445,16 +460,22 @@ fn suggestion_signature(assoc: ty::AssocItem, tcx: TyCtxt<'_>) -> String {
445
460
// regions just fine, showing `fn(&MyType)`.
446
461
fn_sig_suggestion (
447
462
tcx,
448
- tcx. fn_sig ( assoc. def_id ) . subst_identity ( ) . skip_binder ( ) ,
463
+ tcx. fn_sig ( assoc. def_id ) . subst ( tcx , substs ) . skip_binder ( ) ,
449
464
assoc. ident ( tcx) ,
450
- tcx. predicates_of ( assoc. def_id ) ,
465
+ tcx. predicates_of ( assoc. def_id ) . instantiate_own ( tcx , substs ) ,
451
466
assoc,
452
467
)
453
468
}
454
- ty:: AssocKind :: Type => format ! ( "type {} = Type;" , assoc. name) ,
469
+ ty:: AssocKind :: Type => {
470
+ let ( generics, where_clauses) = bounds_from_generic_predicates (
471
+ tcx,
472
+ tcx. predicates_of ( assoc. def_id ) . instantiate_own ( tcx, substs) ,
473
+ ) ;
474
+ format ! ( "type {}{generics} = /* Type */{where_clauses};" , assoc. name)
475
+ }
455
476
ty:: AssocKind :: Const => {
456
477
let ty = tcx. type_of ( assoc. def_id ) . subst_identity ( ) ;
457
- let val = ty_kind_suggestion ( ty) . unwrap_or ( "value " ) ;
478
+ let val = ty_kind_suggestion ( ty) . unwrap_or ( "todo!() " ) ;
458
479
format ! ( "const {}: {} = {};" , assoc. name, ty, val)
459
480
}
460
481
}
0 commit comments