about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <yuki.okushi@huawei.com>2021-10-21 20:23:34 +0900
committerYuki Okushi <yuki.okushi@huawei.com>2021-10-21 20:25:45 +0900
commit3b2dd702fcdd70b81f2e6d217da3c715afc31012 (patch)
tree965018020c73b89f1a828ad98ad64a903fb0b395
parent4626184cafa827e13cc7a71b183a704ee0ec5930 (diff)
downloadrust-3b2dd702fcdd70b81f2e6d217da3c715afc31012.tar.gz
rust-3b2dd702fcdd70b81f2e6d217da3c715afc31012.zip
Do not mention a reexported item if it's private
-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`.