Fix a hole in generic parameter import future-proofing

Add some tests for buggy derive helpers
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index 50704a6..5f571dc 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -75,7 +75,7 @@
 use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
 
 use std::cell::{Cell, RefCell};
-use std::{cmp, fmt, iter, ptr};
+use std::{cmp, fmt, iter, mem, ptr};
 use std::collections::BTreeSet;
 use std::mem::replace;
 use rustc_data_structures::ptr_key::PtrKey;
@@ -2394,11 +2394,27 @@
                 ast::UseTreeKind::Simple(..) if segments.len() == 1 => &[TypeNS, ValueNS][..],
                 _ => &[TypeNS],
             };
+            let report_error = |this: &Self, ns| {
+                let what = if ns == TypeNS { "type parameters" } else { "local variables" };
+                this.session.span_err(ident.span, &format!("imports cannot refer to {}", what));
+            };
+
             for &ns in nss {
-                if let Some(LexicalScopeBinding::Def(..)) =
-                        self.resolve_ident_in_lexical_scope(ident, ns, None, use_tree.prefix.span) {
-                    let what = if ns == TypeNS { "type parameters" } else { "local variables" };
-                    self.session.span_err(ident.span, &format!("imports cannot refer to {}", what));
+                match self.resolve_ident_in_lexical_scope(ident, ns, None, use_tree.prefix.span) {
+                    Some(LexicalScopeBinding::Def(..)) => {
+                        report_error(self, ns);
+                    }
+                    Some(LexicalScopeBinding::Item(binding)) => {
+                        let orig_blacklisted_binding =
+                            mem::replace(&mut self.blacklisted_binding, Some(binding));
+                        if let Some(LexicalScopeBinding::Def(..)) =
+                                self.resolve_ident_in_lexical_scope(ident, ns, None,
+                                                                    use_tree.prefix.span) {
+                            report_error(self, ns);
+                        }
+                        self.blacklisted_binding = orig_blacklisted_binding;
+                    }
+                    None => {}
                 }
             }
         } else if let ast::UseTreeKind::Nested(use_trees) = &use_tree.kind {
diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs
index 5a0ccb6..3fa07cb 100644
--- a/src/librustc_resolve/resolve_imports.rs
+++ b/src/librustc_resolve/resolve_imports.rs
@@ -228,6 +228,11 @@
         }
 
         let check_usable = |this: &mut Self, binding: &'a NameBinding<'a>| {
+            if let Some(blacklisted_binding) = this.blacklisted_binding {
+                if ptr::eq(binding, blacklisted_binding) {
+                    return Err((Determined, Weak::No));
+                }
+            }
             // `extern crate` are always usable for backwards compatibility, see issue #37020,
             // remove this together with `PUB_USE_OF_PRIVATE_EXTERN_CRATE`.
             let usable = this.is_accessible(binding.vis) || binding.is_extern_crate();
diff --git a/src/test/ui/imports/issue-56125.stderr b/src/test/ui/imports/issue-56125.stderr
index 2011184..0a93b2f 100644
--- a/src/test/ui/imports/issue-56125.stderr
+++ b/src/test/ui/imports/issue-56125.stderr
@@ -55,7 +55,7 @@
    = note: `issue_56125` could refer to an extern crate passed with `--extern`
    = help: use `::issue_56125` to refer to this extern crate unambiguously
 note: `issue_56125` could also refer to the module imported here
-  --> $DIR/issue-56125.rs:17:9
+  --> $DIR/issue-56125.rs:18:9
    |
 LL |     use issue_56125::*; //~ ERROR `issue_56125` is ambiguous
    |         ^^^^^^^^^^^^^^
diff --git a/src/test/ui/proc-macro/derive-helper-shadowing.rs b/src/test/ui/proc-macro/derive-helper-shadowing.rs
index aa9eae0..f6fe9f9 100644
--- a/src/test/ui/proc-macro/derive-helper-shadowing.rs
+++ b/src/test/ui/proc-macro/derive-helper-shadowing.rs
@@ -5,6 +5,26 @@
 
 #[my_attr] //~ ERROR `my_attr` is ambiguous
 #[derive(MyTrait)]
-struct S;
+struct S {
+    // FIXME No ambiguity, attributes in non-macro positions are not resolved properly
+    #[my_attr]
+    field: [u8; {
+        // FIXME No ambiguity, derive helpers are not put into scope for non-attributes
+        use my_attr;
 
-fn main() {}
+        // FIXME No ambiguity, derive helpers are not put into scope for inner items
+        #[my_attr]
+        struct U;
+
+        mod inner {
+            #[my_attr] //~ ERROR attribute `my_attr` is currently unknown
+            struct V;
+        }
+
+        0
+    }]
+}
+
+fn main() {
+    let s = S { field: [] };
+}
diff --git a/src/test/ui/proc-macro/derive-helper-shadowing.stderr b/src/test/ui/proc-macro/derive-helper-shadowing.stderr
index cc50fef..8180c84 100644
--- a/src/test/ui/proc-macro/derive-helper-shadowing.stderr
+++ b/src/test/ui/proc-macro/derive-helper-shadowing.stderr
@@ -1,3 +1,11 @@
+error[E0658]: The attribute `my_attr` is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
+  --> $DIR/derive-helper-shadowing.rs:20:15
+   |
+LL |             #[my_attr] //~ ERROR attribute `my_attr` is currently unknown
+   |               ^^^^^^^
+   |
+   = help: add #![feature(custom_attribute)] to the crate attributes to enable
+
 error[E0659]: `my_attr` is ambiguous (derive helper attribute vs any other name)
   --> $DIR/derive-helper-shadowing.rs:6:3
    |
@@ -16,6 +24,7 @@
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: use `crate::my_attr` to refer to this attribute macro unambiguously
 
-error: aborting due to previous error
+error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0659`.
+Some errors occurred: E0658, E0659.
+For more information about an error, try `rustc --explain E0658`.
diff --git a/src/test/ui/rust-2018/future-proofing-locals.rs b/src/test/ui/rust-2018/future-proofing-locals.rs
index 85a122b..ee81363 100644
--- a/src/test/ui/rust-2018/future-proofing-locals.rs
+++ b/src/test/ui/rust-2018/future-proofing-locals.rs
@@ -17,7 +17,7 @@
 }
 
 fn self_import<T>() {
-    use T; // FIXME Should be an error, but future-proofing fails due to `T` being "self-shadowed"
+    use T; //~ ERROR imports cannot refer to type parameters
 }
 
 fn let_binding() {
diff --git a/src/test/ui/rust-2018/future-proofing-locals.stderr b/src/test/ui/rust-2018/future-proofing-locals.stderr
index 68354b3..413e199 100644
--- a/src/test/ui/rust-2018/future-proofing-locals.stderr
+++ b/src/test/ui/rust-2018/future-proofing-locals.stderr
@@ -16,6 +16,12 @@
 LL |     use T::*; //~ ERROR imports cannot refer to type parameters
    |         ^
 
+error: imports cannot refer to type parameters
+  --> $DIR/future-proofing-locals.rs:19:9
+   |
+LL |     use T; //~ ERROR imports cannot refer to type parameters
+   |         ^
+
 error: imports cannot refer to local variables
   --> $DIR/future-proofing-locals.rs:25:9
    |
@@ -46,5 +52,5 @@
 LL |     use {T as _, x}; //~ ERROR imports cannot refer to type parameters
    |                  ^
 
-error: aborting due to 8 previous errors
+error: aborting due to 9 previous errors