about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-06-05 20:59:41 +0000
committerMichael Goulet <michael@errs.io>2023-06-05 21:00:08 +0000
commit140c011ca6659e608833bdc31b66b0f53d11104e (patch)
treec406dacdd549b72253f4515a2eb19cc1c1f7bca6
parent408bbd040613f6776e0a7d05d582c81f4ddc189a (diff)
downloadrust-140c011ca6659e608833bdc31b66b0f53d11104e.tar.gz
rust-140c011ca6659e608833bdc31b66b0f53d11104e.zip
Don't mention already set fields
-rw-r--r--compiler/rustc_hir_typeck/src/expr.rs23
-rw-r--r--tests/ui/async-await/drop-track-bad-field-in-fru.stderr2
-rw-r--r--tests/ui/did_you_mean/issue-42599_available_fields_note.stderr2
-rw-r--r--tests/ui/error-codes/E0560.stderr2
-rw-r--r--tests/ui/issues/issue-5439.stderr2
-rw-r--r--tests/ui/proc-macro/span-preservation.stderr2
-rw-r--r--tests/ui/structs/struct-field-cfg.stderr2
-rw-r--r--tests/ui/structs/struct-fields-shorthand.stderr2
-rw-r--r--tests/ui/structs/struct-fields-too-many.stderr2
-rw-r--r--tests/ui/union/union-fields-2.mirunsafeck.stderr2
-rw-r--r--tests/ui/union/union-fields-2.thirunsafeck.stderr2
11 files changed, 23 insertions, 20 deletions
diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs
index 3c5feb1ba51..f03c7ca44ba 100644
--- a/compiler/rustc_hir_typeck/src/expr.rs
+++ b/compiler/rustc_hir_typeck/src/expr.rs
@@ -2081,13 +2081,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             },
             _ => {
                 // prevent all specified fields from being suggested
-                let skip_fields = skip_fields.iter().map(|x| x.ident.name);
-                if let Some(field_name) = self.suggest_field_name(
-                    variant,
-                    field.ident.name,
-                    skip_fields.collect(),
-                    expr_span,
-                ) {
+                let skip_fields: Vec<_> = skip_fields.iter().map(|x| x.ident.name).collect();
+                if let Some(field_name) =
+                    self.suggest_field_name(variant, field.ident.name, &skip_fields, expr_span)
+                {
                     err.span_suggestion(
                         field.ident.span,
                         "a field with a similar name exists",
@@ -2108,9 +2105,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                                     format!("`{ty}` does not have this field"),
                                 );
                             }
-                            let available_field_names =
+                            let mut available_field_names =
                                 self.available_field_names(variant, expr_span);
-                            if !available_field_names.is_empty() {
+                            available_field_names
+                                .retain(|name| skip_fields.iter().all(|skip| name != skip));
+                            if available_field_names.is_empty() {
+                                err.note("all struct fields are already assigned");
+                            } else {
                                 err.note(format!(
                                     "available fields are: {}",
                                     self.name_series_display(available_field_names)
@@ -2130,7 +2131,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         &self,
         variant: &'tcx ty::VariantDef,
         field: Symbol,
-        skip: Vec<Symbol>,
+        skip: &[Symbol],
         // The span where stability will be checked
         span: Span,
     ) -> Option<Symbol> {
@@ -2582,7 +2583,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         access_span: Span,
     ) {
         if let Some(suggested_field_name) =
-            self.suggest_field_name(def.non_enum_variant(), field.name, vec![], access_span)
+            self.suggest_field_name(def.non_enum_variant(), field.name, &[], access_span)
         {
             err.span_suggestion(
                 field.span,
diff --git a/tests/ui/async-await/drop-track-bad-field-in-fru.stderr b/tests/ui/async-await/drop-track-bad-field-in-fru.stderr
index 07ab8b3c903..b49b15db64c 100644
--- a/tests/ui/async-await/drop-track-bad-field-in-fru.stderr
+++ b/tests/ui/async-await/drop-track-bad-field-in-fru.stderr
@@ -3,6 +3,8 @@ error[E0559]: variant `Option<_>::None` has no field named `value`
    |
 LL |     None { value: (), ..Default::default() }.await;
    |            ^^^^^ `Option<_>::None` does not have this field
+   |
+   = note: all struct fields are already assigned
 
 error[E0277]: `Option<_>` is not a future
   --> $DIR/drop-track-bad-field-in-fru.rs:7:46
diff --git a/tests/ui/did_you_mean/issue-42599_available_fields_note.stderr b/tests/ui/did_you_mean/issue-42599_available_fields_note.stderr
index dbd9dc1bc40..c20bbce3f24 100644
--- a/tests/ui/did_you_mean/issue-42599_available_fields_note.stderr
+++ b/tests/ui/did_you_mean/issue-42599_available_fields_note.stderr
@@ -10,7 +10,7 @@ error[E0560]: struct `Demo` has no field named `egregiously_nonexistent_field`
 LL |             Self { secret_integer: 3, egregiously_nonexistent_field: () }
    |                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Demo` does not have this field
    |
-   = note: available fields are: `favorite_integer`, `secret_integer`, `innocently_misspellable`, `another_field`, `yet_another_field` ... and 2 others
+   = note: available fields are: `favorite_integer`, `innocently_misspellable`, `another_field`, `yet_another_field`, `always_more_fields`, `and_ever`
 
 error[E0609]: no field `inocently_mispellable` on type `Demo`
   --> $DIR/issue-42599_available_fields_note.rs:32:41
diff --git a/tests/ui/error-codes/E0560.stderr b/tests/ui/error-codes/E0560.stderr
index 6b634f1855d..bb5ce478ae1 100644
--- a/tests/ui/error-codes/E0560.stderr
+++ b/tests/ui/error-codes/E0560.stderr
@@ -4,7 +4,7 @@ error[E0560]: struct `Simba` has no field named `father`
 LL |     let s = Simba { mother: 1, father: 0 };
    |                                ^^^^^^ `Simba` does not have this field
    |
-   = note: available fields are: `mother`
+   = note: all struct fields are already assigned
 
 error: aborting due to previous error
 
diff --git a/tests/ui/issues/issue-5439.stderr b/tests/ui/issues/issue-5439.stderr
index dc8f8b878d7..a91e4b31f4b 100644
--- a/tests/ui/issues/issue-5439.stderr
+++ b/tests/ui/issues/issue-5439.stderr
@@ -4,7 +4,7 @@ error[E0560]: struct `Foo` has no field named `nonexistent`
 LL |         return Box::new(Foo { nonexistent: self, foo: i });
    |                               ^^^^^^^^^^^ `Foo` does not have this field
    |
-   = note: available fields are: `foo`
+   = note: all struct fields are already assigned
 
 error: aborting due to previous error
 
diff --git a/tests/ui/proc-macro/span-preservation.stderr b/tests/ui/proc-macro/span-preservation.stderr
index 66c68be2f09..8c15cb9de98 100644
--- a/tests/ui/proc-macro/span-preservation.stderr
+++ b/tests/ui/proc-macro/span-preservation.stderr
@@ -32,7 +32,7 @@ error[E0560]: struct `Foo` has no field named `b`
 LL |     let y = Foo { a: 10, b: 10isize };
    |                          ^ `Foo` does not have this field
    |
-   = note: available fields are: `a`
+   = note: all struct fields are already assigned
 
 error[E0308]: mismatched types
   --> $DIR/span-preservation.rs:39:5
diff --git a/tests/ui/structs/struct-field-cfg.stderr b/tests/ui/structs/struct-field-cfg.stderr
index 5ec47c093a9..2b9ba85ddcb 100644
--- a/tests/ui/structs/struct-field-cfg.stderr
+++ b/tests/ui/structs/struct-field-cfg.stderr
@@ -10,7 +10,7 @@ error[E0560]: struct `Foo` has no field named `absent`
 LL |     let _ = Foo { present: (), #[cfg(all())] absent: () };
    |                                              ^^^^^^ `Foo` does not have this field
    |
-   = note: available fields are: `present`
+   = note: all struct fields are already assigned
 
 error[E0027]: pattern does not mention field `present`
   --> $DIR/struct-field-cfg.rs:13:9
diff --git a/tests/ui/structs/struct-fields-shorthand.stderr b/tests/ui/structs/struct-fields-shorthand.stderr
index a285a392168..d89d45b3903 100644
--- a/tests/ui/structs/struct-fields-shorthand.stderr
+++ b/tests/ui/structs/struct-fields-shorthand.stderr
@@ -4,7 +4,7 @@ error[E0560]: struct `Foo` has no field named `z`
 LL |         x, y, z
    |               ^ `Foo` does not have this field
    |
-   = note: available fields are: `x`, `y`
+   = note: all struct fields are already assigned
 
 error: aborting due to previous error
 
diff --git a/tests/ui/structs/struct-fields-too-many.stderr b/tests/ui/structs/struct-fields-too-many.stderr
index a1b7a7a3110..9342607ebce 100644
--- a/tests/ui/structs/struct-fields-too-many.stderr
+++ b/tests/ui/structs/struct-fields-too-many.stderr
@@ -4,7 +4,7 @@ error[E0560]: struct `BuildData` has no field named `bar`
 LL |         bar: 0
    |         ^^^ `BuildData` does not have this field
    |
-   = note: available fields are: `foo`
+   = note: all struct fields are already assigned
 
 error: aborting due to previous error
 
diff --git a/tests/ui/union/union-fields-2.mirunsafeck.stderr b/tests/ui/union/union-fields-2.mirunsafeck.stderr
index 90ad16402f7..1157f0c2ae7 100644
--- a/tests/ui/union/union-fields-2.mirunsafeck.stderr
+++ b/tests/ui/union/union-fields-2.mirunsafeck.stderr
@@ -16,7 +16,7 @@ error[E0560]: union `U` has no field named `c`
 LL |     let u = U { a: 0, b: 1, c: 2 };
    |                             ^ `U` does not have this field
    |
-   = note: available fields are: `a`, `b`
+   = note: all struct fields are already assigned
 
 error[E0784]: union expressions should have exactly one field
   --> $DIR/union-fields-2.rs:13:13
diff --git a/tests/ui/union/union-fields-2.thirunsafeck.stderr b/tests/ui/union/union-fields-2.thirunsafeck.stderr
index 90ad16402f7..1157f0c2ae7 100644
--- a/tests/ui/union/union-fields-2.thirunsafeck.stderr
+++ b/tests/ui/union/union-fields-2.thirunsafeck.stderr
@@ -16,7 +16,7 @@ error[E0560]: union `U` has no field named `c`
 LL |     let u = U { a: 0, b: 1, c: 2 };
    |                             ^ `U` does not have this field
    |
-   = note: available fields are: `a`, `b`
+   = note: all struct fields are already assigned
 
 error[E0784]: union expressions should have exactly one field
   --> $DIR/union-fields-2.rs:13:13