about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTakayuki Maeda <takoyaki0316@gmail.com>2022-06-22 14:56:40 +0900
committerTakayuki Maeda <takoyaki0316@gmail.com>2022-06-22 14:56:40 +0900
commiteb86daa1383d5330a18aa4e78270a6ca5b4ea469 (patch)
tree060731bcaa468d2b593cc4828fa406ac0ae81151
parentf847261478de5fa72d7e1d2ec3341e31a794fcaf (diff)
downloadrust-eb86daa1383d5330a18aa4e78270a6ca5b4ea469.tar.gz
rust-eb86daa1383d5330a18aa4e78270a6ca5b4ea469.zip
add "was" to pluralize macro and use it
-rw-r--r--compiler/rustc_lint_defs/src/lib.rs3
-rw-r--r--compiler/rustc_typeck/src/check/expr.rs39
-rw-r--r--src/test/ui/issues/issue-76077.stderr2
-rw-r--r--src/test/ui/privacy/issue-79593.stderr2
-rw-r--r--src/test/ui/typeck/issue-87872-missing-inaccessible-field-literal.stderr2
5 files changed, 27 insertions, 21 deletions
diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs
index cb1c6f40987..1cd19c7eaab 100644
--- a/compiler/rustc_lint_defs/src/lib.rs
+++ b/compiler/rustc_lint_defs/src/lib.rs
@@ -26,6 +26,9 @@ macro_rules! pluralize {
     ("is", $x:expr) => {
         if $x == 1 { "is" } else { "are" }
     };
+    ("was", $x:expr) => {
+        if $x == 1 { "was" } else { "were" }
+    };
     ("this", $x:expr) => {
         if $x == 1 { "this" } else { "these" }
     };
diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs
index e5048fc5132..c69de643453 100644
--- a/compiler/rustc_typeck/src/check/expr.rs
+++ b/compiler/rustc_typeck/src/check/expr.rs
@@ -1839,25 +1839,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 }
             })
             .partition(|field| field.2);
-        let remaining_private_fields_len = remaining_private_fields.len();
-        let names = match &remaining_private_fields
-            .iter()
-            .map(|(name, _, _)| name.to_string())
-            .collect::<Vec<_>>()[..]
-        {
-            _ if remaining_private_fields_len > 6 => String::new(),
-            [name] => format!("`{name}` "),
-            [names @ .., last] => {
-                let names = names.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>();
-                format!("{} and `{last}` ", names.join(", "))
-            }
-            [] => unreachable!(),
-        };
         err.span_labels(used_private_fields.iter().map(|(_, span, _)| *span), "private field");
-        err.note(format!(
-            "... and other private field{s} {names}that were not provided",
-            s = pluralize!(remaining_private_fields_len),
-        ));
+        if !remaining_private_fields.is_empty() {
+            let remaining_private_fields_len = remaining_private_fields.len();
+            let names = match &remaining_private_fields
+                .iter()
+                .map(|(name, _, _)| name.to_string())
+                .collect::<Vec<_>>()[..]
+            {
+                _ if remaining_private_fields_len > 6 => String::new(),
+                [name] => format!("`{name}` "),
+                [names @ .., last] => {
+                    let names = names.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>();
+                    format!("{} and `{last}` ", names.join(", "))
+                }
+                [] => unreachable!(),
+            };
+            err.note(format!(
+                "... and other private field{s} {names}that {were} not provided",
+                s = pluralize!(remaining_private_fields_len),
+                were = pluralize!("was", remaining_private_fields_len),
+            ));
+        }
         err.emit();
     }
 
diff --git a/src/test/ui/issues/issue-76077.stderr b/src/test/ui/issues/issue-76077.stderr
index 57f7abe3931..197ca8d5a7b 100644
--- a/src/test/ui/issues/issue-76077.stderr
+++ b/src/test/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 were not provided
+   = note: ... and other private field `you_cant_use_this_field` that was not provided
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/privacy/issue-79593.stderr b/src/test/ui/privacy/issue-79593.stderr
index d878e1c023f..21ba760ad0b 100644
--- a/src/test/ui/privacy/issue-79593.stderr
+++ b/src/test/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 were not provided
+   = note: ... and other 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/src/test/ui/typeck/issue-87872-missing-inaccessible-field-literal.stderr b/src/test/ui/typeck/issue-87872-missing-inaccessible-field-literal.stderr
index fa1c661ef24..f0bd3e0ddf7 100644
--- a/src/test/ui/typeck/issue-87872-missing-inaccessible-field-literal.stderr
+++ b/src/test/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 were not provided
+   = note: ... and other private field `you_cant_use_this_field` that was not provided
 
 error: aborting due to previous error