about summary refs log tree commit diff
path: root/tests/ui/privacy
diff options
context:
space:
mode:
authorOneirical <manchot@videotron.ca>2025-07-13 16:56:31 -0400
committerOneirical <manchot@videotron.ca>2025-08-17 13:01:02 -0400
commit75e0263af9ca27eac2c922538582deec764d1e7b (patch)
treebc8584c15f51966d5ddee98a6782785d5c158fe0 /tests/ui/privacy
parent2e2642e641a941f0a1400c7827fd89aa86fef8f4 (diff)
downloadrust-75e0263af9ca27eac2c922538582deec764d1e7b.tar.gz
rust-75e0263af9ca27eac2c922538582deec764d1e7b.zip
Rehome tests/ui/issues/ tests [5/?]
Diffstat (limited to 'tests/ui/privacy')
-rw-r--r--tests/ui/privacy/inaccessible-fields-pattern-matching-76077.fixed19
-rw-r--r--tests/ui/privacy/inaccessible-fields-pattern-matching-76077.rs19
-rw-r--r--tests/ui/privacy/inaccessible-fields-pattern-matching-76077.stderr24
-rw-r--r--tests/ui/privacy/private-field-struct-construction-76077.rs11
-rw-r--r--tests/ui/privacy/private-field-struct-construction-76077.stderr10
5 files changed, 83 insertions, 0 deletions
diff --git a/tests/ui/privacy/inaccessible-fields-pattern-matching-76077.fixed b/tests/ui/privacy/inaccessible-fields-pattern-matching-76077.fixed
new file mode 100644
index 00000000000..7d648543a20
--- /dev/null
+++ b/tests/ui/privacy/inaccessible-fields-pattern-matching-76077.fixed
@@ -0,0 +1,19 @@
+// https://github.com/rust-lang/rust/issues/76077
+//@ run-rustfix
+#![allow(dead_code, unused_variables)]
+
+pub mod foo {
+    #[derive(Default)]
+    pub struct Foo { invisible: bool, }
+
+    #[derive(Default)]
+    pub struct Bar { pub visible: bool, invisible: bool, }
+}
+
+fn main() {
+    let foo::Foo { .. } = foo::Foo::default();
+    //~^ ERROR pattern requires `..` due to inaccessible fields
+
+    let foo::Bar { visible, .. } = foo::Bar::default();
+    //~^ ERROR pattern requires `..` due to inaccessible fields
+}
diff --git a/tests/ui/privacy/inaccessible-fields-pattern-matching-76077.rs b/tests/ui/privacy/inaccessible-fields-pattern-matching-76077.rs
new file mode 100644
index 00000000000..f3b51187ae3
--- /dev/null
+++ b/tests/ui/privacy/inaccessible-fields-pattern-matching-76077.rs
@@ -0,0 +1,19 @@
+// https://github.com/rust-lang/rust/issues/76077
+//@ run-rustfix
+#![allow(dead_code, unused_variables)]
+
+pub mod foo {
+    #[derive(Default)]
+    pub struct Foo { invisible: bool, }
+
+    #[derive(Default)]
+    pub struct Bar { pub visible: bool, invisible: bool, }
+}
+
+fn main() {
+    let foo::Foo {} = foo::Foo::default();
+    //~^ ERROR pattern requires `..` due to inaccessible fields
+
+    let foo::Bar { visible } = foo::Bar::default();
+    //~^ ERROR pattern requires `..` due to inaccessible fields
+}
diff --git a/tests/ui/privacy/inaccessible-fields-pattern-matching-76077.stderr b/tests/ui/privacy/inaccessible-fields-pattern-matching-76077.stderr
new file mode 100644
index 00000000000..070fa1a53a5
--- /dev/null
+++ b/tests/ui/privacy/inaccessible-fields-pattern-matching-76077.stderr
@@ -0,0 +1,24 @@
+error: pattern requires `..` due to inaccessible fields
+  --> $DIR/inaccessible-fields-pattern-matching-76077.rs:14:9
+   |
+LL |     let foo::Foo {} = foo::Foo::default();
+   |         ^^^^^^^^^^^
+   |
+help: ignore the inaccessible and unused fields
+   |
+LL |     let foo::Foo { .. } = foo::Foo::default();
+   |                    ++
+
+error: pattern requires `..` due to inaccessible fields
+  --> $DIR/inaccessible-fields-pattern-matching-76077.rs:17:9
+   |
+LL |     let foo::Bar { visible } = foo::Bar::default();
+   |         ^^^^^^^^^^^^^^^^^^^^
+   |
+help: ignore the inaccessible and unused fields
+   |
+LL |     let foo::Bar { visible, .. } = foo::Bar::default();
+   |                           ++++
+
+error: aborting due to 2 previous errors
+
diff --git a/tests/ui/privacy/private-field-struct-construction-76077.rs b/tests/ui/privacy/private-field-struct-construction-76077.rs
new file mode 100644
index 00000000000..7fc3473e8de
--- /dev/null
+++ b/tests/ui/privacy/private-field-struct-construction-76077.rs
@@ -0,0 +1,11 @@
+// https://github.com/rust-lang/rust/issues/76077
+pub mod foo {
+    pub struct Foo {
+        you_cant_use_this_field: bool,
+    }
+}
+
+fn main() {
+    foo::Foo {};
+    //~^ ERROR cannot construct `Foo` with struct literal syntax due to private fields
+}
diff --git a/tests/ui/privacy/private-field-struct-construction-76077.stderr b/tests/ui/privacy/private-field-struct-construction-76077.stderr
new file mode 100644
index 00000000000..5131db72fe3
--- /dev/null
+++ b/tests/ui/privacy/private-field-struct-construction-76077.stderr
@@ -0,0 +1,10 @@
+error: cannot construct `Foo` with struct literal syntax due to private fields
+  --> $DIR/private-field-struct-construction-76077.rs:9:5
+   |
+LL |     foo::Foo {};
+   |     ^^^^^^^^
+   |
+   = note: private field `you_cant_use_this_field` that was not provided
+
+error: aborting due to 1 previous error
+