Skip to content

Commit b183bd0

Browse files
committed
Auto merge of #50490 - nrc:method-docs, r=eddyb
save-analysis: emit correct docs for methods cc rust-lang/rls#446 r? @eddyb
2 parents 697a989 + d4c53ac commit b183bd0

File tree

1 file changed

+30
-36
lines changed
  • src/librustc_save_analysis

1 file changed

+30
-36
lines changed

src/librustc_save_analysis/lib.rs

+30-36
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ mod sig;
4040

4141
use rustc::hir;
4242
use rustc::hir::def::Def as HirDef;
43-
use rustc::hir::map::{Node, NodeItem};
43+
use rustc::hir::map::{Node, NodeTraitItem, NodeImplItem};
4444
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
4545
use rustc::middle::cstore::ExternCrate;
4646
use rustc::session::config::CrateType::CrateTypeExecutable;
@@ -418,34 +418,30 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
418418
Some(impl_id) => match self.tcx.hir.get_if_local(impl_id) {
419419
Some(Node::NodeItem(item)) => match item.node {
420420
hir::ItemImpl(.., ref ty, _) => {
421-
let mut result = String::from("<");
422-
result.push_str(&self.tcx.hir.node_to_pretty_string(ty.id));
421+
let mut qualname = String::from("<");
422+
qualname.push_str(&self.tcx.hir.node_to_pretty_string(ty.id));
423423

424424
let mut trait_id = self.tcx.trait_id_of_impl(impl_id);
425425
let mut decl_id = None;
426+
let mut docs = String::new();
427+
let mut attrs = vec![];
428+
if let Some(NodeImplItem(item)) = self.tcx.hir.find(id) {
429+
docs = self.docs_for_attrs(&item.attrs);
430+
attrs = item.attrs.to_vec();
431+
}
432+
426433
if let Some(def_id) = trait_id {
427-
result.push_str(" as ");
428-
result.push_str(&self.tcx.item_path_str(def_id));
434+
// A method in a trait impl.
435+
qualname.push_str(" as ");
436+
qualname.push_str(&self.tcx.item_path_str(def_id));
429437
self.tcx
430438
.associated_items(def_id)
431439
.find(|item| item.name == name)
432440
.map(|item| decl_id = Some(item.def_id));
433-
} else {
434-
if let Some(NodeItem(item)) = self.tcx.hir.find(id) {
435-
if let hir::ItemImpl(_, _, _, _, _, ref ty, _) = item.node {
436-
trait_id = self.lookup_ref_id(ty.id);
437-
}
438-
}
439441
}
440-
result.push_str(">");
441-
442-
(
443-
result,
444-
trait_id,
445-
decl_id,
446-
self.docs_for_attrs(&item.attrs),
447-
item.attrs.to_vec(),
448-
)
442+
qualname.push_str(">");
443+
444+
(qualname, trait_id, decl_id, docs, attrs)
449445
}
450446
_ => {
451447
span_bug!(
@@ -467,25 +463,23 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
467463
}
468464
},
469465
None => match self.tcx.trait_of_item(self.tcx.hir.local_def_id(id)) {
470-
Some(def_id) => match self.tcx.hir.get_if_local(def_id) {
471-
Some(Node::NodeItem(item)) => (
466+
Some(def_id) => {
467+
let mut docs = String::new();
468+
let mut attrs = vec![];
469+
470+
if let Some(NodeTraitItem(item)) = self.tcx.hir.find(id) {
471+
docs = self.docs_for_attrs(&item.attrs);
472+
attrs = item.attrs.to_vec();
473+
}
474+
475+
(
472476
format!("::{}", self.tcx.item_path_str(def_id)),
473477
Some(def_id),
474478
None,
475-
self.docs_for_attrs(&item.attrs),
476-
item.attrs.to_vec(),
477-
),
478-
r => {
479-
span_bug!(
480-
span,
481-
"Could not find container {:?} for \
482-
method {}, got {:?}",
483-
def_id,
484-
id,
485-
r
486-
);
487-
}
488-
},
479+
docs,
480+
attrs,
481+
)
482+
}
489483
None => {
490484
debug!("Could not find container for method {} at {:?}", id, span);
491485
// This is not necessarily a bug, if there was a compilation error,

0 commit comments

Comments
 (0)