about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2021-10-25 07:54:13 +0200
committerGitHub <noreply@github.com>2021-10-25 07:54:13 +0200
commitc734a9e0769de0843b16591a5b3fb9b56ec4417c (patch)
tree6552a41736d2b15580796eba011a19dcb7f5e0a1
parentb25172b5048dce325e44b2e1c381acfe3815f957 (diff)
parent3b2dd702fcdd70b81f2e6d217da3c715afc31012 (diff)
downloadrust-c734a9e0769de0843b16591a5b3fb9b56ec4417c.tar.gz
rust-c734a9e0769de0843b16591a5b3fb9b56ec4417c.zip
Rollup merge of #90127 - JohnTitor:fix-90113, r=estebank
Do not mention a reexported item if it's private

Fixes #90113
The _actual_ regression was introduced in #73652, then #88838 made it worse. This fixes the issue by not counting such an import as a candidate.
-rw-r--r--compiler/rustc_resolve/src/diagnostics.rs9
-rw-r--r--src/test/ui/resolve/issue-90113.rs21
-rw-r--r--src/test/ui/resolve/issue-90113.stderr14
3 files changed, 44 insertions, 0 deletions
diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs
index 63000a9d13d..e599bf4cab0 100644
--- a/compiler/rustc_resolve/src/diagnostics.rs
+++ b/compiler/rustc_resolve/src/diagnostics.rs
@@ -829,6 +829,15 @@ impl<'a> Resolver<'a> {
                     return;
                 }
 
+                // #90113: Do not count an inaccessible reexported item as a candidate.
+                if let NameBindingKind::Import { binding, .. } = name_binding.kind {
+                    if this.is_accessible_from(binding.vis, parent_scope.module)
+                        && !this.is_accessible_from(name_binding.vis, parent_scope.module)
+                    {
+                        return;
+                    }
+                }
+
                 // collect results based on the filter function
                 // avoid suggesting anything from the same module in which we are resolving
                 if ident.name == lookup_ident.name
diff --git a/src/test/ui/resolve/issue-90113.rs b/src/test/ui/resolve/issue-90113.rs
new file mode 100644
index 00000000000..f6658b45ed1
--- /dev/null
+++ b/src/test/ui/resolve/issue-90113.rs
@@ -0,0 +1,21 @@
+mod list {
+    pub use self::List::Cons;
+
+    pub enum List<T> {
+        Cons(T, Box<List<T>>),
+    }
+}
+
+mod alias {
+    use crate::list::List;
+
+    pub type Foo = List<String>;
+}
+
+fn foo(l: crate::alias::Foo) {
+    match l {
+        Cons(..) => {} //~ ERROR: cannot find tuple struct or tuple variant `Cons` in this scope
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/resolve/issue-90113.stderr b/src/test/ui/resolve/issue-90113.stderr
new file mode 100644
index 00000000000..1b78720571c
--- /dev/null
+++ b/src/test/ui/resolve/issue-90113.stderr
@@ -0,0 +1,14 @@
+error[E0531]: cannot find tuple struct or tuple variant `Cons` in this scope
+  --> $DIR/issue-90113.rs:17:9
+   |
+LL |         Cons(..) => {}
+   |         ^^^^ not found in this scope
+   |
+help: consider importing this tuple variant
+   |
+LL | use list::List::Cons;
+   |
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0531`.