@@ -20,7 +20,7 @@ use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData};
2020use rustc_middle:: middle:: resolve_lifetime as rl;
2121use rustc_middle:: ty:: fold:: TypeFolder ;
2222use 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 } ;
2424use rustc_middle:: { bug, span_bug} ;
2525use rustc_mir:: const_eval:: { is_const_fn, is_unstable_const_fn} ;
2626use rustc_span:: hygiene:: { AstPass , MacroKind } ;
@@ -435,8 +435,23 @@ impl Clean<GenericParamDef> for ty::GenericParamDef {
435435 let ( name, kind) = match self . kind {
436436 ty:: GenericParamDefKind :: Lifetime => ( self . name , GenericParamDefKind :: Lifetime ) ,
437437 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+ } ;
440455 (
441456 self . name ,
442457 GenericParamDefKind :: Type {
0 commit comments