Skip to content

Commit 5ccafa1

Browse files
committed
Simplified checking for non_exhaustive attribute.
1 parent 3e59aef commit 5ccafa1

File tree

7 files changed

+8
-41
lines changed

7 files changed

+8
-41
lines changed

src/librustdoc/clean/auto_trait.rs

-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
229229
def_id: self.next_def_id(def_id.krate),
230230
stability: None,
231231
deprecation: None,
232-
non_exhaustive: false,
233232
inner: ImplItem(Impl {
234233
unsafety: hir::Unsafety::Normal,
235234
generics: new_generics,

src/librustdoc/clean/inline.rs

-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ pub fn try_inline(cx: &DocContext, def: Def, name: ast::Name, visited: &mut FxHa
111111
visibility: Some(clean::Public),
112112
stability: cx.tcx.lookup_stability(did).clean(cx),
113113
deprecation: cx.tcx.lookup_deprecation(did).clean(cx),
114-
non_exhaustive: false,
115114
def_id: did,
116115
});
117116
Some(ret)
@@ -413,7 +412,6 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
413412
visibility: Some(clean::Inherited),
414413
stability: tcx.lookup_stability(did).clean(cx),
415414
deprecation: tcx.lookup_deprecation(did).clean(cx),
416-
non_exhaustive: false,
417415
def_id: did,
418416
});
419417
}

src/librustdoc/clean/mod.rs

+6-25
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ impl<'a, 'tcx, 'rcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx, 'rcx>
192192
visibility: Some(Public),
193193
stability: get_stability(cx, def_id),
194194
deprecation: get_deprecation(cx, def_id),
195-
non_exhaustive: false,
196195
def_id,
197196
inner: PrimitiveItem(prim),
198197
}
@@ -205,7 +204,6 @@ impl<'a, 'tcx, 'rcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx, 'rcx>
205204
visibility: Some(Public),
206205
stability: get_stability(cx, def_id),
207206
deprecation: get_deprecation(cx, def_id),
208-
non_exhaustive: false,
209207
def_id,
210208
inner: KeywordItem(kw),
211209
}
@@ -368,7 +366,6 @@ pub struct Item {
368366
pub def_id: DefId,
369367
pub stability: Option<Stability>,
370368
pub deprecation: Option<Deprecation>,
371-
pub non_exhaustive: bool,
372369
}
373370

374371
impl fmt::Debug for Item {
@@ -498,6 +495,12 @@ impl Item {
498495
self.stability.as_ref().map(|s| &s.since[..])
499496
}
500497

498+
pub fn is_non_exhaustive(&self) -> bool {
499+
self.attrs.other_attrs.iter()
500+
.filter(|a| a.name().as_str() == "non_exhaustive")
501+
.count() > 0
502+
}
503+
501504
/// Returns a documentation-level item type from the item.
502505
pub fn type_(&self) -> ItemType {
503506
ItemType::from(self)
@@ -628,7 +631,6 @@ impl Clean<Item> for doctree::Module {
628631
visibility: self.vis.clean(cx),
629632
stability: self.stab.clean(cx),
630633
deprecation: self.depr.clean(cx),
631-
non_exhaustive: false,
632634
def_id: cx.tcx.hir.local_def_id(self.id),
633635
inner: ModuleItem(Module {
634636
is_crate: self.is_crate,
@@ -2121,7 +2123,6 @@ impl Clean<Item> for doctree::Function {
21212123
visibility: self.vis.clean(cx),
21222124
stability: self.stab.clean(cx),
21232125
deprecation: self.depr.clean(cx),
2124-
non_exhaustive: false,
21252126
def_id: cx.tcx.hir.local_def_id(self.id),
21262127
inner: FunctionItem(Function {
21272128
decl,
@@ -2303,7 +2304,6 @@ impl Clean<Item> for doctree::Trait {
23032304
visibility: self.vis.clean(cx),
23042305
stability: self.stab.clean(cx),
23052306
deprecation: self.depr.clean(cx),
2306-
non_exhaustive: false,
23072307
inner: TraitItem(Trait {
23082308
auto: self.is_auto.clean(cx),
23092309
unsafety: self.unsafety,
@@ -2373,7 +2373,6 @@ impl Clean<Item> for hir::TraitItem {
23732373
visibility: None,
23742374
stability: get_stability(cx, cx.tcx.hir.local_def_id(self.id)),
23752375
deprecation: get_deprecation(cx, cx.tcx.hir.local_def_id(self.id)),
2376-
non_exhaustive: false,
23772376
inner,
23782377
}
23792378
}
@@ -2402,7 +2401,6 @@ impl Clean<Item> for hir::ImplItem {
24022401
visibility: self.vis.clean(cx),
24032402
stability: get_stability(cx, cx.tcx.hir.local_def_id(self.id)),
24042403
deprecation: get_deprecation(cx, cx.tcx.hir.local_def_id(self.id)),
2405-
non_exhaustive: false,
24062404
inner,
24072405
}
24082406
}
@@ -2549,7 +2547,6 @@ impl<'tcx> Clean<Item> for ty::AssociatedItem {
25492547
visibility,
25502548
stability: get_stability(cx, self.def_id),
25512549
deprecation: get_deprecation(cx, self.def_id),
2552-
non_exhaustive: false,
25532550
def_id: self.def_id,
25542551
attrs: inline::load_attrs(cx, self.def_id),
25552552
source: cx.tcx.def_span(self.def_id).clean(cx),
@@ -3203,7 +3200,6 @@ impl Clean<Item> for hir::StructField {
32033200
visibility: self.vis.clean(cx),
32043201
stability: get_stability(cx, cx.tcx.hir.local_def_id(self.id)),
32053202
deprecation: get_deprecation(cx, cx.tcx.hir.local_def_id(self.id)),
3206-
non_exhaustive: false,
32073203
def_id: cx.tcx.hir.local_def_id(self.id),
32083204
inner: StructFieldItem(self.ty.clean(cx)),
32093205
}
@@ -3219,7 +3215,6 @@ impl<'tcx> Clean<Item> for ty::FieldDef {
32193215
visibility: self.vis.clean(cx),
32203216
stability: get_stability(cx, self.did),
32213217
deprecation: get_deprecation(cx, self.did),
3222-
non_exhaustive: false,
32233218
def_id: self.did,
32243219
inner: StructFieldItem(cx.tcx.type_of(self.did).clean(cx)),
32253220
}
@@ -3284,7 +3279,6 @@ impl Clean<Vec<Item>> for doctree::Struct {
32843279
visibility: self.vis.clean(cx),
32853280
stability: self.stab.clean(cx),
32863281
deprecation: self.depr.clean(cx),
3287-
non_exhaustive: self.non_exhaustive,
32883282
inner: StructItem(Struct {
32893283
struct_type: self.struct_type,
32903284
generics: self.generics.clean(cx),
@@ -3310,7 +3304,6 @@ impl Clean<Vec<Item>> for doctree::Union {
33103304
visibility: self.vis.clean(cx),
33113305
stability: self.stab.clean(cx),
33123306
deprecation: self.depr.clean(cx),
3313-
non_exhaustive: false,
33143307
inner: UnionItem(Union {
33153308
struct_type: self.struct_type,
33163309
generics: self.generics.clean(cx),
@@ -3363,7 +3356,6 @@ impl Clean<Vec<Item>> for doctree::Enum {
33633356
visibility: self.vis.clean(cx),
33643357
stability: self.stab.clean(cx),
33653358
deprecation: self.depr.clean(cx),
3366-
non_exhaustive: self.non_exhaustive,
33673359
inner: EnumItem(Enum {
33683360
variants: self.variants.clean(cx),
33693361
generics: self.generics.clean(cx),
@@ -3389,7 +3381,6 @@ impl Clean<Item> for doctree::Variant {
33893381
visibility: None,
33903382
stability: self.stab.clean(cx),
33913383
deprecation: self.depr.clean(cx),
3392-
non_exhaustive: false,
33933384
def_id: cx.tcx.hir.local_def_id(self.def.id()),
33943385
inner: VariantItem(Variant {
33953386
kind: self.def.clean(cx),
@@ -3420,7 +3411,6 @@ impl<'tcx> Clean<Item> for ty::VariantDef {
34203411
def_id: field.did,
34213412
stability: get_stability(cx, field.did),
34223413
deprecation: get_deprecation(cx, field.did),
3423-
non_exhaustive: false,
34243414
inner: StructFieldItem(cx.tcx.type_of(field.did).clean(cx))
34253415
}
34263416
}).collect()
@@ -3436,7 +3426,6 @@ impl<'tcx> Clean<Item> for ty::VariantDef {
34363426
inner: VariantItem(Variant { kind: kind }),
34373427
stability: get_stability(cx, self.did),
34383428
deprecation: get_deprecation(cx, self.did),
3439-
non_exhaustive: false,
34403429
}
34413430
}
34423431
}
@@ -3688,7 +3677,6 @@ impl Clean<Item> for doctree::Typedef {
36883677
visibility: self.vis.clean(cx),
36893678
stability: self.stab.clean(cx),
36903679
deprecation: self.depr.clean(cx),
3691-
non_exhaustive: false,
36923680
inner: TypedefItem(Typedef {
36933681
type_: self.ty.clean(cx),
36943682
generics: self.gen.clean(cx),
@@ -3740,7 +3728,6 @@ impl Clean<Item> for doctree::Static {
37403728
visibility: self.vis.clean(cx),
37413729
stability: self.stab.clean(cx),
37423730
deprecation: self.depr.clean(cx),
3743-
non_exhaustive: false,
37443731
inner: StaticItem(Static {
37453732
type_: self.type_.clean(cx),
37463733
mutability: self.mutability.clean(cx),
@@ -3766,7 +3753,6 @@ impl Clean<Item> for doctree::Constant {
37663753
visibility: self.vis.clean(cx),
37673754
stability: self.stab.clean(cx),
37683755
deprecation: self.depr.clean(cx),
3769-
non_exhaustive: false,
37703756
inner: ConstantItem(Constant {
37713757
type_: self.type_.clean(cx),
37723758
expr: print_const_expr(cx, self.expr),
@@ -3855,7 +3841,6 @@ impl Clean<Vec<Item>> for doctree::Impl {
38553841
visibility: self.vis.clean(cx),
38563842
stability: self.stab.clean(cx),
38573843
deprecation: self.depr.clean(cx),
3858-
non_exhaustive: false,
38593844
inner: ImplItem(Impl {
38603845
unsafety: self.unsafety,
38613846
generics: self.generics.clean(cx),
@@ -3942,7 +3927,6 @@ impl Clean<Item> for doctree::ExternCrate {
39423927
visibility: self.vis.clean(cx),
39433928
stability: None,
39443929
deprecation: None,
3945-
non_exhaustive: false,
39463930
inner: ExternCrateItem(self.name.clean(cx), self.path.clone())
39473931
}
39483932
}
@@ -3989,7 +3973,6 @@ impl Clean<Vec<Item>> for doctree::Import {
39893973
visibility: self.vis.clean(cx),
39903974
stability: None,
39913975
deprecation: None,
3992-
non_exhaustive: false,
39933976
inner: ImportItem(inner)
39943977
}]
39953978
}
@@ -4058,7 +4041,6 @@ impl Clean<Item> for hir::ForeignItem {
40584041
visibility: self.vis.clean(cx),
40594042
stability: get_stability(cx, cx.tcx.hir.local_def_id(self.id)),
40604043
deprecation: get_deprecation(cx, cx.tcx.hir.local_def_id(self.id)),
4061-
non_exhaustive: false,
40624044
inner,
40634045
}
40644046
}
@@ -4233,7 +4215,6 @@ impl Clean<Item> for doctree::Macro {
42334215
visibility: Some(Public),
42344216
stability: self.stab.clean(cx),
42354217
deprecation: self.depr.clean(cx),
4236-
non_exhaustive: false,
42374218
def_id: self.def_id,
42384219
inner: MacroItem(Macro {
42394220
source: format!("macro_rules! {} {{\n{}}}",

src/librustdoc/doctree.rs

-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ pub struct Struct {
9797
pub vis: hir::Visibility,
9898
pub stab: Option<attr::Stability>,
9999
pub depr: Option<attr::Deprecation>,
100-
pub non_exhaustive: bool,
101100
pub id: NodeId,
102101
pub struct_type: StructType,
103102
pub name: Name,
@@ -124,7 +123,6 @@ pub struct Enum {
124123
pub vis: hir::Visibility,
125124
pub stab: Option<attr::Stability>,
126125
pub depr: Option<attr::Deprecation>,
127-
pub non_exhaustive: bool,
128126
pub variants: hir::HirVec<Variant>,
129127
pub generics: hir::Generics,
130128
pub attrs: hir::HirVec<ast::Attribute>,

src/librustdoc/fold.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ pub trait DocFolder : Sized {
9999
inner,
100100
stability,
101101
deprecation,
102-
non_exhaustive
103102
} = item;
104103

105104
let inner = match inner {
@@ -108,7 +107,7 @@ pub trait DocFolder : Sized {
108107
};
109108

110109
Some(Item { attrs, name, source, inner, visibility,
111-
stability, deprecation, non_exhaustive, def_id })
110+
stability, deprecation, def_id })
112111
}
113112

114113
fn fold_mod(&mut self, m: Module) -> Module {

src/librustdoc/html/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2264,7 +2264,7 @@ fn document_stability(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item)
22642264
}
22652265

22662266
fn document_non_exhaustive(w: &mut fmt::Formatter, item: &clean::Item) -> fmt::Result {
2267-
if item.non_exhaustive {
2267+
if item.is_non_exhaustive() {
22682268
write!(w, "<div class='non-exhaustive'><div class='stab non-exhaustive'>")?;
22692269
write!(w, "<details><summary><span class=microscope>🔬</span>")?;
22702270

src/librustdoc/visit_ast.rs

-8
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
8989
.and_then(|def_id| self.cx.tcx.lookup_deprecation(def_id))
9090
}
9191

92-
fn non_exhaustive(&self, id: ast::NodeId) -> bool {
93-
self.cx.tcx.hir.opt_local_def_id(id)
94-
.map(|def_id| self.cx.tcx.has_attr(def_id, "non_exhaustive"))
95-
.unwrap_or(false)
96-
}
97-
9892
pub fn visit(&mut self, krate: &hir::Crate) {
9993
self.attrs = krate.attrs.clone();
10094

@@ -125,7 +119,6 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
125119
vis: item.vis.clone(),
126120
stab: self.stability(item.id),
127121
depr: self.deprecation(item.id),
128-
non_exhaustive: self.non_exhaustive(item.id),
129122
attrs: item.attrs.clone(),
130123
generics: generics.clone(),
131124
fields: sd.fields().iter().cloned().collect(),
@@ -169,7 +162,6 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
169162
vis: it.vis.clone(),
170163
stab: self.stability(it.id),
171164
depr: self.deprecation(it.id),
172-
non_exhaustive: self.non_exhaustive(it.id),
173165
generics: params.clone(),
174166
attrs: it.attrs.clone(),
175167
id: it.id,

0 commit comments

Comments
 (0)