rustdoc: Add support for pub(restricted)
This commit is contained in:
parent
fe63e479d1
commit
3daded02fa
3 changed files with 71 additions and 5 deletions
|
|
@ -17,7 +17,7 @@ pub use self::ItemEnum::*;
|
|||
pub use self::TyParamBound::*;
|
||||
pub use self::SelfTy::*;
|
||||
pub use self::FunctionRetTy::*;
|
||||
pub use self::Visibility::*;
|
||||
pub use self::Visibility::{Public, Inherited};
|
||||
|
||||
use syntax;
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
|
@ -2976,11 +2976,22 @@ impl<'tcx> Clean<Item> for ty::FieldDef {
|
|||
pub enum Visibility {
|
||||
Public,
|
||||
Inherited,
|
||||
Crate,
|
||||
Restricted(DefId, Path),
|
||||
}
|
||||
|
||||
impl Clean<Option<Visibility>> for hir::Visibility {
|
||||
fn clean(&self, _: &DocContext) -> Option<Visibility> {
|
||||
Some(if *self == hir::Visibility::Public { Public } else { Inherited })
|
||||
fn clean(&self, cx: &DocContext) -> Option<Visibility> {
|
||||
Some(match *self {
|
||||
hir::Visibility::Public => Visibility::Public,
|
||||
hir::Visibility::Inherited => Visibility::Inherited,
|
||||
hir::Visibility::Crate => Visibility::Crate,
|
||||
hir::Visibility::Restricted { ref path, .. } => {
|
||||
let path = path.clean(cx);
|
||||
let did = register_def(cx, path.def);
|
||||
Visibility::Restricted(did, path)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -927,8 +927,19 @@ impl<'a> fmt::Display for Method<'a> {
|
|||
impl<'a> fmt::Display for VisSpace<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self.get() {
|
||||
Some(clean::Public) => write!(f, "pub "),
|
||||
Some(clean::Inherited) | None => Ok(())
|
||||
Some(clean::Public) => f.write_str("pub "),
|
||||
Some(clean::Inherited) | None => Ok(()),
|
||||
Some(clean::Visibility::Crate) => write!(f, "pub(crate) "),
|
||||
Some(clean::Visibility::Restricted(did, ref path)) => {
|
||||
f.write_str("pub(")?;
|
||||
if path.segments.len() != 1
|
||||
|| (path.segments[0].name != "self" && path.segments[0].name != "super")
|
||||
{
|
||||
f.write_str("in ")?;
|
||||
}
|
||||
resolved_path(f, did, path, true, false)?;
|
||||
f.write_str(") ")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue