From 4be3e96b80a5dc5bddeaccd2a7c3af1abf8bf452 Mon Sep 17 00:00:00 2001 From: Shotaro Yamada Date: Fri, 16 Mar 2018 16:53:40 +0900 Subject: [PATCH] Checks for unknown attributes before aborting ...due to unresolved macros. --- src/librustc_driver/driver.rs | 10 ++++++---- src/test/ui/issue-49074.rs | 24 ++++++++++++++++++++++++ src/test/ui/issue-49074.stderr | 19 +++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/issue-49074.rs create mode 100644 src/test/ui/issue-49074.stderr diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index e52575f02b2ff..b5e31bdf6686a 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -877,10 +877,6 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session, Ok(()) })?; - if resolver.found_unresolved_macro { - sess.parse_sess.span_diagnostic.abort_if_errors(); - } - // Needs to go *after* expansion to be able to check the results of macro expansion. time(sess, "complete gated feature checking", || { sess.track_errors(|| { @@ -892,6 +888,12 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session, }) })?; + // Unresolved macros might be due to mistyped `#[macro_use]`, + // so abort after checking for unknown attributes. (#49074) + if resolver.found_unresolved_macro { + sess.parse_sess.span_diagnostic.abort_if_errors(); + } + // Lower ast -> hir. // First, we need to collect the dep_graph. let dep_graph = match future_dep_graph { diff --git a/src/test/ui/issue-49074.rs b/src/test/ui/issue-49074.rs new file mode 100644 index 0000000000000..2e7e118441090 --- /dev/null +++ b/src/test/ui/issue-49074.rs @@ -0,0 +1,24 @@ +// 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. + +// Check that unknown attribute error is shown even if there are unresolved macros. + +#[marco_use] // typo +//~^ ERROR The attribute `marco_use` is currently unknown to the compiler +mod foo { + macro_rules! bar { + () => (); + } +} + +fn main() { + bar!(); + //~^ ERROR cannot find macro `bar!` +} diff --git a/src/test/ui/issue-49074.stderr b/src/test/ui/issue-49074.stderr new file mode 100644 index 0000000000000..c9984ea2e9a8a --- /dev/null +++ b/src/test/ui/issue-49074.stderr @@ -0,0 +1,19 @@ +error: cannot find macro `bar!` in this scope + --> $DIR/issue-49074.rs:22:4 + | +LL | bar!(); + | ^^^ + | + = help: have you added the `#[macro_use]` on the module/import? + +error[E0658]: The attribute `marco_use` is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642) + --> $DIR/issue-49074.rs:13:1 + | +LL | #[marco_use] // typo + | ^^^^^^^^^^^^ + | + = help: add #![feature(custom_attribute)] to the crate attributes to enable + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0658`.