]> git.lizzy.rs Git - rust.git/commitdiff
Don't suggest importing items with hygienic names
authorMatthew Jasper <mjjasper1@gmail.com>
Thu, 21 Oct 2021 22:36:51 +0000 (23:36 +0100)
committerMatthew Jasper <mjjasper1@gmail.com>
Thu, 21 Oct 2021 22:36:51 +0000 (23:36 +0100)
This will potentially hide a few correct suggestions, but importing
these items from another module is not generally possible.

compiler/rustc_resolve/src/diagnostics.rs
compiler/rustc_span/src/hygiene.rs

index 63000a9d13d412eb2920c7d894dbb1c2008b450a..aefb3f2cb9c8399d25be44f42d7f20a58249bca0 100644 (file)
@@ -831,9 +831,11 @@ fn lookup_import_candidates_from_module<FilterFn>(
 
                 // collect results based on the filter function
                 // avoid suggesting anything from the same module in which we are resolving
+                // avoid suggesting anything with a hygienic name
                 if ident.name == lookup_ident.name
                     && ns == namespace
                     && !ptr::eq(in_module, parent_scope.module)
+                    && !ident.span.normalize_to_macros_2_0().from_expansion()
                 {
                     let res = name_binding.res();
                     if filter_fn(res) {
index aa15febe8853d709855a1ffc919dc18c67f4e5c9..724d1904dc33c7125d7231f2190abc64d7d4f7c9 100644 (file)
@@ -709,7 +709,7 @@ pub fn normalize_to_macros_2_0_and_adjust(&mut self, expn_id: ExpnId) -> Option<
     ///         pub fn f() {} // `f`'s `SyntaxContext` has a single `ExpnId` from `m`.
     ///         pub fn $i() {} // `$i`'s `SyntaxContext` is empty.
     ///     }
-    ///     n(f);
+    ///     n!(f);
     ///     macro n($j:ident) {
     ///         use foo::*;
     ///         f(); // `f`'s `SyntaxContext` has a mark from `m` and a mark from `n`