about summary refs log tree commit diff
path: root/tests/ui/pub
diff options
context:
space:
mode:
authoryuk1ty <yuk1ty@users.noreply.github.com>2025-05-03 20:10:56 +0900
committeryuk1ty <yuk1ty@users.noreply.github.com>2025-05-03 20:10:56 +0900
commit265b10fe2e411a7af34f892aaa7635fba96cce2c (patch)
tree5297331a7e81ca86b88a6e17d12c838f3ba3afca /tests/ui/pub
parentd2eadb7a94ef8c9deb5137695df33cd1fc5aee92 (diff)
downloadrust-265b10fe2e411a7af34f892aaa7635fba96cce2c.tar.gz
rust-265b10fe2e411a7af34f892aaa7635fba96cce2c.zip
Correct warning message in restricted visibility
Diffstat (limited to 'tests/ui/pub')
-rw-r--r--tests/ui/pub/pub-restricted-warning.rs25
-rw-r--r--tests/ui/pub/pub-restricted-warning.stderr27
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/ui/pub/pub-restricted-warning.rs b/tests/ui/pub/pub-restricted-warning.rs
new file mode 100644
index 00000000000..80384afbb00
--- /dev/null
+++ b/tests/ui/pub/pub-restricted-warning.rs
@@ -0,0 +1,25 @@
+//@ check-pass
+
+#![allow(dead_code)]
+
+mod outer {
+    pub mod inner {
+        pub(in crate::outer) struct Foo;
+        pub fn bar() -> Foo {
+            //~^ WARNING type `Foo` is more private than the item `outer::inner::bar` [private_interfaces]
+            Foo
+        }
+    }
+
+    pub mod nested {
+        pub mod inner {
+            pub(in crate::outer::nested) struct NestedFoo;
+            pub fn bar() -> NestedFoo {
+                //~^ WARNING type `NestedFoo` is more private than the item `nested::inner::bar` [private_interfaces]
+                NestedFoo
+            }
+        }
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/pub/pub-restricted-warning.stderr b/tests/ui/pub/pub-restricted-warning.stderr
new file mode 100644
index 00000000000..74f32d3de3c
--- /dev/null
+++ b/tests/ui/pub/pub-restricted-warning.stderr
@@ -0,0 +1,27 @@
+warning: type `Foo` is more private than the item `outer::inner::bar`
+  --> $DIR/pub-restricted-warning.rs:8:9
+   |
+LL |         pub fn bar() -> Foo {
+   |         ^^^^^^^^^^^^^^^^^^^ function `outer::inner::bar` is reachable at visibility `pub(crate)`
+   |
+note: but type `Foo` is only usable at visibility `pub(in crate::outer)`
+  --> $DIR/pub-restricted-warning.rs:7:9
+   |
+LL |         pub(in crate::outer) struct Foo;
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   = note: `#[warn(private_interfaces)]` on by default
+
+warning: type `NestedFoo` is more private than the item `nested::inner::bar`
+  --> $DIR/pub-restricted-warning.rs:17:13
+   |
+LL |             pub fn bar() -> NestedFoo {
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^ function `nested::inner::bar` is reachable at visibility `pub(crate)`
+   |
+note: but type `NestedFoo` is only usable at visibility `pub(in crate::outer::nested)`
+  --> $DIR/pub-restricted-warning.rs:16:13
+   |
+LL |             pub(in crate::outer::nested) struct NestedFoo;
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+warning: 2 warnings emitted
+