about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJonas Schievink <jonasschievink@gmail.com>2020-10-24 22:40:00 +0200
committerGitHub <noreply@github.com>2020-10-24 22:40:00 +0200
commit58ae889779e761e35d3ca0c8c7beb92cde52dd7d (patch)
tree10d7ea33a9c6d0412470cd4122ea4afdd5563ed3
parenta8ff5a4e03a4f0fc7cb87bc3fdb4a1e0144e6e73 (diff)
parentef09ed200227207872b8e201d091681be3240c5b (diff)
downloadrust-58ae889779e761e35d3ca0c8c7beb92cde52dd7d.tar.gz
rust-58ae889779e761e35d3ca0c8c7beb92cde52dd7d.zip
Rollup merge of #78327 - petrochenkov:inconsist, r=Aaron1011
resolve: Relax macro resolution consistency check to account for any errors

The check was previously omitted only when ambiguity errors or `Res::Err` were encountered, but the "macro-expanded `extern crate` items cannot shadow..." error (at least) can cause same inconsistencies as well.

Fixes https://github.com/rust-lang/rust/issues/78325
-rw-r--r--compiler/rustc_resolve/src/macros.rs8
-rw-r--r--src/test/ui/macros/issue-78325-inconsistent-resolution.rs12
-rw-r--r--src/test/ui/macros/issue-78325-inconsistent-resolution.stderr13
3 files changed, 29 insertions, 4 deletions
diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs
index bea71389647..b5b281b93bc 100644
--- a/compiler/rustc_resolve/src/macros.rs
+++ b/compiler/rustc_resolve/src/macros.rs
@@ -19,7 +19,7 @@ use rustc_feature::is_builtin_attr_name;
 use rustc_hir::def::{self, DefKind, NonMacroAttrKind};
 use rustc_hir::def_id;
 use rustc_middle::middle::stability;
-use rustc_middle::{span_bug, ty};
+use rustc_middle::ty;
 use rustc_session::lint::builtin::UNUSED_MACROS;
 use rustc_session::Session;
 use rustc_span::edition::Edition;
@@ -885,11 +885,11 @@ impl<'a> Resolver<'a> {
                                  initial_res: Option<Res>,
                                  res: Res| {
             if let Some(initial_res) = initial_res {
-                if res != initial_res && res != Res::Err && this.ambiguity_errors.is_empty() {
+                if res != initial_res {
                     // Make sure compilation does not succeed if preferred macro resolution
                     // has changed after the macro had been expanded. In theory all such
-                    // situations should be reported as ambiguity errors, so this is a bug.
-                    span_bug!(span, "inconsistent resolution for a macro");
+                    // situations should be reported as errors, so this is a bug.
+                    this.session.delay_span_bug(span, "inconsistent resolution for a macro");
                 }
             } else {
                 // It's possible that the macro was unresolved (indeterminate) and silently
diff --git a/src/test/ui/macros/issue-78325-inconsistent-resolution.rs b/src/test/ui/macros/issue-78325-inconsistent-resolution.rs
new file mode 100644
index 00000000000..919eca4f9bf
--- /dev/null
+++ b/src/test/ui/macros/issue-78325-inconsistent-resolution.rs
@@ -0,0 +1,12 @@
+macro_rules! define_other_core {
+    ( ) => {
+        extern crate std as core;
+        //~^ ERROR macro-expanded `extern crate` items cannot shadow names passed with `--extern`
+    };
+}
+
+fn main() {
+    core::panic!();
+}
+
+define_other_core!();
diff --git a/src/test/ui/macros/issue-78325-inconsistent-resolution.stderr b/src/test/ui/macros/issue-78325-inconsistent-resolution.stderr
new file mode 100644
index 00000000000..cf3af593141
--- /dev/null
+++ b/src/test/ui/macros/issue-78325-inconsistent-resolution.stderr
@@ -0,0 +1,13 @@
+error: macro-expanded `extern crate` items cannot shadow names passed with `--extern`
+  --> $DIR/issue-78325-inconsistent-resolution.rs:3:9
+   |
+LL |         extern crate std as core;
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | define_other_core!();
+   | --------------------- in this macro invocation
+   |
+   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to previous error
+