Skip to content

Commit b996a98

Browse files
committed
rustdoc: skip PatKind::Missing in visit_pat
1 parent cb79c42 commit b996a98

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

compiler/rustc_ast_pretty/src/pprust/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ pub fn where_bound_predicate_to_string(where_bound_predicate: &ast::WhereBoundPr
3333
State::new().where_bound_predicate_to_string(where_bound_predicate)
3434
}
3535

36+
/// # Panics
37+
///
38+
/// Panics if `pat.kind` is `PatKind::Missing`.
3639
pub fn pat_to_string(pat: &ast::Pat) -> String {
3740
State::new().pat_to_string(pat)
3841
}

src/librustdoc/html/macro_expansion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_ast::visit::{Visitor, walk_crate, walk_expr, walk_item, walk_pat, walk_stmt};
2-
use rustc_ast::{Crate, Expr, Item, Pat, Stmt};
2+
use rustc_ast::{Crate, Expr, Item, Pat, PatKind, Stmt};
33
use rustc_data_structures::fx::FxHashMap;
44
use rustc_span::source_map::SourceMap;
55
use rustc_span::{BytePos, Span};
@@ -147,7 +147,7 @@ impl<'ast> Visitor<'ast> for ExpandedCodeVisitor<'ast> {
147147
}
148148

149149
fn visit_pat(&mut self, pat: &'ast Pat) {
150-
if pat.span.from_expansion() {
150+
if pat.span.from_expansion() && !matches!(pat.kind, PatKind::Missing) {
151151
self.handle_new_span(pat.span, || rustc_ast_pretty::pprust::pat_to_string(pat));
152152
} else {
153153
walk_pat(self, pat);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Ensure rustdoc does not ICE When expanding a macro that
2+
// generates a `PatKind::Missing` pattern.
3+
4+
//@ compile-flags: -Zunstable-options --generate-macro-expansion
5+
6+
#![crate_name = "foo"]
7+
8+
//@ has 'src/foo/missing-par-ice-150154.rs.html'
9+
10+
macro_rules! foo {
11+
() => {
12+
fn(())
13+
}
14+
}
15+
16+
fn bar() {
17+
let _: foo!();
18+
}

0 commit comments

Comments
 (0)