Skip to content

Commit

Permalink
Move def_id_to_path to use site in visit_ast
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Aug 11, 2019
1 parent 65ea7b7 commit 19c85a8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
20 changes: 1 addition & 19 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -39,7 +39,7 @@ use std::fmt;
use std::hash::{Hash, Hasher};
use std::default::Default;
use std::{mem, slice, vec};
use std::iter::{FromIterator, once};
use std::iter::FromIterator;
use std::rc::Rc;
use std::cell::RefCell;
use std::sync::Arc;
Expand Down Expand Up @@ -4398,24 +4398,6 @@ impl Clean<TypeBindingKind> for hir::TypeBindingKind {
}
}

pub fn def_id_to_path(
cx: &DocContext<'_>,
did: DefId,
name: Option<String>
) -> Vec<String> {
let crate_name = name.unwrap_or_else(|| cx.tcx.crate_name(did.krate).to_string());
let relative = cx.tcx.def_path(did).data.into_iter().filter_map(|elem| {
// extern blocks have an empty name
let s = elem.data.to_string();
if !s.is_empty() {
Some(s)
} else {
None
}
});
once(crate_name).chain(relative).collect()
}

pub fn enter_impl_trait<F, R>(cx: &DocContext<'_>, f: F) -> R
where
F: FnOnce() -> R,
Expand Down
19 changes: 18 additions & 1 deletion src/librustdoc/visit_ast.rs
Expand Up @@ -15,9 +15,26 @@ use syntax_pos::{self, Span};
use std::mem;

use crate::core;
use crate::clean::{self, AttributesExt, NestedAttributesExt, def_id_to_path};
use crate::clean::{self, AttributesExt, NestedAttributesExt};
use crate::doctree::*;

fn def_id_to_path(
cx: &core::DocContext<'_>,
did: DefId,
name: Option<String>
) -> Vec<String> {
let crate_name = name.unwrap_or_else(|| cx.tcx.crate_name(did.krate).to_string());
let relative = cx.tcx.def_path(did).data.into_iter().filter_map(|elem| {
// extern blocks have an empty name
let s = elem.data.to_string();
if !s.is_empty() {
Some(s)
} else {
None
}
});
std::iter::once(crate_name).chain(relative).collect()
}

// Also, is there some reason that this doesn't use the 'visit'
// framework from syntax?.
Expand Down

0 comments on commit 19c85a8

Please sign in to comment.