1
Fork 0

Move def_id_to_path to use site in visit_ast

This commit is contained in:
Mark Rousskov 2019-08-10 13:37:31 -04:00
parent 65ea7b7947
commit 19c85a8f8a
2 changed files with 19 additions and 20 deletions

View file

@ -39,7 +39,7 @@ use std::fmt;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use std::default::Default; use std::default::Default;
use std::{mem, slice, vec}; use std::{mem, slice, vec};
use std::iter::{FromIterator, once}; use std::iter::FromIterator;
use std::rc::Rc; use std::rc::Rc;
use std::cell::RefCell; use std::cell::RefCell;
use std::sync::Arc; use std::sync::Arc;
@ -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 pub fn enter_impl_trait<F, R>(cx: &DocContext<'_>, f: F) -> R
where where
F: FnOnce() -> R, F: FnOnce() -> R,

View file

@ -15,9 +15,26 @@ use syntax_pos::{self, Span};
use std::mem; use std::mem;
use crate::core; use crate::core;
use crate::clean::{self, AttributesExt, NestedAttributesExt, def_id_to_path}; use crate::clean::{self, AttributesExt, NestedAttributesExt};
use crate::doctree::*; 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' // Also, is there some reason that this doesn't use the 'visit'
// framework from syntax?. // framework from syntax?.