Make hir::Visibility non-copyable and add ty::Visibility
This commit is contained in:
parent
ffbbf24186
commit
bb66d91c98
21 changed files with 200 additions and 165 deletions
|
|
@ -361,7 +361,7 @@ pub fn build_impl(cx: &DocContext,
|
|||
})
|
||||
}
|
||||
ty::MethodTraitItem(method) => {
|
||||
if method.vis != hir::Public && associated_trait.is_none() {
|
||||
if method.vis != ty::Visibility::Public && associated_trait.is_none() {
|
||||
return None
|
||||
}
|
||||
let mut item = method.clean(cx);
|
||||
|
|
@ -471,7 +471,7 @@ fn build_module(cx: &DocContext, tcx: &TyCtxt,
|
|||
cstore::DlDef(Def::ForeignMod(did)) => {
|
||||
fill_in(cx, tcx, did, items);
|
||||
}
|
||||
cstore::DlDef(def) if item.vis == hir::Public => {
|
||||
cstore::DlDef(def) if item.vis == ty::Visibility::Public => {
|
||||
if !visited.insert(def) { continue }
|
||||
if let Some(i) = try_inline_def(cx, tcx, def) {
|
||||
items.extend(i)
|
||||
|
|
|
|||
|
|
@ -1754,7 +1754,7 @@ impl Clean<Item> for hir::StructField {
|
|||
name: Some(self.name).clean(cx),
|
||||
attrs: self.attrs.clean(cx),
|
||||
source: self.span.clean(cx),
|
||||
visibility: Some(self.vis),
|
||||
visibility: self.vis.clean(cx),
|
||||
stability: get_stability(cx, cx.map.local_def_id(self.id)),
|
||||
deprecation: get_deprecation(cx, cx.map.local_def_id(self.id)),
|
||||
def_id: cx.map.local_def_id(self.id),
|
||||
|
|
@ -1771,7 +1771,7 @@ impl<'tcx> Clean<Item> for ty::FieldDefData<'tcx, 'static> {
|
|||
name: Some(self.name).clean(cx),
|
||||
attrs: attr_map.get(&self.did).unwrap_or(&Vec::new()).clean(cx),
|
||||
source: Span::empty(),
|
||||
visibility: Some(self.vis),
|
||||
visibility: self.vis.clean(cx),
|
||||
stability: get_stability(cx, self.did),
|
||||
deprecation: get_deprecation(cx, self.did),
|
||||
def_id: self.did,
|
||||
|
|
@ -1784,7 +1784,13 @@ pub type Visibility = hir::Visibility;
|
|||
|
||||
impl Clean<Option<Visibility>> for hir::Visibility {
|
||||
fn clean(&self, _: &DocContext) -> Option<Visibility> {
|
||||
Some(*self)
|
||||
Some(self.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl Clean<Option<Visibility>> for ty::Visibility {
|
||||
fn clean(&self, _: &DocContext) -> Option<Visibility> {
|
||||
Some(if *self == ty::Visibility::Public { hir::Public } else { hir::Inherited })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1902,7 +1908,7 @@ impl<'tcx> Clean<Item> for ty::VariantDefData<'tcx, 'static> {
|
|||
source: Span::empty(),
|
||||
name: Some(field.name.clean(cx)),
|
||||
attrs: cx.tcx().get_attrs(field.did).clean(cx),
|
||||
visibility: Some(field.vis),
|
||||
visibility: field.vis.clean(cx),
|
||||
def_id: field.did,
|
||||
stability: get_stability(cx, field.did),
|
||||
deprecation: get_deprecation(cx, field.did),
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ use html::render::{cache, CURRENT_LOCATION_KEY};
|
|||
/// Helper to render an optional visibility with a space after it (if the
|
||||
/// visibility is preset)
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct VisSpace(pub Option<hir::Visibility>);
|
||||
pub struct VisSpace<'a>(pub &'a Option<hir::Visibility>);
|
||||
/// Similarly to VisSpace, this structure is used to render a function style with a
|
||||
/// space after it.
|
||||
#[derive(Copy, Clone)]
|
||||
|
|
@ -56,9 +56,9 @@ pub struct TyParamBounds<'a>(pub &'a [clean::TyParamBound]);
|
|||
pub struct CommaSep<'a, T: 'a>(pub &'a [T]);
|
||||
pub struct AbiSpace(pub Abi);
|
||||
|
||||
impl VisSpace {
|
||||
pub fn get(&self) -> Option<hir::Visibility> {
|
||||
let VisSpace(v) = *self; v
|
||||
impl<'a> VisSpace<'a> {
|
||||
pub fn get(self) -> &'a Option<hir::Visibility> {
|
||||
let VisSpace(v) = self; v
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -636,9 +636,9 @@ impl<'a> fmt::Display for Method<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for VisSpace {
|
||||
impl<'a> fmt::Display for VisSpace<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.get() {
|
||||
match *self.get() {
|
||||
Some(hir::Public) => write!(f, "pub "),
|
||||
Some(hir::Inherited) | None => Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1714,13 +1714,13 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
|
|||
match *src {
|
||||
Some(ref src) => {
|
||||
write!(w, "<tr><td><code>{}extern crate {} as {};",
|
||||
VisSpace(myitem.visibility),
|
||||
VisSpace(&myitem.visibility),
|
||||
src,
|
||||
name)?
|
||||
}
|
||||
None => {
|
||||
write!(w, "<tr><td><code>{}extern crate {};",
|
||||
VisSpace(myitem.visibility), name)?
|
||||
VisSpace(&myitem.visibility), name)?
|
||||
}
|
||||
}
|
||||
write!(w, "</code></td></tr>")?;
|
||||
|
|
@ -1728,7 +1728,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
|
|||
|
||||
clean::ImportItem(ref import) => {
|
||||
write!(w, "<tr><td><code>{}{}</code></td></tr>",
|
||||
VisSpace(myitem.visibility), *import)?;
|
||||
VisSpace(&myitem.visibility), *import)?;
|
||||
}
|
||||
|
||||
_ => {
|
||||
|
|
@ -1831,7 +1831,7 @@ fn item_constant(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
|||
c: &clean::Constant) -> fmt::Result {
|
||||
write!(w, "<pre class='rust const'>{vis}const \
|
||||
{name}: {typ}{init}</pre>",
|
||||
vis = VisSpace(it.visibility),
|
||||
vis = VisSpace(&it.visibility),
|
||||
name = it.name.as_ref().unwrap(),
|
||||
typ = c.type_,
|
||||
init = Initializer(&c.expr))?;
|
||||
|
|
@ -1842,7 +1842,7 @@ fn item_static(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
|||
s: &clean::Static) -> fmt::Result {
|
||||
write!(w, "<pre class='rust static'>{vis}static {mutability}\
|
||||
{name}: {typ}{init}</pre>",
|
||||
vis = VisSpace(it.visibility),
|
||||
vis = VisSpace(&it.visibility),
|
||||
mutability = MutableSpace(s.mutability),
|
||||
name = it.name.as_ref().unwrap(),
|
||||
typ = s.type_,
|
||||
|
|
@ -1859,7 +1859,7 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
|||
};
|
||||
write!(w, "<pre class='rust fn'>{vis}{constness}{unsafety}{abi}fn \
|
||||
{name}{generics}{decl}{where_clause}</pre>",
|
||||
vis = VisSpace(it.visibility),
|
||||
vis = VisSpace(&it.visibility),
|
||||
constness = ConstnessSpace(vis_constness),
|
||||
unsafety = UnsafetySpace(f.unsafety),
|
||||
abi = AbiSpace(f.abi),
|
||||
|
|
@ -1887,7 +1887,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
|||
|
||||
// Output the trait definition
|
||||
write!(w, "<pre class='rust trait'>{}{}trait {}{}{}{} ",
|
||||
VisSpace(it.visibility),
|
||||
VisSpace(&it.visibility),
|
||||
UnsafetySpace(t.unsafety),
|
||||
it.name.as_ref().unwrap(),
|
||||
t.generics,
|
||||
|
|
@ -2214,7 +2214,7 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
|||
write!(w, "<pre class='rust enum'>")?;
|
||||
render_attributes(w, it)?;
|
||||
write!(w, "{}enum {}{}{}",
|
||||
VisSpace(it.visibility),
|
||||
VisSpace(&it.visibility),
|
||||
it.name.as_ref().unwrap(),
|
||||
e.generics,
|
||||
WhereClause(&e.generics))?;
|
||||
|
|
@ -2326,7 +2326,7 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
|
|||
tab: &str,
|
||||
structhead: bool) -> fmt::Result {
|
||||
write!(w, "{}{}{}",
|
||||
VisSpace(it.visibility),
|
||||
VisSpace(&it.visibility),
|
||||
if structhead {"struct "} else {""},
|
||||
it.name.as_ref().unwrap())?;
|
||||
if let Some(g) = g {
|
||||
|
|
@ -2338,7 +2338,7 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
|
|||
for field in fields {
|
||||
if let clean::StructFieldItem(ref ty) = field.inner {
|
||||
write!(w, " {}{}: {},\n{}",
|
||||
VisSpace(field.visibility),
|
||||
VisSpace(&field.visibility),
|
||||
field.name.as_ref().unwrap(),
|
||||
*ty,
|
||||
tab)?;
|
||||
|
|
@ -2361,7 +2361,7 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
|
|||
write!(w, "_")?
|
||||
}
|
||||
clean::StructFieldItem(ref ty) => {
|
||||
write!(w, "{}{}", VisSpace(field.visibility), *ty)?
|
||||
write!(w, "{}{}", VisSpace(&field.visibility), *ty)?
|
||||
}
|
||||
_ => unreachable!()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||
id: item.id,
|
||||
struct_type: struct_type,
|
||||
name: name,
|
||||
vis: item.vis,
|
||||
vis: item.vis.clone(),
|
||||
stab: self.stability(item.id),
|
||||
depr: self.deprecation(item.id),
|
||||
attrs: item.attrs.clone(),
|
||||
|
|
@ -125,7 +125,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||
def: v.node.data.clone(),
|
||||
whence: v.span,
|
||||
}).collect(),
|
||||
vis: it.vis,
|
||||
vis: it.vis.clone(),
|
||||
stab: self.stability(it.id),
|
||||
depr: self.deprecation(it.id),
|
||||
generics: params.clone(),
|
||||
|
|
@ -144,7 +144,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||
debug!("Visiting fn");
|
||||
Function {
|
||||
id: item.id,
|
||||
vis: item.vis,
|
||||
vis: item.vis.clone(),
|
||||
stab: self.stability(item.id),
|
||||
depr: self.deprecation(item.id),
|
||||
attrs: item.attrs.clone(),
|
||||
|
|
@ -166,7 +166,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||
om.where_outer = span;
|
||||
om.where_inner = m.inner;
|
||||
om.attrs = attrs;
|
||||
om.vis = vis;
|
||||
om.vis = vis.clone();
|
||||
om.stab = self.stability(id);
|
||||
om.depr = self.deprecation(id);
|
||||
om.id = id;
|
||||
|
|
@ -299,7 +299,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||
om.extern_crates.push(ExternCrate {
|
||||
name: name,
|
||||
path: p.map(|x|x.to_string()),
|
||||
vis: item.vis,
|
||||
vis: item.vis.clone(),
|
||||
attrs: item.attrs.clone(),
|
||||
whence: item.span,
|
||||
})
|
||||
|
|
@ -324,7 +324,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||
};
|
||||
om.imports.push(Import {
|
||||
id: item.id,
|
||||
vis: item.vis,
|
||||
vis: item.vis.clone(),
|
||||
attrs: item.attrs.clone(),
|
||||
node: node,
|
||||
whence: item.span,
|
||||
|
|
@ -333,7 +333,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||
hir::ItemMod(ref m) => {
|
||||
om.mods.push(self.visit_mod_contents(item.span,
|
||||
item.attrs.clone(),
|
||||
item.vis,
|
||||
item.vis.clone(),
|
||||
item.id,
|
||||
m,
|
||||
Some(name)));
|
||||
|
|
@ -353,7 +353,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||
id: item.id,
|
||||
attrs: item.attrs.clone(),
|
||||
whence: item.span,
|
||||
vis: item.vis,
|
||||
vis: item.vis.clone(),
|
||||
stab: self.stability(item.id),
|
||||
depr: self.deprecation(item.id),
|
||||
};
|
||||
|
|
@ -368,7 +368,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||
name: name,
|
||||
attrs: item.attrs.clone(),
|
||||
whence: item.span,
|
||||
vis: item.vis,
|
||||
vis: item.vis.clone(),
|
||||
stab: self.stability(item.id),
|
||||
depr: self.deprecation(item.id),
|
||||
};
|
||||
|
|
@ -382,7 +382,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||
name: name,
|
||||
attrs: item.attrs.clone(),
|
||||
whence: item.span,
|
||||
vis: item.vis,
|
||||
vis: item.vis.clone(),
|
||||
stab: self.stability(item.id),
|
||||
depr: self.deprecation(item.id),
|
||||
};
|
||||
|
|
@ -398,7 +398,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||
id: item.id,
|
||||
attrs: item.attrs.clone(),
|
||||
whence: item.span,
|
||||
vis: item.vis,
|
||||
vis: item.vis.clone(),
|
||||
stab: self.stability(item.id),
|
||||
depr: self.deprecation(item.id),
|
||||
};
|
||||
|
|
@ -415,7 +415,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||
attrs: item.attrs.clone(),
|
||||
id: item.id,
|
||||
whence: item.span,
|
||||
vis: item.vis,
|
||||
vis: item.vis.clone(),
|
||||
stab: self.stability(item.id),
|
||||
depr: self.deprecation(item.id),
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue