From 04309be834e94b8382ab67b0901103b5b61a7c66 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 2 Feb 2018 12:09:25 +0530 Subject: [PATCH 1/2] Fix rustdoc ICE on macros defined within functions fixes #47639 --- src/librustc/lint/context.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 32ab458cb91de..2efb9f2dc9cae 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -1042,11 +1042,20 @@ pub fn check_ast_crate(sess: &Session, krate: &ast::Crate) { // Put the lint store levels and passes back in the session. cx.lint_sess.restore(&sess.lint_store); - // Emit all buffered lints from early on in the session now that we've - // calculated the lint levels for all AST nodes. - for (_id, lints) in cx.buffered.map { - for early_lint in lints { - span_bug!(early_lint.span, "failed to process bufferd lint here"); + // All of the buffered lints should have been emitted at this point. + // If not, that means that we somehow buffered a lint for a node id + // that was not lint-checked (perhaps it doesn't exist?). This is a bug. + // + // Rustdoc runs everybody-loops before the early lints and removes + // function bodies, so it's totally possible for linted + // node ids to not exist (e.g. macros defined within functions for the + // unused_macro lint) anymore. So we only run this check + // when we're not in rustdoc mode. (see issue #47639) + if !sess.opts.actually_rustdoc { + for (_id, lints) in cx.buffered.map { + for early_lint in lints { + span_bug!(early_lint.span, "failed to process buffered lint here"); + } } } } From c3cf9bc5c796dfe72e947c19e9ca63e94d5d419d Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 2 Feb 2018 12:11:16 +0530 Subject: [PATCH 2/2] Add regression test --- src/test/rustdoc/issue-47639.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/test/rustdoc/issue-47639.rs diff --git a/src/test/rustdoc/issue-47639.rs b/src/test/rustdoc/issue-47639.rs new file mode 100644 index 0000000000000..167c3aaec4ab6 --- /dev/null +++ b/src/test/rustdoc/issue-47639.rs @@ -0,0 +1,16 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// This should not ICE +pub fn test() { + macro_rules! foo { + () => () + } +}