Skip to content

Commit 6a84d34

Browse files
committed
Create a valid Res in external_path()
The order of the `where` bounds on auto trait impls changed because rustdoc currently sorts auto trait `where` bounds based on the `Debug` output for the bound. Now that the bounds have an actual `Res`, they are being unintentionally sorted by their `DefId` rather than their path. So, I had to update a test for the change in ordering of the rendered bounds.
1 parent 0bb1c28 commit 6a84d34

File tree

4 files changed

+13
-20
lines changed

4 files changed

+13
-20
lines changed

src/librustdoc/clean/mod.rs

+5-14
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl Clean<Type> for (ty::TraitRef<'_>, &[TypeBinding]) {
166166
inline::record_extern_fqn(cx, trait_ref.def_id, kind);
167167
let path = external_path(
168168
cx,
169-
cx.tcx.item_name(trait_ref.def_id),
169+
trait_ref.def_id,
170170
Some(trait_ref.def_id),
171171
true,
172172
bounds.to_vec(),
@@ -1448,19 +1448,12 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
14481448
AdtKind::Enum => ItemType::Enum,
14491449
};
14501450
inline::record_extern_fqn(cx, did, kind);
1451-
let path = external_path(cx, cx.tcx.item_name(did), None, false, vec![], substs);
1451+
let path = external_path(cx, did, None, false, vec![], substs);
14521452
ResolvedPath { path, did, is_generic: false }
14531453
}
14541454
ty::Foreign(did) => {
14551455
inline::record_extern_fqn(cx, did, ItemType::ForeignType);
1456-
let path = external_path(
1457-
cx,
1458-
cx.tcx.item_name(did),
1459-
None,
1460-
false,
1461-
vec![],
1462-
InternalSubsts::empty(),
1463-
);
1456+
let path = external_path(cx, did, None, false, vec![], InternalSubsts::empty());
14641457
ResolvedPath { path, did, is_generic: false }
14651458
}
14661459
ty::Dynamic(ref obj, ref reg) => {
@@ -1484,8 +1477,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
14841477

14851478
for did in dids {
14861479
let empty = cx.tcx.intern_substs(&[]);
1487-
let path =
1488-
external_path(cx, cx.tcx.item_name(did), Some(did), false, vec![], empty);
1480+
let path = external_path(cx, did, Some(did), false, vec![], empty);
14891481
inline::record_extern_fqn(cx, did, ItemType::Trait);
14901482
let bound = PolyTrait {
14911483
trait_: ResolvedPath { path, did, is_generic: false },
@@ -1502,8 +1494,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
15021494
});
15031495
}
15041496

1505-
let path =
1506-
external_path(cx, cx.tcx.item_name(did), Some(did), false, bindings, substs);
1497+
let path = external_path(cx, did, Some(did), false, bindings, substs);
15071498
bounds.insert(
15081499
0,
15091500
PolyTrait {

src/librustdoc/clean/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ impl GenericBound {
11581158
crate fn maybe_sized(cx: &mut DocContext<'_>) -> GenericBound {
11591159
let did = cx.tcx.require_lang_item(LangItem::Sized, None);
11601160
let empty = cx.tcx.intern_substs(&[]);
1161-
let path = external_path(cx, cx.tcx.item_name(did), Some(did), false, vec![], empty);
1161+
let path = external_path(cx, did, Some(did), false, vec![], empty);
11621162
inline::record_extern_fqn(cx, did, ItemType::Trait);
11631163
GenericBound::TraitBound(
11641164
PolyTrait {

src/librustdoc/clean/utils.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,21 @@ fn external_generic_args(
141141
}
142142
}
143143

144-
// trait_did should be set to a trait's DefId if called on a TraitRef, in order to sugar
145-
// from Fn<(A, B,), C> to Fn(A, B) -> C
144+
/// trait_did should be set to a trait's DefId if called on a TraitRef, in order to sugar
145+
/// from `Fn<(A, B,), C>` to `Fn(A, B) -> C`
146146
pub(super) fn external_path(
147147
cx: &mut DocContext<'_>,
148-
name: Symbol,
148+
did: DefId,
149149
trait_did: Option<DefId>,
150150
has_self: bool,
151151
bindings: Vec<TypeBinding>,
152152
substs: SubstsRef<'_>,
153153
) -> Path {
154+
let def_kind = cx.tcx.def_kind(did);
155+
let name = cx.tcx.item_name(did);
154156
Path {
155157
global: false,
156-
res: Res::Err,
158+
res: Res::Def(def_kind, did),
157159
segments: vec![PathSegment {
158160
name,
159161
args: external_generic_args(cx, trait_did, has_self, bindings, substs),

src/test/rustdoc/synthetic_auto/no-redundancy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ where
1010

1111
// @has no_redundancy/struct.Outer.html
1212
// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl has-srclink"]//h3[@class="code-header in-band"]' \
13-
// "impl<T> Send for Outer<T> where T: Copy + Send"
13+
// "impl<T> Send for Outer<T> where T: Send + Copy"
1414
pub struct Outer<T> {
1515
inner_field: Inner<T>,
1616
}

0 commit comments

Comments
 (0)