Skip to content

Commit 4be0707

Browse files
committed
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 ```
1 parent abe34e9 commit 4be0707

File tree

6 files changed

+8
-7
lines changed

6 files changed

+8
-7
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2090,7 +2090,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20902090
[] => unreachable!(),
20912091
};
20922092
err.note(format!(
2093-
"... and other private field{s} {names}that {were} not provided",
2093+
"{}private field{s} {names}that {were} not provided",
2094+
if used_fields.is_empty() { "" } else { "...and other " },
20942095
s = pluralize!(remaining_private_fields_len),
20952096
were = pluralize!("was", remaining_private_fields_len),
20962097
));

tests/ui/issues/issue-76077.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: cannot construct `Foo` with struct literal syntax due to private fields
44
LL | foo::Foo {};
55
| ^^^^^^^^
66
|
7-
= note: ... and other private field `you_cant_use_this_field` that was not provided
7+
= note: private field `you_cant_use_this_field` that was not provided
88

99
error: aborting due to 1 previous error
1010

tests/ui/privacy/issue-79593.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ error: cannot construct `Pub` with struct literal syntax due to private fields
1616
LL | foo::Pub {};
1717
| ^^^^^^^^
1818
|
19-
= note: ... and other private field `private` that was not provided
19+
= note: private field `private` that was not provided
2020

2121
error[E0063]: missing field `y` in initializer of `Enum`
2222
--> $DIR/issue-79593.rs:23:5

tests/ui/privacy/suggest-box-new.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ error: cannot construct `HashMap<_, _, _>` with struct literal syntax due to pri
5656
LL | let _ = std::collections::HashMap {};
5757
| ^^^^^^^^^^^^^^^^^^^^^^^^^
5858
|
59-
= note: ... and other private field `base` that was not provided
59+
= note: private field `base` that was not provided
6060
help: you might have meant to use an associated function to build this type
6161
|
6262
LL | let _ = std::collections::HashMap::new();
@@ -78,7 +78,7 @@ error: cannot construct `Box<_, _>` with struct literal syntax due to private fi
7878
LL | let _ = Box {};
7979
| ^^^
8080
|
81-
= note: ... and other private fields `0` and `1` that were not provided
81+
= note: private fields `0` and `1` that were not provided
8282
help: you might have meant to use an associated function to build this type
8383
|
8484
LL | let _ = Box::new(_);

tests/ui/typeck/issue-87872-missing-inaccessible-field-literal.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: cannot construct `Foo` with struct literal syntax due to private fields
44
LL | foo::Foo {};
55
| ^^^^^^^^
66
|
7-
= note: ... and other private field `you_cant_use_this_field` that was not provided
7+
= note: private field `you_cant_use_this_field` that was not provided
88

99
error: aborting due to 1 previous error
1010

tests/ui/typeck/missing-private-fields-in-struct-literal.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | a: (),
99
LL | b: (),
1010
| ----- private field
1111
|
12-
= note: ... and other private fields `c`, `d` and `e` that were not provided
12+
= note: ...and other private fields `c`, `d` and `e` that were not provided
1313

1414
error: aborting due to 1 previous error
1515

0 commit comments

Comments
 (0)