@@ -98,6 +98,12 @@ pub fn rustdoc_item_def2type<I: CrateIndexer>(
9898/// Convert a type alias definition from the JSON documentation
9999/// for a crate into our own representation for types.
100100///
101+ /// With [`TypeAliasResolution::Resolve`], the alias is transparent and the
102+ /// returned type is the (recursively-resolved) right-hand side.
103+ /// With [`TypeAliasResolution::Preserve`], the alias identity is kept and the
104+ /// returned type is a [`Type::TypeAlias`] pointing at `item` itself — mirroring
105+ /// how [`rustdoc_new_type_def2type`] returns a [`Type::Path`] for nominal types.
106+ ///
101107/// # Panics
102108///
103109/// Panics if the item isn't a type alias.
@@ -113,12 +119,43 @@ pub fn rustdoc_type_alias2type<I: CrateIndexer>(
113119 item. inner. kind( )
114120 )
115121 } ;
116- let resolved = resolve_type (
117- & inner. type_ ,
118- & krate. core . package_id ,
119- krate_collection,
120- & GenericBindings :: default ( ) ,
121- alias_resolution,
122- ) ?;
123- Ok ( resolved)
122+ let ty = if alias_resolution != TypeAliasResolution :: Preserve {
123+ resolve_type (
124+ & inner. type_ ,
125+ & krate. core . package_id ,
126+ krate_collection,
127+ & GenericBindings :: default ( ) ,
128+ alias_resolution,
129+ ) ?
130+ } else {
131+ // Don't resolve the aliased type if the resolution strategy is set to "preserve".
132+ let path = krate. import_index . items [ & item. id ] . canonical_path ( ) ;
133+ let generic_arguments = inner
134+ . generics
135+ . params
136+ . iter ( )
137+ . map ( |param| match & param. kind {
138+ rustdoc_types:: GenericParamDefKind :: Lifetime { .. } => {
139+ GenericArgument :: Lifetime ( GenericLifetimeParameter :: from_name ( & param. name ) )
140+ }
141+ rustdoc_types:: GenericParamDefKind :: Type { .. } => {
142+ GenericArgument :: TypeParameter ( Type :: Generic ( Generic {
143+ name : param. name . clone ( ) ,
144+ } ) )
145+ }
146+ rustdoc_types:: GenericParamDefKind :: Const { .. } => {
147+ GenericArgument :: Const ( ConstGenericArgument {
148+ value : param. name . clone ( ) ,
149+ } )
150+ }
151+ } )
152+ . collect ( ) ;
153+ Type :: TypeAlias ( PathType {
154+ package_id : krate. core . package_id . clone ( ) ,
155+ rustdoc_id : Some ( item. id ) ,
156+ base_type : path. into ( ) ,
157+ generic_arguments,
158+ } )
159+ } ;
160+ Ok ( ty)
124161}
0 commit comments