Skip to content

Commit f02f739

Browse files
committed
rustdoc: Correctly inline required/provided methods
Apparently relying on provided_source in ty::Method is unreliable! Closes #14594
1 parent 287af7f commit f02f739

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ pub fn record_extern_fqn(cx: &core::DocContext,
129129
match cx.maybe_typed {
130130
core::Typed(ref tcx) => {
131131
let fqn = csearch::get_item_path(tcx, did);
132-
let fqn = fqn.move_iter().map(|i| i.to_str().to_string()).collect();
132+
let fqn = fqn.move_iter().map(|i| i.to_str()).collect();
133133
cx.external_paths.borrow_mut().get_mut_ref().insert(did, (fqn, kind));
134134
}
135135
core::NotTyped(..) => {}
@@ -138,10 +138,18 @@ pub fn record_extern_fqn(cx: &core::DocContext,
138138

139139
pub fn build_external_trait(tcx: &ty::ctxt, did: ast::DefId) -> clean::Trait {
140140
let def = ty::lookup_trait_def(tcx, did);
141-
let methods = ty::trait_methods(tcx, did);
141+
let methods = ty::trait_methods(tcx, did).clean();
142+
let provided = ty::provided_trait_methods(tcx, did);
143+
let mut methods = methods.move_iter().map(|meth| {
144+
if provided.iter().any(|a| a.def_id == meth.def_id) {
145+
clean::Provided(meth)
146+
} else {
147+
clean::Required(meth)
148+
}
149+
});
142150
clean::Trait {
143151
generics: def.generics.clean(),
144-
methods: methods.iter().map(|i| i.clean()).collect(),
152+
methods: methods.collect(),
145153
parents: Vec::new(), // FIXME: this is likely wrong
146154
}
147155
}
@@ -263,10 +271,7 @@ fn build_impl(cx: &core::DocContext,
263271
if method.vis != ast::Public && associated_trait.is_none() {
264272
return None
265273
}
266-
let mut item = match ty::method(tcx, *did).clean() {
267-
clean::Provided(item) => item,
268-
clean::Required(item) => item,
269-
};
274+
let mut item = ty::method(tcx, *did).clean();
270275
item.inner = match item.inner.clone() {
271276
clean::TyMethodItem(clean::TyMethod {
272277
fn_style, decl, self_, generics

src/librustdoc/clean/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -942,9 +942,8 @@ impl Clean<TraitMethod> for ast::TraitMethod {
942942
}
943943
}
944944

945-
impl Clean<TraitMethod> for ty::Method {
946-
fn clean(&self) -> TraitMethod {
947-
let m = if self.provided_source.is_some() {Provided} else {Required};
945+
impl Clean<Item> for ty::Method {
946+
fn clean(&self) -> Item {
948947
let cx = super::ctxtkey.get().unwrap();
949948
let tcx = match cx.maybe_typed {
950949
core::Typed(ref tcx) => tcx,
@@ -972,7 +971,7 @@ impl Clean<TraitMethod> for ty::Method {
972971
}
973972
};
974973

975-
m(Item {
974+
Item {
976975
name: Some(self.ident.clean()),
977976
visibility: Some(ast::Inherited),
978977
def_id: self.def_id,
@@ -984,7 +983,7 @@ impl Clean<TraitMethod> for ty::Method {
984983
self_: self_,
985984
decl: (self.def_id, &sig).clean(),
986985
})
987-
})
986+
}
988987
}
989988
}
990989

0 commit comments

Comments
 (0)