about summary refs log tree commit diff
path: root/compiler
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 /compiler
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
```
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_hir_typeck/src/expr.rs3
1 files changed, 2 insertions, 1 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),
             ));