about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2025-01-18 20:07:05 +0000
committerEsteban Küber <esteban@kuber.com.ar>2025-01-18 20:33:15 +0000
commitdeef3ebaec2ff0ff818161f3b9b86a42bed5fe36 (patch)
tree29becbbad6d9a19783b3a25dfbcc54e3b5318c80 /tests
parentbbcf26fc33afb4695014aff22fa77dcb7d9eb715 (diff)
Emit a single privacy error for multiple fields on the same struct expression
Collect all unreachable fields in a single struct literal struct and emit a single error, instead of one error per private field.

```
error[E0451]: fields `beta` and `gamma` of struct `Alpha` are private
  --> $DIR/visibility.rs:18:13
   |
LL |     let _x = Alpha {
   |              ----- in this type
LL |         beta: 0,
   |         ^^^^^^^ private field
LL |         ..
   |         ^^ field `gamma` is private
```
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/deprecation/deprecation-lint.stderr2
-rw-r--r--tests/ui/error-codes/E0451.stderr2
-rw-r--r--tests/ui/pattern/usefulness/issue-82772-match-box-as-struct.stderr2
-rw-r--r--tests/ui/privacy/private-struct-field-ctor.stderr2
-rw-r--r--tests/ui/privacy/private-struct-field-pattern.stderr2
-rw-r--r--tests/ui/privacy/restricted/struct-literal-field.stderr2
-rw-r--r--tests/ui/privacy/union-field-privacy-1.stderr2
-rw-r--r--tests/ui/structs/default-field-values/visibility.rs23
-rw-r--r--tests/ui/structs/default-field-values/visibility.stderr62
-rw-r--r--tests/ui/typeck/issue-82772.stderr6
10 files changed, 74 insertions, 31 deletions
diff --git a/tests/ui/deprecation/deprecation-lint.stderr b/tests/ui/deprecation/deprecation-lint.stderr
index 075bb42fa9a..95ae1b04d86 100644
--- a/tests/ui/deprecation/deprecation-lint.stderr
+++ b/tests/ui/deprecation/deprecation-lint.stderr
@@ -743,7 +743,7 @@ LL |         let _ = nested::DeprecatedStruct {
    |                 ------------------------ in this type
 LL |
 LL |             i: 0
-   |             ^^^^ private field
+   |             ^ private field
 
 error: aborting due to 123 previous errors
 
diff --git a/tests/ui/error-codes/E0451.stderr b/tests/ui/error-codes/E0451.stderr
index 419cf117efe..2cd30095c80 100644
--- a/tests/ui/error-codes/E0451.stderr
+++ b/tests/ui/error-codes/E0451.stderr
@@ -8,7 +8,7 @@ error[E0451]: field `b` of struct `Foo` is private
   --> $DIR/E0451.rs:18:29
    |
 LL |     let f = bar::Foo{ a: 0, b: 0 };
-   |                             ^^^^ private field
+   |                             ^ private field
 
 error: aborting due to 2 previous errors
 
diff --git a/tests/ui/pattern/usefulness/issue-82772-match-box-as-struct.stderr b/tests/ui/pattern/usefulness/issue-82772-match-box-as-struct.stderr
index ba7573839ed..ee21b4c8d46 100644
--- a/tests/ui/pattern/usefulness/issue-82772-match-box-as-struct.stderr
+++ b/tests/ui/pattern/usefulness/issue-82772-match-box-as-struct.stderr
@@ -2,7 +2,7 @@ error[E0451]: field `1` of struct `Box` is private
   --> $DIR/issue-82772-match-box-as-struct.rs:4:15
    |
 LL |     let Box { 1: _, .. }: Box<()>;
-   |               ^^^^ private field
+   |               ^ private field
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/privacy/private-struct-field-ctor.stderr b/tests/ui/privacy/private-struct-field-ctor.stderr
index 2a35537237a..8eb1bf7990b 100644
--- a/tests/ui/privacy/private-struct-field-ctor.stderr
+++ b/tests/ui/privacy/private-struct-field-ctor.stderr
@@ -2,7 +2,7 @@ error[E0451]: field `x` of struct `Foo` is private
   --> $DIR/private-struct-field-ctor.rs:8:22
    |
 LL |     let s = a::Foo { x: 1 };
-   |                      ^^^^ private field
+   |                      ^ private field
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/privacy/private-struct-field-pattern.stderr b/tests/ui/privacy/private-struct-field-pattern.stderr
index de24d1e0962..5609596721d 100644
--- a/tests/ui/privacy/private-struct-field-pattern.stderr
+++ b/tests/ui/privacy/private-struct-field-pattern.stderr
@@ -2,7 +2,7 @@ error[E0451]: field `x` of struct `Foo` is private
   --> $DIR/private-struct-field-pattern.rs:15:15
    |
 LL |         Foo { x: _ } => {}
-   |               ^^^^ private field
+   |               ^ private field
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/privacy/restricted/struct-literal-field.stderr b/tests/ui/privacy/restricted/struct-literal-field.stderr
index dcdadf1da4b..e1cf7c2fadb 100644
--- a/tests/ui/privacy/restricted/struct-literal-field.stderr
+++ b/tests/ui/privacy/restricted/struct-literal-field.stderr
@@ -2,7 +2,7 @@ error[E0451]: field `x` of struct `S` is private
   --> $DIR/struct-literal-field.rs:18:9
    |
 LL |     S { x: 0 };
-   |         ^^^^ private field
+   |         ^ private field
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/privacy/union-field-privacy-1.stderr b/tests/ui/privacy/union-field-privacy-1.stderr
index b1f0b785ea7..6f883b16d02 100644
--- a/tests/ui/privacy/union-field-privacy-1.stderr
+++ b/tests/ui/privacy/union-field-privacy-1.stderr
@@ -2,7 +2,7 @@ error[E0451]: field `c` of union `U` is private
   --> $DIR/union-field-privacy-1.rs:12:20
    |
 LL |     let u = m::U { c: 0 };
-   |                    ^^^^ private field
+   |                    ^ private field
 
 error[E0451]: field `c` of union `U` is private
   --> $DIR/union-field-privacy-1.rs:16:16
diff --git a/tests/ui/structs/default-field-values/visibility.rs b/tests/ui/structs/default-field-values/visibility.rs
index e1f76a5fe24..ff1245551b0 100644
--- a/tests/ui/structs/default-field-values/visibility.rs
+++ b/tests/ui/structs/default-field-values/visibility.rs
@@ -1,5 +1,6 @@
 #![feature(default_field_values)]
 pub mod foo {
+    #[derive(Default)]
     pub struct Alpha {
         beta: u8 = 42,
         gamma: bool = true,
@@ -7,10 +8,22 @@ pub mod foo {
 }
 
 mod bar {
+    use crate::foo::Alpha;
     fn baz() {
-        let x = crate::foo::Alpha { .. };
-        //~^ ERROR field `beta` of struct `Alpha` is private
-        //~| ERROR field `gamma` of struct `Alpha` is private
+        let _x = Alpha { .. };
+        //~^ ERROR fields `beta` and `gamma` of struct `Alpha` are private
+        let _x = Alpha {
+            beta: 0, //~ ERROR fields `beta` and `gamma` of struct `Alpha` are private
+            gamma: false,
+        };
+        let _x = Alpha {
+            beta: 0, //~ ERROR fields `beta` and `gamma` of struct `Alpha` are private
+            ..
+        };
+        let _x = Alpha { beta: 0, .. };
+        //~^ ERROR fields `beta` and `gamma` of struct `Alpha` are private
+        let _x = Alpha { beta: 0, ..Default::default() };
+        //~^ ERROR fields `beta` and `gamma` of struct `Alpha` are private
     }
 }
 
@@ -20,10 +33,10 @@ pub mod baz {
     }
 }
 fn main() {
-    let a = baz::S {
+    let _a = baz::S {
         .. //~ ERROR field `x` of struct `S` is private
     };
-    let b = baz::S {
+    let _b = baz::S {
         x: 0, //~ ERROR field `x` of struct `S` is private
     };
 }
diff --git a/tests/ui/structs/default-field-values/visibility.stderr b/tests/ui/structs/default-field-values/visibility.stderr
index 666782933d3..38b96033252 100644
--- a/tests/ui/structs/default-field-values/visibility.stderr
+++ b/tests/ui/structs/default-field-values/visibility.stderr
@@ -1,31 +1,61 @@
 error[E0451]: field `x` of struct `S` is private
-  --> $DIR/visibility.rs:24:9
+  --> $DIR/visibility.rs:37:9
    |
-LL |     let a = baz::S {
-   |             ------ in this type
+LL |     let _a = baz::S {
+   |              ------ in this type
 LL |         ..
    |         ^^ field `x` is private
 
 error[E0451]: field `x` of struct `S` is private
-  --> $DIR/visibility.rs:27:9
+  --> $DIR/visibility.rs:40:9
    |
-LL |     let b = baz::S {
-   |             ------ in this type
+LL |     let _b = baz::S {
+   |              ------ in this type
 LL |         x: 0,
-   |         ^^^^ private field
+   |         ^ private field
 
-error[E0451]: field `beta` of struct `Alpha` is private
-  --> $DIR/visibility.rs:11:37
+error[E0451]: fields `beta` and `gamma` of struct `Alpha` are private
+  --> $DIR/visibility.rs:13:26
    |
-LL |         let x = crate::foo::Alpha { .. };
-   |                                     ^^ field `beta` is private
+LL |         let _x = Alpha { .. };
+   |                          ^^ fields `beta` and `gamma` are private
 
-error[E0451]: field `gamma` of struct `Alpha` is private
-  --> $DIR/visibility.rs:11:37
+error[E0451]: fields `beta` and `gamma` of struct `Alpha` are private
+  --> $DIR/visibility.rs:16:13
    |
-LL |         let x = crate::foo::Alpha { .. };
-   |                                     ^^ field `gamma` is private
+LL |         let _x = Alpha {
+   |                  ----- in this type
+LL |             beta: 0,
+   |             ^^^^ private field
+LL |             gamma: false,
+   |             ^^^^^ private field
 
-error: aborting due to 4 previous errors
+error[E0451]: fields `beta` and `gamma` of struct `Alpha` are private
+  --> $DIR/visibility.rs:20:13
+   |
+LL |         let _x = Alpha {
+   |                  ----- in this type
+LL |             beta: 0,
+   |             ^^^^^^^ private field
+LL |             ..
+   |             ^^ field `gamma` is private
+
+error[E0451]: fields `beta` and `gamma` of struct `Alpha` are private
+  --> $DIR/visibility.rs:23:26
+   |
+LL |         let _x = Alpha { beta: 0, .. };
+   |                          ^^^^^^^  ^^ field `gamma` is private
+   |                          |
+   |                          private field
+
+error[E0451]: fields `beta` and `gamma` of struct `Alpha` are private
+  --> $DIR/visibility.rs:25:26
+   |
+LL |         let _x = Alpha { beta: 0, ..Default::default() };
+   |                          ^^^^^^^    ^^^^^^^^^^^^^^^^^^ field `gamma` is private
+   |                          |
+   |                          private field
+
+error: aborting due to 7 previous errors
 
 For more information about this error, try `rustc --explain E0451`.
diff --git a/tests/ui/typeck/issue-82772.stderr b/tests/ui/typeck/issue-82772.stderr
index 321143cb968..a314306137a 100644
--- a/tests/ui/typeck/issue-82772.stderr
+++ b/tests/ui/typeck/issue-82772.stderr
@@ -2,19 +2,19 @@ error[E0451]: field `0` of struct `Box` is private
   --> $DIR/issue-82772.rs:5:15
    |
 LL |     let Box { 0: _, .. }: Box<()>;
-   |               ^^^^ private field
+   |               ^ private field
 
 error[E0451]: field `1` of struct `Box` is private
   --> $DIR/issue-82772.rs:6:15
    |
 LL |     let Box { 1: _, .. }: Box<()>;
-   |               ^^^^ private field
+   |               ^ private field
 
 error[E0451]: field `1` of struct `ModPrivateStruct` is private
   --> $DIR/issue-82772.rs:7:28
    |
 LL |     let ModPrivateStruct { 1: _, .. } = ModPrivateStruct::default();
-   |                            ^^^^ private field
+   |                            ^ private field
 
 error: aborting due to 3 previous errors