Skip to content

Commit be5f4fe

Browse files
committed
Auto merge of #42262 - Mark-Simulacrum:issue-40350, r=eddyb
Don't ICE with nested enums in missing docs lint. Fixes #40350.
2 parents 9111927 + 918875f commit be5f4fe

File tree

2 files changed

+29
-44
lines changed

2 files changed

+29
-44
lines changed

src/librustc_lint/builtin.rs

+5-44
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,6 @@ declare_lint! {
259259
}
260260

261261
pub struct MissingDoc {
262-
/// Stack of IDs of struct definitions.
263-
struct_def_stack: Vec<ast::NodeId>,
264-
265-
/// True if inside variant definition
266-
in_variant: bool,
267-
268262
/// Stack of whether #[doc(hidden)] is set
269263
/// at each level which has lint attributes.
270264
doc_hidden_stack: Vec<bool>,
@@ -276,8 +270,6 @@ pub struct MissingDoc {
276270
impl MissingDoc {
277271
pub fn new() -> MissingDoc {
278272
MissingDoc {
279-
struct_def_stack: vec![],
280-
in_variant: false,
281273
doc_hidden_stack: vec![false],
282274
private_traits: HashSet::new(),
283275
}
@@ -345,25 +337,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
345337
self.doc_hidden_stack.pop().expect("empty doc_hidden_stack");
346338
}
347339

348-
fn check_struct_def(&mut self,
349-
_: &LateContext,
350-
_: &hir::VariantData,
351-
_: ast::Name,
352-
_: &hir::Generics,
353-
item_id: ast::NodeId) {
354-
self.struct_def_stack.push(item_id);
355-
}
356-
357-
fn check_struct_def_post(&mut self,
358-
_: &LateContext,
359-
_: &hir::VariantData,
360-
_: ast::Name,
361-
_: &hir::Generics,
362-
item_id: ast::NodeId) {
363-
let popped = self.struct_def_stack.pop().expect("empty struct_def_stack");
364-
assert!(popped == item_id);
365-
}
366-
367340
fn check_crate(&mut self, cx: &LateContext, krate: &hir::Crate) {
368341
self.check_missing_docs_attrs(cx, None, &krate.attrs, krate.span, "crate");
369342
}
@@ -451,16 +424,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
451424

452425
fn check_struct_field(&mut self, cx: &LateContext, sf: &hir::StructField) {
453426
if !sf.is_positional() {
454-
if sf.vis == hir::Public || self.in_variant {
455-
let cur_struct_def = *self.struct_def_stack
456-
.last()
457-
.expect("empty struct_def_stack");
458-
self.check_missing_docs_attrs(cx,
459-
Some(cur_struct_def),
460-
&sf.attrs,
461-
sf.span,
462-
"a struct field")
463-
}
427+
self.check_missing_docs_attrs(cx,
428+
Some(sf.id),
429+
&sf.attrs,
430+
sf.span,
431+
"a struct field")
464432
}
465433
}
466434

@@ -470,13 +438,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
470438
&v.node.attrs,
471439
v.span,
472440
"a variant");
473-
assert!(!self.in_variant);
474-
self.in_variant = true;
475-
}
476-
477-
fn check_variant_post(&mut self, _: &LateContext, _: &hir::Variant, _: &hir::Generics) {
478-
assert!(self.in_variant);
479-
self.in_variant = false;
480441
}
481442
}
482443

src/test/compile-fail/issue-40350.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(rustc_attrs)]
12+
#![allow(warnings)]
13+
14+
enum E {
15+
A = {
16+
enum F { B }
17+
0
18+
}
19+
}
20+
21+
#[rustc_error]
22+
fn main() {}
23+
//~^ ERROR compilation successful
24+

0 commit comments

Comments
 (0)