1
Fork 0

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.
This commit is contained in:
Noah Lev 2021-08-24 10:33:41 -07:00
parent 0bb1c285af
commit 6a84d34784
4 changed files with 13 additions and 20 deletions

View file

@ -166,7 +166,7 @@ impl Clean<Type> for (ty::TraitRef<'_>, &[TypeBinding]) {
inline::record_extern_fqn(cx, trait_ref.def_id, kind); inline::record_extern_fqn(cx, trait_ref.def_id, kind);
let path = external_path( let path = external_path(
cx, cx,
cx.tcx.item_name(trait_ref.def_id), trait_ref.def_id,
Some(trait_ref.def_id), Some(trait_ref.def_id),
true, true,
bounds.to_vec(), bounds.to_vec(),
@ -1448,19 +1448,12 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
AdtKind::Enum => ItemType::Enum, AdtKind::Enum => ItemType::Enum,
}; };
inline::record_extern_fqn(cx, did, kind); 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 } ResolvedPath { path, did, is_generic: false }
} }
ty::Foreign(did) => { ty::Foreign(did) => {
inline::record_extern_fqn(cx, did, ItemType::ForeignType); inline::record_extern_fqn(cx, did, ItemType::ForeignType);
let path = external_path( let path = external_path(cx, did, None, false, vec![], InternalSubsts::empty());
cx,
cx.tcx.item_name(did),
None,
false,
vec![],
InternalSubsts::empty(),
);
ResolvedPath { path, did, is_generic: false } ResolvedPath { path, did, is_generic: false }
} }
ty::Dynamic(ref obj, ref reg) => { ty::Dynamic(ref obj, ref reg) => {
@ -1484,8 +1477,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
for did in dids { for did in dids {
let empty = cx.tcx.intern_substs(&[]); let empty = cx.tcx.intern_substs(&[]);
let path = let path = external_path(cx, did, Some(did), false, vec![], empty);
external_path(cx, cx.tcx.item_name(did), Some(did), false, vec![], empty);
inline::record_extern_fqn(cx, did, ItemType::Trait); inline::record_extern_fqn(cx, did, ItemType::Trait);
let bound = PolyTrait { let bound = PolyTrait {
trait_: ResolvedPath { path, did, is_generic: false }, trait_: ResolvedPath { path, did, is_generic: false },
@ -1502,8 +1494,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
}); });
} }
let path = let path = external_path(cx, did, Some(did), false, bindings, substs);
external_path(cx, cx.tcx.item_name(did), Some(did), false, bindings, substs);
bounds.insert( bounds.insert(
0, 0,
PolyTrait { PolyTrait {

View file

@ -1158,7 +1158,7 @@ impl GenericBound {
crate fn maybe_sized(cx: &mut DocContext<'_>) -> GenericBound { crate fn maybe_sized(cx: &mut DocContext<'_>) -> GenericBound {
let did = cx.tcx.require_lang_item(LangItem::Sized, None); let did = cx.tcx.require_lang_item(LangItem::Sized, None);
let empty = cx.tcx.intern_substs(&[]); 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); inline::record_extern_fqn(cx, did, ItemType::Trait);
GenericBound::TraitBound( GenericBound::TraitBound(
PolyTrait { PolyTrait {

View file

@ -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 /// 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 /// from `Fn<(A, B,), C>` to `Fn(A, B) -> C`
pub(super) fn external_path( pub(super) fn external_path(
cx: &mut DocContext<'_>, cx: &mut DocContext<'_>,
name: Symbol, did: DefId,
trait_did: Option<DefId>, trait_did: Option<DefId>,
has_self: bool, has_self: bool,
bindings: Vec<TypeBinding>, bindings: Vec<TypeBinding>,
substs: SubstsRef<'_>, substs: SubstsRef<'_>,
) -> Path { ) -> Path {
let def_kind = cx.tcx.def_kind(did);
let name = cx.tcx.item_name(did);
Path { Path {
global: false, global: false,
res: Res::Err, res: Res::Def(def_kind, did),
segments: vec![PathSegment { segments: vec![PathSegment {
name, name,
args: external_generic_args(cx, trait_did, has_self, bindings, substs), args: external_generic_args(cx, trait_did, has_self, bindings, substs),

View file

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