about summary refs log tree commit diff
diff options
context:
space:
mode:
authortopecongiro <seuchida@gmail.com>2017-12-28 00:46:27 +0900
committertopecongiro <seuchida@gmail.com>2017-12-28 00:46:27 +0900
commitd1b287cf3274bf26f9bcb30dbad3cb31d8e1cded (patch)
treef0ba140a0488045f0e15919fda9f3e489773e849
parent0efdfa1d6220484770e3730062b92a9d2b2e20b9 (diff)
Report an error when resolving non-ident macro path failed
-rw-r--r--src/librustc_resolve/macros.rs10
-rw-r--r--src/test/compile-fail/extern-macro.rs18
2 files changed, 27 insertions, 1 deletions
diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs
index 260a0cd7cd7..14b5c6c9a5e 100644
--- a/src/librustc_resolve/macros.rs
+++ b/src/librustc_resolve/macros.rs
@@ -429,7 +429,15 @@ impl<'a> Resolver<'a> {
             let def = match self.resolve_path(&path, Some(MacroNS), false, span) {
                 PathResult::NonModule(path_res) => match path_res.base_def() {
                     Def::Err => Err(Determinacy::Determined),
-                    def @ _ => Ok(def),
+                    def @ _ => {
+                        if path_res.unresolved_segments() > 0 {
+                            self.found_unresolved_macro = true;
+                            self.session.span_err(span, "fail to resolve non-ident macro path");
+                            Err(Determinacy::Determined)
+                        } else {
+                            Ok(def)
+                        }
+                    }
                 },
                 PathResult::Module(..) => unreachable!(),
                 PathResult::Indeterminate if !force => return Err(Determinacy::Undetermined),
diff --git a/src/test/compile-fail/extern-macro.rs b/src/test/compile-fail/extern-macro.rs
new file mode 100644
index 00000000000..4267103ab9a
--- /dev/null
+++ b/src/test/compile-fail/extern-macro.rs
@@ -0,0 +1,18 @@
+// Copyright 2017 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.
+
+// #41719
+
+#![feature(use_extern_macros)]
+
+fn main() {
+    enum Foo {}
+    let _ = Foo::bar!(); //~ ERROR fail to resolve non-ident macro path
+}