about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-07-15 03:28:17 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-07-18 13:42:45 +0300
commita7726ce08680c8c0789286f799be13c5b0ad9a01 (patch)
tree75c3dfaf07ed74bcc7ea9a0afc787f184dce6742
parent3845a08a555fcc5f97e9f6b77e0727e756f31a01 (diff)
downloadrust-a7726ce08680c8c0789286f799be13c5b0ad9a01.tar.gz
rust-a7726ce08680c8c0789286f799be13c5b0ad9a01.zip
resolve: Attempt to resolve unresolved paths in macro namespace
-rw-r--r--src/librustc_resolve/diagnostics.rs4
-rw-r--r--src/librustc_resolve/lib.rs32
-rw-r--r--src/test/ui/hygiene/rustc-macro-transparency.rs4
-rw-r--r--src/test/ui/hygiene/rustc-macro-transparency.stderr11
-rw-r--r--src/test/ui/impl-trait/universal_wrong_bounds.rs7
-rw-r--r--src/test/ui/impl-trait/universal_wrong_bounds.stderr14
-rw-r--r--src/test/ui/issues/issue-37534.rs2
-rw-r--r--src/test/ui/issues/issue-37534.stderr8
-rw-r--r--src/test/ui/no-implicit-prelude-nested.rs6
-rw-r--r--src/test/ui/no-implicit-prelude-nested.stderr22
-rw-r--r--src/test/ui/no-implicit-prelude.rs2
-rw-r--r--src/test/ui/no-implicit-prelude.stderr10
12 files changed, 62 insertions, 60 deletions
diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs
index 7bd4ee0deea..9024d2ae36f 100644
--- a/src/librustc_resolve/diagnostics.rs
+++ b/src/librustc_resolve/diagnostics.rs
@@ -414,7 +414,7 @@ impl<'a> Resolver<'a> {
         };
 
         match (res, source) {
-            (Res::Def(DefKind::Macro(..), _), _) => {
+            (Res::Def(DefKind::Macro(MacroKind::Bang), _), _) => {
                 err.span_suggestion(
                     span,
                     "use `!` to invoke the macro",
@@ -574,7 +574,7 @@ impl<'a> Resolver<'a> {
                         for derive in &parent_scope.derives {
                             let parent_scope = ParentScope { derives: Vec::new(), ..*parent_scope };
                             if let Ok((Some(ext), _)) = this.resolve_macro_path(
-                                derive, MacroKind::Derive, &parent_scope, true, true
+                                derive, MacroKind::Derive, &parent_scope, false, false
                             ) {
                                 suggestions.extend(ext.helper_attrs.iter().map(|name| {
                                     TypoSuggestion::from_res(*name, res)
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index e4d8ae11f0f..4679c80ee1c 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -3664,9 +3664,7 @@ impl<'a> Resolver<'a> {
         crate_lint: CrateLint,
     ) -> Option<PartialRes> {
         let mut fin_res = None;
-        // FIXME: can't resolve paths in macro namespace yet, macros are
-        // processed by the little special hack below.
-        for (i, ns) in [primary_ns, TypeNS, ValueNS, /*MacroNS*/].iter().cloned().enumerate() {
+        for (i, ns) in [primary_ns, TypeNS, ValueNS].iter().cloned().enumerate() {
             if i == 0 || ns != primary_ns {
                 match self.resolve_qpath(id, qself, path, ns, span, global_by_default, crate_lint) {
                     // If defer_to_typeck, then resolution > no resolution,
@@ -3675,21 +3673,25 @@ impl<'a> Resolver<'a> {
                                          defer_to_typeck =>
                         return Some(partial_res),
                     partial_res => if fin_res.is_none() { fin_res = partial_res },
-                };
+                }
             }
         }
-        if primary_ns != MacroNS &&
-           (self.macro_names.contains(&path[0].ident.modern()) ||
-            self.builtin_macros.get(&path[0].ident.name).cloned()
-                               .and_then(NameBinding::macro_kind) == Some(MacroKind::Bang) ||
-            self.macro_use_prelude.get(&path[0].ident.name).cloned()
-                                  .and_then(NameBinding::macro_kind) == Some(MacroKind::Bang)) {
-            // Return some dummy definition, it's enough for error reporting.
-            return Some(PartialRes::new(Res::Def(
-                DefKind::Macro(MacroKind::Bang),
-                DefId::local(CRATE_DEF_INDEX),
-            )));
+
+        // `MacroNS`
+        assert!(primary_ns != MacroNS);
+        if qself.is_none() {
+            let path_seg = |seg: &Segment| ast::PathSegment::from_ident(seg.ident);
+            let path = Path { segments: path.iter().map(path_seg).collect(), span };
+            let parent_scope =
+                ParentScope { module: self.current_module, ..self.dummy_parent_scope() };
+            for macro_kind in &[MacroKind::Bang, MacroKind::Attr, MacroKind::Derive] {
+                if let Ok((_, res)) = self.resolve_macro_path(&path, *macro_kind,
+                                                              &parent_scope, false, false) {
+                    return Some(PartialRes::new(res));
+                }
+            }
         }
+
         fin_res
     }
 
diff --git a/src/test/ui/hygiene/rustc-macro-transparency.rs b/src/test/ui/hygiene/rustc-macro-transparency.rs
index a0a3d411d28..5f36993af2f 100644
--- a/src/test/ui/hygiene/rustc-macro-transparency.rs
+++ b/src/test/ui/hygiene/rustc-macro-transparency.rs
@@ -26,6 +26,6 @@ fn main() {
     Opaque; //~ ERROR cannot find value `Opaque` in this scope
 
     transparent; // OK
-    semitransparent; //~ ERROR cannot find value `semitransparent` in this scope
-    opaque; //~ ERROR cannot find value `opaque` in this scope
+    semitransparent; //~ ERROR expected value, found macro `semitransparent`
+    opaque; //~ ERROR expected value, found macro `opaque`
 }
diff --git a/src/test/ui/hygiene/rustc-macro-transparency.stderr b/src/test/ui/hygiene/rustc-macro-transparency.stderr
index 2a9df221e2c..5eacfdf8dee 100644
--- a/src/test/ui/hygiene/rustc-macro-transparency.stderr
+++ b/src/test/ui/hygiene/rustc-macro-transparency.stderr
@@ -4,18 +4,19 @@ error[E0425]: cannot find value `Opaque` in this scope
 LL |     Opaque;
    |     ^^^^^^ help: a local variable with a similar name exists: `opaque`
 
-error[E0425]: cannot find value `semitransparent` in this scope
+error[E0423]: expected value, found macro `semitransparent`
   --> $DIR/rustc-macro-transparency.rs:29:5
    |
 LL |     semitransparent;
-   |     ^^^^^^^^^^^^^^^ not found in this scope
+   |     ^^^^^^^^^^^^^^^ help: use `!` to invoke the macro: `semitransparent!`
 
-error[E0425]: cannot find value `opaque` in this scope
+error[E0423]: expected value, found macro `opaque`
   --> $DIR/rustc-macro-transparency.rs:30:5
    |
 LL |     opaque;
-   |     ^^^^^^ not found in this scope
+   |     ^^^^^^ help: use `!` to invoke the macro: `opaque!`
 
 error: aborting due to 3 previous errors
 
-For more information about this error, try `rustc --explain E0425`.
+Some errors have detailed explanations: E0423, E0425.
+For more information about an error, try `rustc --explain E0423`.
diff --git a/src/test/ui/impl-trait/universal_wrong_bounds.rs b/src/test/ui/impl-trait/universal_wrong_bounds.rs
index 56a13ea257e..2182506c7b7 100644
--- a/src/test/ui/impl-trait/universal_wrong_bounds.rs
+++ b/src/test/ui/impl-trait/universal_wrong_bounds.rs
@@ -6,9 +6,8 @@ fn foo(f: impl Display + Clone) -> String {
     wants_clone(f);
 }
 
-fn wants_debug(g: impl Debug) { } //~ ERROR cannot find
-fn wants_display(g: impl Debug) { } //~ ERROR cannot find
+fn wants_debug(g: impl Debug) { } //~ ERROR expected trait, found derive macro `Debug`
+fn wants_display(g: impl Debug) { } //~ ERROR expected trait, found derive macro `Debug`
 fn wants_clone(g: impl Clone) { }
 
-fn main() {
-}
+fn main() {}
diff --git a/src/test/ui/impl-trait/universal_wrong_bounds.stderr b/src/test/ui/impl-trait/universal_wrong_bounds.stderr
index 1fd3ebff62a..f530792955b 100644
--- a/src/test/ui/impl-trait/universal_wrong_bounds.stderr
+++ b/src/test/ui/impl-trait/universal_wrong_bounds.stderr
@@ -1,23 +1,23 @@
-error[E0405]: cannot find trait `Debug` in this scope
+error[E0404]: expected trait, found derive macro `Debug`
   --> $DIR/universal_wrong_bounds.rs:9:24
    |
 LL | fn wants_debug(g: impl Debug) { }
-   |                        ^^^^^ not found in this scope
-help: possible candidate is found in another module, you can import it into scope
+   |                        ^^^^^ not a trait
+help: possible better candidate is found in another module, you can import it into scope
    |
 LL | use std::fmt::Debug;
    |
 
-error[E0405]: cannot find trait `Debug` in this scope
+error[E0404]: expected trait, found derive macro `Debug`
   --> $DIR/universal_wrong_bounds.rs:10:26
    |
 LL | fn wants_display(g: impl Debug) { }
-   |                          ^^^^^ not found in this scope
-help: possible candidate is found in another module, you can import it into scope
+   |                          ^^^^^ not a trait
+help: possible better candidate is found in another module, you can import it into scope
    |
 LL | use std::fmt::Debug;
    |
 
 error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0405`.
+For more information about this error, try `rustc --explain E0404`.
diff --git a/src/test/ui/issues/issue-37534.rs b/src/test/ui/issues/issue-37534.rs
index 9386b4516a3..1e67e9a8158 100644
--- a/src/test/ui/issues/issue-37534.rs
+++ b/src/test/ui/issues/issue-37534.rs
@@ -1,5 +1,5 @@
 struct Foo<T: ?Hash> { }
-//~^ ERROR cannot find trait `Hash` in this scope
+//~^ ERROR expected trait, found derive macro `Hash`
 //~^^ ERROR parameter `T` is never used
 //~^^^ WARN default bound relaxed for a type parameter, but this does nothing
 
diff --git a/src/test/ui/issues/issue-37534.stderr b/src/test/ui/issues/issue-37534.stderr
index 741e93561bc..3a0ab32dcc6 100644
--- a/src/test/ui/issues/issue-37534.stderr
+++ b/src/test/ui/issues/issue-37534.stderr
@@ -1,9 +1,9 @@
-error[E0405]: cannot find trait `Hash` in this scope
+error[E0404]: expected trait, found derive macro `Hash`
   --> $DIR/issue-37534.rs:1:16
    |
 LL | struct Foo<T: ?Hash> { }
-   |                ^^^^ not found in this scope
-help: possible candidate is found in another module, you can import it into scope
+   |                ^^^^ not a trait
+help: possible better candidate is found in another module, you can import it into scope
    |
 LL | use std::hash::Hash;
    |
@@ -24,5 +24,5 @@ LL | struct Foo<T: ?Hash> { }
 
 error: aborting due to 2 previous errors
 
-Some errors have detailed explanations: E0392, E0405.
+Some errors have detailed explanations: E0392, E0404.
 For more information about an error, try `rustc --explain E0392`.
diff --git a/src/test/ui/no-implicit-prelude-nested.rs b/src/test/ui/no-implicit-prelude-nested.rs
index fae52c0edc1..c314967da4f 100644
--- a/src/test/ui/no-implicit-prelude-nested.rs
+++ b/src/test/ui/no-implicit-prelude-nested.rs
@@ -9,7 +9,7 @@ mod foo {
     mod baz {
         struct Test;
         impl Add for Test {} //~ ERROR cannot find trait `Add` in this scope
-        impl Clone for Test {} //~ ERROR cannot find trait `Clone` in this scope
+        impl Clone for Test {} //~ ERROR expected trait, found derive macro `Clone`
         impl Iterator for Test {} //~ ERROR cannot find trait `Iterator` in this scope
         impl ToString for Test {} //~ ERROR cannot find trait `ToString` in this scope
         impl Writer for Test {} //~ ERROR cannot find trait `Writer` in this scope
@@ -21,7 +21,7 @@ mod foo {
 
     struct Test;
     impl Add for Test {} //~ ERROR cannot find trait `Add` in this scope
-    impl Clone for Test {} //~ ERROR cannot find trait `Clone` in this scope
+    impl Clone for Test {} //~ ERROR expected trait, found derive macro `Clone`
     impl Iterator for Test {} //~ ERROR cannot find trait `Iterator` in this scope
     impl ToString for Test {} //~ ERROR cannot find trait `ToString` in this scope
     impl Writer for Test {} //~ ERROR cannot find trait `Writer` in this scope
@@ -36,7 +36,7 @@ fn qux() {
     mod qux_inner {
         struct Test;
         impl Add for Test {} //~ ERROR cannot find trait `Add` in this scope
-        impl Clone for Test {} //~ ERROR cannot find trait `Clone` in this scope
+        impl Clone for Test {} //~ ERROR expected trait, found derive macro `Clone`
         impl Iterator for Test {} //~ ERROR cannot find trait `Iterator` in this scope
         impl ToString for Test {} //~ ERROR cannot find trait `ToString` in this scope
         impl Writer for Test {} //~ ERROR cannot find trait `Writer` in this scope
diff --git a/src/test/ui/no-implicit-prelude-nested.stderr b/src/test/ui/no-implicit-prelude-nested.stderr
index 79b9396d41c..8d695e45da4 100644
--- a/src/test/ui/no-implicit-prelude-nested.stderr
+++ b/src/test/ui/no-implicit-prelude-nested.stderr
@@ -8,12 +8,12 @@ help: possible candidate is found in another module, you can import it into scop
 LL |         use std::ops::Add;
    |
 
-error[E0405]: cannot find trait `Clone` in this scope
+error[E0404]: expected trait, found derive macro `Clone`
   --> $DIR/no-implicit-prelude-nested.rs:12:14
    |
 LL |         impl Clone for Test {}
-   |              ^^^^^ not found in this scope
-help: possible candidates are found in other modules, you can import them into scope
+   |              ^^^^^ not a trait
+help: possible better candidates are found in other modules, you can import them into scope
    |
 LL |         use std::clone::Clone;
    |
@@ -72,12 +72,12 @@ help: possible candidate is found in another module, you can import it into scop
 LL |     use std::ops::Add;
    |
 
-error[E0405]: cannot find trait `Clone` in this scope
+error[E0404]: expected trait, found derive macro `Clone`
   --> $DIR/no-implicit-prelude-nested.rs:24:10
    |
 LL |     impl Clone for Test {}
-   |          ^^^^^ not found in this scope
-help: possible candidates are found in other modules, you can import them into scope
+   |          ^^^^^ not a trait
+help: possible better candidates are found in other modules, you can import them into scope
    |
 LL |     use std::clone::Clone;
    |
@@ -136,12 +136,12 @@ help: possible candidate is found in another module, you can import it into scop
 LL |         use std::ops::Add;
    |
 
-error[E0405]: cannot find trait `Clone` in this scope
+error[E0404]: expected trait, found derive macro `Clone`
   --> $DIR/no-implicit-prelude-nested.rs:39:14
    |
 LL |         impl Clone for Test {}
-   |              ^^^^^ not found in this scope
-help: possible candidates are found in other modules, you can import them into scope
+   |              ^^^^^ not a trait
+help: possible better candidates are found in other modules, you can import them into scope
    |
 LL |         use std::clone::Clone;
    |
@@ -192,5 +192,5 @@ LL |         use std::prelude::v1::drop;
 
 error: aborting due to 18 previous errors
 
-Some errors have detailed explanations: E0405, E0425.
-For more information about an error, try `rustc --explain E0405`.
+Some errors have detailed explanations: E0404, E0405, E0425.
+For more information about an error, try `rustc --explain E0404`.
diff --git a/src/test/ui/no-implicit-prelude.rs b/src/test/ui/no-implicit-prelude.rs
index e2074bbb8c8..4b0ca4d524e 100644
--- a/src/test/ui/no-implicit-prelude.rs
+++ b/src/test/ui/no-implicit-prelude.rs
@@ -8,7 +8,7 @@
 
 struct Test;
 impl Add for Test {} //~ ERROR cannot find trait `Add` in this scope
-impl Clone for Test {} //~ ERROR cannot find trait `Clone` in this scope
+impl Clone for Test {} //~ ERROR expected trait, found derive macro `Clone`
 impl Iterator for Test {} //~ ERROR cannot find trait `Iterator` in this scope
 impl ToString for Test {} //~ ERROR cannot find trait `ToString` in this scope
 impl Writer for Test {} //~ ERROR cannot find trait `Writer` in this scope
diff --git a/src/test/ui/no-implicit-prelude.stderr b/src/test/ui/no-implicit-prelude.stderr
index eac1fcb7b67..6ae889df602 100644
--- a/src/test/ui/no-implicit-prelude.stderr
+++ b/src/test/ui/no-implicit-prelude.stderr
@@ -8,12 +8,12 @@ help: possible candidate is found in another module, you can import it into scop
 LL | use std::ops::Add;
    |
 
-error[E0405]: cannot find trait `Clone` in this scope
+error[E0404]: expected trait, found derive macro `Clone`
   --> $DIR/no-implicit-prelude.rs:11:6
    |
 LL | impl Clone for Test {}
-   |      ^^^^^ not found in this scope
-help: possible candidates are found in other modules, you can import them into scope
+   |      ^^^^^ not a trait
+help: possible better candidates are found in other modules, you can import them into scope
    |
 LL | use std::clone::Clone;
    |
@@ -64,5 +64,5 @@ LL | use std::prelude::v1::drop;
 
 error: aborting due to 6 previous errors
 
-Some errors have detailed explanations: E0405, E0425.
-For more information about an error, try `rustc --explain E0405`.
+Some errors have detailed explanations: E0404, E0405, E0425.
+For more information about an error, try `rustc --explain E0404`.