@@ -20,7 +20,7 @@ use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData};
20
20
use rustc_middle:: middle:: resolve_lifetime as rl;
21
21
use rustc_middle:: ty:: fold:: TypeFolder ;
22
22
use rustc_middle:: ty:: subst:: { InternalSubsts , Subst } ;
23
- use rustc_middle:: ty:: { self , AdtKind , Lift , Ty , TyCtxt } ;
23
+ use rustc_middle:: ty:: { self , AdtKind , DefIdTree , Lift , Ty , TyCtxt } ;
24
24
use rustc_middle:: { bug, span_bug} ;
25
25
use rustc_mir:: const_eval:: { is_const_fn, is_unstable_const_fn} ;
26
26
use rustc_span:: hygiene:: { AstPass , MacroKind } ;
@@ -435,8 +435,23 @@ impl Clean<GenericParamDef> for ty::GenericParamDef {
435
435
let ( name, kind) = match self . kind {
436
436
ty:: GenericParamDefKind :: Lifetime => ( self . name , GenericParamDefKind :: Lifetime ) ,
437
437
ty:: GenericParamDefKind :: Type { has_default, synthetic, .. } => {
438
- let default =
439
- if has_default { Some ( cx. tcx . type_of ( self . def_id ) . clean ( cx) ) } else { None } ;
438
+ let default = if has_default {
439
+ let mut default = cx. tcx . type_of ( self . def_id ) . clean ( cx) ;
440
+
441
+ // We need to reassign the `self_def_id`, if there's a parent (which is the
442
+ // `Self` type), so we can properly render `<Self as X>` casts, because the
443
+ // information about which type `Self` is, is only present here, but not in
444
+ // the cleaning process of the type itself. To resolve this and have the
445
+ // `self_def_id` set, we override it here.
446
+ // See https://github.com/rust-lang/rust/issues/85454
447
+ if let QPath { ref mut self_def_id, .. } = default {
448
+ * self_def_id = cx. tcx . parent ( self . def_id ) ;
449
+ }
450
+
451
+ Some ( default)
452
+ } else {
453
+ None
454
+ } ;
440
455
(
441
456
self . name ,
442
457
GenericParamDefKind :: Type {
0 commit comments