Skip to content

Commit

Permalink
Create a valid Res in external_path()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
camelid committed Sep 11, 2021
1 parent 0bb1c28 commit 6a84d34
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
19 changes: 5 additions & 14 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -166,7 +166,7 @@ impl Clean<Type> for (ty::TraitRef<'_>, &[TypeBinding]) {
inline::record_extern_fqn(cx, trait_ref.def_id, kind);
let path = external_path(
cx,
cx.tcx.item_name(trait_ref.def_id),
trait_ref.def_id,
Some(trait_ref.def_id),
true,
bounds.to_vec(),
Expand Down Expand Up @@ -1448,19 +1448,12 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
AdtKind::Enum => ItemType::Enum,
};
inline::record_extern_fqn(cx, did, kind);
let path = external_path(cx, cx.tcx.item_name(did), None, false, vec![], substs);
let path = external_path(cx, did, None, false, vec![], substs);
ResolvedPath { path, did, is_generic: false }
}
ty::Foreign(did) => {
inline::record_extern_fqn(cx, did, ItemType::ForeignType);
let path = external_path(
cx,
cx.tcx.item_name(did),
None,
false,
vec![],
InternalSubsts::empty(),
);
let path = external_path(cx, did, None, false, vec![], InternalSubsts::empty());
ResolvedPath { path, did, is_generic: false }
}
ty::Dynamic(ref obj, ref reg) => {
Expand All @@ -1484,8 +1477,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {

for did in dids {
let empty = cx.tcx.intern_substs(&[]);
let path =
external_path(cx, cx.tcx.item_name(did), Some(did), false, vec![], empty);
let path = external_path(cx, did, Some(did), false, vec![], empty);
inline::record_extern_fqn(cx, did, ItemType::Trait);
let bound = PolyTrait {
trait_: ResolvedPath { path, did, is_generic: false },
Expand All @@ -1502,8 +1494,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
});
}

let path =
external_path(cx, cx.tcx.item_name(did), Some(did), false, bindings, substs);
let path = external_path(cx, did, Some(did), false, bindings, substs);
bounds.insert(
0,
PolyTrait {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/types.rs
Expand Up @@ -1158,7 +1158,7 @@ impl GenericBound {
crate fn maybe_sized(cx: &mut DocContext<'_>) -> GenericBound {
let did = cx.tcx.require_lang_item(LangItem::Sized, None);
let empty = cx.tcx.intern_substs(&[]);
let path = external_path(cx, cx.tcx.item_name(did), Some(did), false, vec![], empty);
let path = external_path(cx, did, Some(did), false, vec![], empty);
inline::record_extern_fqn(cx, did, ItemType::Trait);
GenericBound::TraitBound(
PolyTrait {
Expand Down
10 changes: 6 additions & 4 deletions src/librustdoc/clean/utils.rs
Expand Up @@ -141,19 +141,21 @@ fn external_generic_args(
}
}

// trait_did should be set to a trait's DefId if called on a TraitRef, in order to sugar
// from Fn<(A, B,), C> to Fn(A, B) -> C
/// trait_did should be set to a trait's DefId if called on a TraitRef, in order to sugar
/// from `Fn<(A, B,), C>` to `Fn(A, B) -> C`
pub(super) fn external_path(
cx: &mut DocContext<'_>,
name: Symbol,
did: DefId,
trait_did: Option<DefId>,
has_self: bool,
bindings: Vec<TypeBinding>,
substs: SubstsRef<'_>,
) -> Path {
let def_kind = cx.tcx.def_kind(did);
let name = cx.tcx.item_name(did);
Path {
global: false,
res: Res::Err,
res: Res::Def(def_kind, did),
segments: vec![PathSegment {
name,
args: external_generic_args(cx, trait_did, has_self, bindings, substs),
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/synthetic_auto/no-redundancy.rs
Expand Up @@ -10,7 +10,7 @@ where

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

0 comments on commit 6a84d34

Please sign in to comment.