about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-03-17 17:20:47 +0800
committerGitHub <noreply@github.com>2018-03-17 17:20:47 +0800
commitf24e35cabdc686f616b285ec7b01b53715a6a7bf (patch)
treefaea87515927ded5ab712aa3879764607a3c47ef
parentc78426bfc88062ec28664a309ff32d4b3c206a9f (diff)
parent4be3e96b80a5dc5bddeaccd2a7c3af1abf8bf452 (diff)
downloadrust-f24e35cabdc686f616b285ec7b01b53715a6a7bf.tar.gz
rust-f24e35cabdc686f616b285ec7b01b53715a6a7bf.zip
Rollup merge of #49077 - sinkuu:macro_use_typo, r=estebank
Checks for unknown attributes before aborting due to unresolved macros

Fixes #49074

The ``attribute `...` is currently unknown to the compiler`` error was not shown if there are any unresolved macros, which might be caused by mistyped `macro_use`.
-rw-r--r--src/librustc_driver/driver.rs10
-rw-r--r--src/test/ui/issue-49074.rs24
-rw-r--r--src/test/ui/issue-49074.stderr19
3 files changed, 49 insertions, 4 deletions
diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs
index e52575f02b2..b5e31bdf668 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 00000000000..2e7e1184410
--- /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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 00000000000..c9984ea2e9a
--- /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`.