about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-11-30 09:28:25 +0100
committerGitHub <noreply@github.com>2023-11-30 09:28:25 +0100
commit13ded6651346893f9ee28ba8770c8aa1268c593f (patch)
treefd74347f14582b2f1f4e7d1f0f32ba14122ebde5
parente9a870d5ebebb26833a1789adcb4db53de260025 (diff)
parent4be07075b3651a69f05b9b9f16312fe3a8cf21fd (diff)
downloadrust-13ded6651346893f9ee28ba8770c8aa1268c593f.tar.gz
rust-13ded6651346893f9ee28ba8770c8aa1268c593f.zip
Rollup merge of #118453 - estebank:priv-fields, r=compiler-errors
Tweak message on ADT with private fields building

When trying to create an inaccessible ADT due to private fields, handle the case when no fields were passed.

```
error: cannot construct `Foo` with struct literal syntax due to private fields
  --> $DIR/issue-76077.rs:8:5
   |
LL |     foo::Foo {};
   |     ^^^^^^^^
   |
   = note: private field `you_cant_use_this_field` that was not provided
```
-rw-r--r--compiler/rustc_hir_typeck/src/expr.rs3
-rw-r--r--tests/ui/issues/issue-76077.stderr2
-rw-r--r--tests/ui/privacy/issue-79593.stderr2
-rw-r--r--tests/ui/privacy/suggest-box-new.stderr4
-rw-r--r--tests/ui/typeck/issue-87872-missing-inaccessible-field-literal.stderr2
-rw-r--r--tests/ui/typeck/missing-private-fields-in-struct-literal.stderr2
6 files changed, 8 insertions, 7 deletions
diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs
index ed5ac2cea38..c2a8eb3bc8e 100644
--- a/compiler/rustc_hir_typeck/src/expr.rs
+++ b/compiler/rustc_hir_typeck/src/expr.rs
@@ -2090,7 +2090,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 [] => unreachable!(),
             };
             err.note(format!(
-                "... and other private field{s} {names}that {were} not provided",
+                "{}private field{s} {names}that {were} not provided",
+                if used_fields.is_empty() { "" } else { "...and other " },
                 s = pluralize!(remaining_private_fields_len),
                 were = pluralize!("was", remaining_private_fields_len),
             ));
diff --git a/tests/ui/issues/issue-76077.stderr b/tests/ui/issues/issue-76077.stderr
index 4c510e91ada..3fef5ffce30 100644
--- a/tests/ui/issues/issue-76077.stderr
+++ b/tests/ui/issues/issue-76077.stderr
@@ -4,7 +4,7 @@ error: cannot construct `Foo` with struct literal syntax due to private fields
 LL |     foo::Foo {};
    |     ^^^^^^^^
    |
-   = note: ... and other private field `you_cant_use_this_field` that was not provided
+   = note: private field `you_cant_use_this_field` that was not provided
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/privacy/issue-79593.stderr b/tests/ui/privacy/issue-79593.stderr
index 21ba760ad0b..5bb69836f60 100644
--- a/tests/ui/privacy/issue-79593.stderr
+++ b/tests/ui/privacy/issue-79593.stderr
@@ -16,7 +16,7 @@ error: cannot construct `Pub` with struct literal syntax due to private fields
 LL |     foo::Pub {};
    |     ^^^^^^^^
    |
-   = note: ... and other private field `private` that was not provided
+   = note: private field `private` that was not provided
 
 error[E0063]: missing field `y` in initializer of `Enum`
   --> $DIR/issue-79593.rs:23:5
diff --git a/tests/ui/privacy/suggest-box-new.stderr b/tests/ui/privacy/suggest-box-new.stderr
index 2224f1c60d6..8b01e8c3c10 100644
--- a/tests/ui/privacy/suggest-box-new.stderr
+++ b/tests/ui/privacy/suggest-box-new.stderr
@@ -56,7 +56,7 @@ error: cannot construct `HashMap<_, _, _>` with struct literal syntax due to pri
 LL |     let _ = std::collections::HashMap {};
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^
    |
-   = note: ... and other private field `base` that was not provided
+   = note: private field `base` that was not provided
 help: you might have meant to use an associated function to build this type
    |
 LL |     let _ = std::collections::HashMap::new();
@@ -78,7 +78,7 @@ error: cannot construct `Box<_, _>` with struct literal syntax due to private fi
 LL |     let _ = Box {};
    |             ^^^
    |
-   = note: ... and other private fields `0` and `1` that were not provided
+   = note: private fields `0` and `1` that were not provided
 help: you might have meant to use an associated function to build this type
    |
 LL |     let _ = Box::new(_);
diff --git a/tests/ui/typeck/issue-87872-missing-inaccessible-field-literal.stderr b/tests/ui/typeck/issue-87872-missing-inaccessible-field-literal.stderr
index eab494ffbdf..899dd02583a 100644
--- a/tests/ui/typeck/issue-87872-missing-inaccessible-field-literal.stderr
+++ b/tests/ui/typeck/issue-87872-missing-inaccessible-field-literal.stderr
@@ -4,7 +4,7 @@ error: cannot construct `Foo` with struct literal syntax due to private fields
 LL |     foo::Foo {};
    |     ^^^^^^^^
    |
-   = note: ... and other private field `you_cant_use_this_field` that was not provided
+   = note: private field `you_cant_use_this_field` that was not provided
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/typeck/missing-private-fields-in-struct-literal.stderr b/tests/ui/typeck/missing-private-fields-in-struct-literal.stderr
index 96998ca244d..003eaa40592 100644
--- a/tests/ui/typeck/missing-private-fields-in-struct-literal.stderr
+++ b/tests/ui/typeck/missing-private-fields-in-struct-literal.stderr
@@ -9,7 +9,7 @@ LL |         a: (),
 LL |         b: (),
    |         ----- private field
    |
-   = note: ... and other private fields `c`, `d` and `e` that were not provided
+   = note: ...and other private fields `c`, `d` and `e` that were not provided
 
 error: aborting due to 1 previous error