Simplified checking for non_exhaustive attribute.
This commit is contained in:
parent
3e59aef385
commit
5ccafa106f
7 changed files with 8 additions and 41 deletions
|
|
@ -229,7 +229,6 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
|
|||
def_id: self.next_def_id(def_id.krate),
|
||||
stability: None,
|
||||
deprecation: None,
|
||||
non_exhaustive: false,
|
||||
inner: ImplItem(Impl {
|
||||
unsafety: hir::Unsafety::Normal,
|
||||
generics: new_generics,
|
||||
|
|
|
|||
|
|
@ -111,7 +111,6 @@ pub fn try_inline(cx: &DocContext, def: Def, name: ast::Name, visited: &mut FxHa
|
|||
visibility: Some(clean::Public),
|
||||
stability: cx.tcx.lookup_stability(did).clean(cx),
|
||||
deprecation: cx.tcx.lookup_deprecation(did).clean(cx),
|
||||
non_exhaustive: false,
|
||||
def_id: did,
|
||||
});
|
||||
Some(ret)
|
||||
|
|
@ -413,7 +412,6 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
|
|||
visibility: Some(clean::Inherited),
|
||||
stability: tcx.lookup_stability(did).clean(cx),
|
||||
deprecation: tcx.lookup_deprecation(did).clean(cx),
|
||||
non_exhaustive: false,
|
||||
def_id: did,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -192,7 +192,6 @@ impl<'a, 'tcx, 'rcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx, 'rcx>
|
|||
visibility: Some(Public),
|
||||
stability: get_stability(cx, def_id),
|
||||
deprecation: get_deprecation(cx, def_id),
|
||||
non_exhaustive: false,
|
||||
def_id,
|
||||
inner: PrimitiveItem(prim),
|
||||
}
|
||||
|
|
@ -205,7 +204,6 @@ impl<'a, 'tcx, 'rcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx, 'rcx>
|
|||
visibility: Some(Public),
|
||||
stability: get_stability(cx, def_id),
|
||||
deprecation: get_deprecation(cx, def_id),
|
||||
non_exhaustive: false,
|
||||
def_id,
|
||||
inner: KeywordItem(kw),
|
||||
}
|
||||
|
|
@ -368,7 +366,6 @@ pub struct Item {
|
|||
pub def_id: DefId,
|
||||
pub stability: Option<Stability>,
|
||||
pub deprecation: Option<Deprecation>,
|
||||
pub non_exhaustive: bool,
|
||||
}
|
||||
|
||||
impl fmt::Debug for Item {
|
||||
|
|
@ -498,6 +495,12 @@ impl Item {
|
|||
self.stability.as_ref().map(|s| &s.since[..])
|
||||
}
|
||||
|
||||
pub fn is_non_exhaustive(&self) -> bool {
|
||||
self.attrs.other_attrs.iter()
|
||||
.filter(|a| a.name().as_str() == "non_exhaustive")
|
||||
.count() > 0
|
||||
}
|
||||
|
||||
/// Returns a documentation-level item type from the item.
|
||||
pub fn type_(&self) -> ItemType {
|
||||
ItemType::from(self)
|
||||
|
|
@ -628,7 +631,6 @@ impl Clean<Item> for doctree::Module {
|
|||
visibility: self.vis.clean(cx),
|
||||
stability: self.stab.clean(cx),
|
||||
deprecation: self.depr.clean(cx),
|
||||
non_exhaustive: false,
|
||||
def_id: cx.tcx.hir.local_def_id(self.id),
|
||||
inner: ModuleItem(Module {
|
||||
is_crate: self.is_crate,
|
||||
|
|
@ -2121,7 +2123,6 @@ impl Clean<Item> for doctree::Function {
|
|||
visibility: self.vis.clean(cx),
|
||||
stability: self.stab.clean(cx),
|
||||
deprecation: self.depr.clean(cx),
|
||||
non_exhaustive: false,
|
||||
def_id: cx.tcx.hir.local_def_id(self.id),
|
||||
inner: FunctionItem(Function {
|
||||
decl,
|
||||
|
|
@ -2303,7 +2304,6 @@ impl Clean<Item> for doctree::Trait {
|
|||
visibility: self.vis.clean(cx),
|
||||
stability: self.stab.clean(cx),
|
||||
deprecation: self.depr.clean(cx),
|
||||
non_exhaustive: false,
|
||||
inner: TraitItem(Trait {
|
||||
auto: self.is_auto.clean(cx),
|
||||
unsafety: self.unsafety,
|
||||
|
|
@ -2373,7 +2373,6 @@ impl Clean<Item> for hir::TraitItem {
|
|||
visibility: None,
|
||||
stability: get_stability(cx, cx.tcx.hir.local_def_id(self.id)),
|
||||
deprecation: get_deprecation(cx, cx.tcx.hir.local_def_id(self.id)),
|
||||
non_exhaustive: false,
|
||||
inner,
|
||||
}
|
||||
}
|
||||
|
|
@ -2402,7 +2401,6 @@ impl Clean<Item> for hir::ImplItem {
|
|||
visibility: self.vis.clean(cx),
|
||||
stability: get_stability(cx, cx.tcx.hir.local_def_id(self.id)),
|
||||
deprecation: get_deprecation(cx, cx.tcx.hir.local_def_id(self.id)),
|
||||
non_exhaustive: false,
|
||||
inner,
|
||||
}
|
||||
}
|
||||
|
|
@ -2549,7 +2547,6 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
|
|||
visibility,
|
||||
stability: get_stability(cx, self.def_id),
|
||||
deprecation: get_deprecation(cx, self.def_id),
|
||||
non_exhaustive: false,
|
||||
def_id: self.def_id,
|
||||
attrs: inline::load_attrs(cx, self.def_id),
|
||||
source: cx.tcx.def_span(self.def_id).clean(cx),
|
||||
|
|
@ -3203,7 +3200,6 @@ impl Clean<Item> for hir::StructField {
|
|||
visibility: self.vis.clean(cx),
|
||||
stability: get_stability(cx, cx.tcx.hir.local_def_id(self.id)),
|
||||
deprecation: get_deprecation(cx, cx.tcx.hir.local_def_id(self.id)),
|
||||
non_exhaustive: false,
|
||||
def_id: cx.tcx.hir.local_def_id(self.id),
|
||||
inner: StructFieldItem(self.ty.clean(cx)),
|
||||
}
|
||||
|
|
@ -3219,7 +3215,6 @@ impl<'tcx> Clean<Item> for ty::FieldDef {
|
|||
visibility: self.vis.clean(cx),
|
||||
stability: get_stability(cx, self.did),
|
||||
deprecation: get_deprecation(cx, self.did),
|
||||
non_exhaustive: false,
|
||||
def_id: self.did,
|
||||
inner: StructFieldItem(cx.tcx.type_of(self.did).clean(cx)),
|
||||
}
|
||||
|
|
@ -3284,7 +3279,6 @@ impl Clean<Vec<Item>> for doctree::Struct {
|
|||
visibility: self.vis.clean(cx),
|
||||
stability: self.stab.clean(cx),
|
||||
deprecation: self.depr.clean(cx),
|
||||
non_exhaustive: self.non_exhaustive,
|
||||
inner: StructItem(Struct {
|
||||
struct_type: self.struct_type,
|
||||
generics: self.generics.clean(cx),
|
||||
|
|
@ -3310,7 +3304,6 @@ impl Clean<Vec<Item>> for doctree::Union {
|
|||
visibility: self.vis.clean(cx),
|
||||
stability: self.stab.clean(cx),
|
||||
deprecation: self.depr.clean(cx),
|
||||
non_exhaustive: false,
|
||||
inner: UnionItem(Union {
|
||||
struct_type: self.struct_type,
|
||||
generics: self.generics.clean(cx),
|
||||
|
|
@ -3363,7 +3356,6 @@ impl Clean<Vec<Item>> for doctree::Enum {
|
|||
visibility: self.vis.clean(cx),
|
||||
stability: self.stab.clean(cx),
|
||||
deprecation: self.depr.clean(cx),
|
||||
non_exhaustive: self.non_exhaustive,
|
||||
inner: EnumItem(Enum {
|
||||
variants: self.variants.clean(cx),
|
||||
generics: self.generics.clean(cx),
|
||||
|
|
@ -3389,7 +3381,6 @@ impl Clean<Item> for doctree::Variant {
|
|||
visibility: None,
|
||||
stability: self.stab.clean(cx),
|
||||
deprecation: self.depr.clean(cx),
|
||||
non_exhaustive: false,
|
||||
def_id: cx.tcx.hir.local_def_id(self.def.id()),
|
||||
inner: VariantItem(Variant {
|
||||
kind: self.def.clean(cx),
|
||||
|
|
@ -3420,7 +3411,6 @@ impl<'tcx> Clean<Item> for ty::VariantDef {
|
|||
def_id: field.did,
|
||||
stability: get_stability(cx, field.did),
|
||||
deprecation: get_deprecation(cx, field.did),
|
||||
non_exhaustive: false,
|
||||
inner: StructFieldItem(cx.tcx.type_of(field.did).clean(cx))
|
||||
}
|
||||
}).collect()
|
||||
|
|
@ -3436,7 +3426,6 @@ impl<'tcx> Clean<Item> for ty::VariantDef {
|
|||
inner: VariantItem(Variant { kind: kind }),
|
||||
stability: get_stability(cx, self.did),
|
||||
deprecation: get_deprecation(cx, self.did),
|
||||
non_exhaustive: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3688,7 +3677,6 @@ impl Clean<Item> for doctree::Typedef {
|
|||
visibility: self.vis.clean(cx),
|
||||
stability: self.stab.clean(cx),
|
||||
deprecation: self.depr.clean(cx),
|
||||
non_exhaustive: false,
|
||||
inner: TypedefItem(Typedef {
|
||||
type_: self.ty.clean(cx),
|
||||
generics: self.gen.clean(cx),
|
||||
|
|
@ -3740,7 +3728,6 @@ impl Clean<Item> for doctree::Static {
|
|||
visibility: self.vis.clean(cx),
|
||||
stability: self.stab.clean(cx),
|
||||
deprecation: self.depr.clean(cx),
|
||||
non_exhaustive: false,
|
||||
inner: StaticItem(Static {
|
||||
type_: self.type_.clean(cx),
|
||||
mutability: self.mutability.clean(cx),
|
||||
|
|
@ -3766,7 +3753,6 @@ impl Clean<Item> for doctree::Constant {
|
|||
visibility: self.vis.clean(cx),
|
||||
stability: self.stab.clean(cx),
|
||||
deprecation: self.depr.clean(cx),
|
||||
non_exhaustive: false,
|
||||
inner: ConstantItem(Constant {
|
||||
type_: self.type_.clean(cx),
|
||||
expr: print_const_expr(cx, self.expr),
|
||||
|
|
@ -3855,7 +3841,6 @@ impl Clean<Vec<Item>> for doctree::Impl {
|
|||
visibility: self.vis.clean(cx),
|
||||
stability: self.stab.clean(cx),
|
||||
deprecation: self.depr.clean(cx),
|
||||
non_exhaustive: false,
|
||||
inner: ImplItem(Impl {
|
||||
unsafety: self.unsafety,
|
||||
generics: self.generics.clean(cx),
|
||||
|
|
@ -3942,7 +3927,6 @@ impl Clean<Item> for doctree::ExternCrate {
|
|||
visibility: self.vis.clean(cx),
|
||||
stability: None,
|
||||
deprecation: None,
|
||||
non_exhaustive: false,
|
||||
inner: ExternCrateItem(self.name.clean(cx), self.path.clone())
|
||||
}
|
||||
}
|
||||
|
|
@ -3989,7 +3973,6 @@ impl Clean<Vec<Item>> for doctree::Import {
|
|||
visibility: self.vis.clean(cx),
|
||||
stability: None,
|
||||
deprecation: None,
|
||||
non_exhaustive: false,
|
||||
inner: ImportItem(inner)
|
||||
}]
|
||||
}
|
||||
|
|
@ -4058,7 +4041,6 @@ impl Clean<Item> for hir::ForeignItem {
|
|||
visibility: self.vis.clean(cx),
|
||||
stability: get_stability(cx, cx.tcx.hir.local_def_id(self.id)),
|
||||
deprecation: get_deprecation(cx, cx.tcx.hir.local_def_id(self.id)),
|
||||
non_exhaustive: false,
|
||||
inner,
|
||||
}
|
||||
}
|
||||
|
|
@ -4233,7 +4215,6 @@ impl Clean<Item> for doctree::Macro {
|
|||
visibility: Some(Public),
|
||||
stability: self.stab.clean(cx),
|
||||
deprecation: self.depr.clean(cx),
|
||||
non_exhaustive: false,
|
||||
def_id: self.def_id,
|
||||
inner: MacroItem(Macro {
|
||||
source: format!("macro_rules! {} {{\n{}}}",
|
||||
|
|
|
|||
|
|
@ -97,7 +97,6 @@ pub struct Struct {
|
|||
pub vis: hir::Visibility,
|
||||
pub stab: Option<attr::Stability>,
|
||||
pub depr: Option<attr::Deprecation>,
|
||||
pub non_exhaustive: bool,
|
||||
pub id: NodeId,
|
||||
pub struct_type: StructType,
|
||||
pub name: Name,
|
||||
|
|
@ -124,7 +123,6 @@ pub struct Enum {
|
|||
pub vis: hir::Visibility,
|
||||
pub stab: Option<attr::Stability>,
|
||||
pub depr: Option<attr::Deprecation>,
|
||||
pub non_exhaustive: bool,
|
||||
pub variants: hir::HirVec<Variant>,
|
||||
pub generics: hir::Generics,
|
||||
pub attrs: hir::HirVec<ast::Attribute>,
|
||||
|
|
|
|||
|
|
@ -99,7 +99,6 @@ pub trait DocFolder : Sized {
|
|||
inner,
|
||||
stability,
|
||||
deprecation,
|
||||
non_exhaustive
|
||||
} = item;
|
||||
|
||||
let inner = match inner {
|
||||
|
|
@ -108,7 +107,7 @@ pub trait DocFolder : Sized {
|
|||
};
|
||||
|
||||
Some(Item { attrs, name, source, inner, visibility,
|
||||
stability, deprecation, non_exhaustive, def_id })
|
||||
stability, deprecation, def_id })
|
||||
}
|
||||
|
||||
fn fold_mod(&mut self, m: Module) -> Module {
|
||||
|
|
|
|||
|
|
@ -2264,7 +2264,7 @@ fn document_stability(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item)
|
|||
}
|
||||
|
||||
fn document_non_exhaustive(w: &mut fmt::Formatter, item: &clean::Item) -> fmt::Result {
|
||||
if item.non_exhaustive {
|
||||
if item.is_non_exhaustive() {
|
||||
write!(w, "<div class='non-exhaustive'><div class='stab non-exhaustive'>")?;
|
||||
write!(w, "<details><summary><span class=microscope>🔬</span>")?;
|
||||
|
||||
|
|
|
|||
|
|
@ -89,12 +89,6 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
|
|||
.and_then(|def_id| self.cx.tcx.lookup_deprecation(def_id))
|
||||
}
|
||||
|
||||
fn non_exhaustive(&self, id: ast::NodeId) -> bool {
|
||||
self.cx.tcx.hir.opt_local_def_id(id)
|
||||
.map(|def_id| self.cx.tcx.has_attr(def_id, "non_exhaustive"))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn visit(&mut self, krate: &hir::Crate) {
|
||||
self.attrs = krate.attrs.clone();
|
||||
|
||||
|
|
@ -125,7 +119,6 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
|
|||
vis: item.vis.clone(),
|
||||
stab: self.stability(item.id),
|
||||
depr: self.deprecation(item.id),
|
||||
non_exhaustive: self.non_exhaustive(item.id),
|
||||
attrs: item.attrs.clone(),
|
||||
generics: generics.clone(),
|
||||
fields: sd.fields().iter().cloned().collect(),
|
||||
|
|
@ -169,7 +162,6 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
|
|||
vis: it.vis.clone(),
|
||||
stab: self.stability(it.id),
|
||||
depr: self.deprecation(it.id),
|
||||
non_exhaustive: self.non_exhaustive(it.id),
|
||||
generics: params.clone(),
|
||||
attrs: it.attrs.clone(),
|
||||
id: it.id,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue